-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgetting-started.py
49 lines (34 loc) · 1.29 KB
/
getting-started.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from terminusdb_client import WOQLClient
from terminusdb_client.woqlschema import WOQLSchema, DocumentTemplate, LexicalKey
user = "jimbo"
team = "logicistics" # My team name.
endpoint = f"https://cloud.terminusdb.com/{team}/"
client = WOQLClient(endpoint)
client.connect(user=user, team=team, use_token=True)
client.create_database("example_db")
schema = WOQLSchema()
class Player(DocumentTemplate):
_schema = schema
_key = LexicalKey(["name"])
name: str
position: str
schema.commit(client, commit_msg = "Adding Player Schema")
objects = [
Player(name="George", position="Centre Back"),
Player(name="Doug", position="Full Back"),
Player(name="Karen", position="Centre Forward")
]
client.insert_document(objects, commit_msg = f"Inserting player data")
documents = client.get_all_documents()
# documents comes back as a iterable that can be convert into a list
print("All documents")
print(list(documents))
print("=============")
# getting a specific document by id
player_doug = client.get_document("Player/Doug")
print("Specific document")
print(player_doug)
matches = client.query_document({"@type" : "Player",
"position": "Full Back"})
# matches comes back as a iterable that can be convert into a list
print(list(matches))