import tiledb
import os
# TileDB automatically sets the TILEDB_REST_TOKEN variable in your
# running server.
= os.environ["TILEDB_REST_TOKEN"]
tiledb_token
# You should set the appropriate environment variables with your keys.
# Get the keys from the environment variables.
= os.environ["TILEDB_ACCOUNT"]
tiledb_account
# Get the bucket from environment variables
= os.environ["S3_BUCKET"]
s3_bucket
# Define a configuration object and set the default context.
# This context initialization can be performed only once.
= tiledb.Config(
cfg
{"rest.token": tiledb_token,
}
) tiledb.default_ctx(cfg)
Basic TileDB Cloud
You can run this tutorial only on TileDB Cloud. However, TileDB Cloud has a free tier. We strongly recommend that you sign up and run everything there, as that requires no installations or deployment.
This tutorial shows basic usage of arrays on TileDB Cloud. It assumes you have already completed the Get Started section.
Start by setting some environment variables. It can look something like this:
import os
"S3_BUCKET"] = "s3://<your_bucket_name>"
os.environ["TILEDB_ACCOUNT"] = "<your_tiledb_account_username>" os.environ[
Next, fetch the environment variables you created and define the global context:
The rest of the tutorial is almost the same as the Tutorials: Basic Dense section, whereas you can create, write, and read any array in the same manner after setting up your TileDB credentials as shown earlier.
Import the necessary libraries, set the array URI (that is, its path, which in this tutorial will be on local storage), and delete any previously created arrays with the same name.
Next, create the array by specifying its schema. The only difference between TileDB Cloud and TileDB Open-source when creating and registering arrays is that the TileDB Cloud URI should be of the form: tiledb://<account>/s3://<bucket>/<array_name>
. TileDB Cloud understands that you are trying to create an array in S3 URI s3://<bucket>/<array_name>
and register it under <account>
. After you create and register the array, you can access the array as tiledb://<account>/<array_name>
.
Populate the array with a 2-dimensional array. Observe that now you use the array URI in the form tiledb://<account>/<array_name>
.
Read the data by using the slicing methods supported in TileDB. Again, you access the array with URI tiledb://<account>/<array_name>
.
Clean up in the end by deleting the array. Observet that the standard TileDB object management functions work directly with tiledb://
URIs (that is, TileDB Cloud arrays).