Skip to content

Commit c26d1d1

Browse files
committed
Add example
1 parent 596df01 commit c26d1d1

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

examples/profile.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# query_condition_sparse.py
2+
#
3+
# LICENSE
4+
#
5+
# The MIT License
6+
#
7+
# Copyright (c) 2025 TileDB, Inc.
8+
#
9+
# Permission is hereby granted, free of charge, to any person obtaining a copy
10+
# of this software and associated documentation files (the "Software"), to deal
11+
# in the Software without restriction, including without limitation the rights
12+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
# copies of the Software, and to permit persons to whom the Software is
14+
# furnished to do so, subject to the following conditions:
15+
#
16+
# The above copyright notice and this permission notice shall be included in
17+
# all copies or substantial portions of the Software.
18+
#
19+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
# THE SOFTWARE.
26+
#
27+
28+
# This example demonstrates how to create, save, and use profiles in TileDB.
29+
# It also shows how to remove profiles when they are no longer needed.
30+
31+
import tiledb
32+
33+
34+
def create_and_save_profiles():
35+
p1 = tiledb.Profile()
36+
p1["rest.token"] = "my_token"
37+
p1.save()
38+
39+
p2 = tiledb.Profile("my_profile_name")
40+
p2["rest.server_address"] = "https://my.address"
41+
p2.save()
42+
43+
def use_profiles():
44+
# Create a config object. This will use the default profile.
45+
cfg = tiledb.Config()
46+
print("rest.token:", cfg["rest.token"])
47+
48+
# Create a config object using a specific profile name.
49+
cfg_with_profile = tiledb.Config({"profile_name": "my_profile_name"})
50+
print("rest.server_address:", cfg_with_profile["rest.server_address"])
51+
52+
# Use on of the profile to create a context.
53+
ctx = tiledb.Ctx(cfg_with_profile)
54+
55+
# Use the context to create a new array. The REST credentials from the profile will be used.
56+
array_name = "tiledb://my_workspace/my_teamspace/my_array"
57+
dom = tiledb.Domain(tiledb.Dim(name="d", domain=(1, 10), tile=5, dtype="int32"))
58+
schema = tiledb.ArraySchema(domain=dom, sparse=False, attrs=[tiledb.Attr(name="a", dtype="float64")])
59+
tiledb.Array.create(array_name, schema, ctx=ctx)
60+
61+
def remove_profiles():
62+
# Remove the default profile
63+
tiledb.Profile.remove()
64+
65+
# Remove a specific profile by name
66+
tiledb.Profile.remove("my_profile_name")
67+
68+
if __name__ == "__main__":
69+
create_and_save_profiles()
70+
use_profiles()
71+
remove_profiles()

0 commit comments

Comments
 (0)