Skip to content

Commit 61548ca

Browse files
committed
Add example
1 parent 7b5f9f9 commit 61548ca

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

examples/profile.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
44+
def use_profiles():
45+
# Create a config object. This will use the default profile.
46+
cfg = tiledb.Config()
47+
print("rest.token:", cfg["rest.token"])
48+
49+
# Create a config object using a specific profile name.
50+
cfg_with_profile = tiledb.Config({"profile_name": "my_profile_name"})
51+
print("rest.server_address:", cfg_with_profile["rest.server_address"])
52+
53+
# Use on of the profile to create a context.
54+
ctx = tiledb.Ctx(cfg_with_profile)
55+
56+
# Use the context to create a new array. The REST credentials from the profile will be used.
57+
array_name = "tiledb://my_workspace/my_teamspace/my_array"
58+
dom = tiledb.Domain(tiledb.Dim(name="d", domain=(1, 10), tile=5, dtype="int32"))
59+
schema = tiledb.ArraySchema(
60+
domain=dom, sparse=False, attrs=[tiledb.Attr(name="a", dtype="float64")]
61+
)
62+
tiledb.Array.create(array_name, schema, ctx=ctx)
63+
64+
65+
def remove_profiles():
66+
# Remove the default profile
67+
tiledb.Profile.remove()
68+
69+
# Remove a specific profile by name
70+
tiledb.Profile.remove("my_profile_name")
71+
72+
73+
if __name__ == "__main__":
74+
create_and_save_profiles()
75+
use_profiles()
76+
remove_profiles()

0 commit comments

Comments
 (0)