-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttp_usage.py
More file actions
69 lines (55 loc) · 1.82 KB
/
http_usage.py
File metadata and controls
69 lines (55 loc) · 1.82 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env python3
"""
HTTP usage example for RiceDB Python client.
Forces HTTP transport.
"""
import os
from dotenv import load_dotenv
from ricedb import RiceDBClient
load_dotenv()
HOST = os.environ.get("HOST", "localhost")
PORT = int(os.environ.get("PORT", "50051"))
PASSWORD = os.environ.get("PASSWORD", "admin")
SSL = os.environ.get("SSL", "false").lower() == "true"
def main():
print(" RiceDB Python Client - HTTP Usage Example\n")
# Initialize client (force HTTP)
client = RiceDBClient(HOST, port=PORT, transport="http")
client.ssl = SSL
# Connect to the server
print("1 Connecting to RiceDB server (HTTP)...")
try:
if client.connect():
transport_info = client.get_transport_info()
print(f" Connected via {transport_info['type'].upper()}")
# Login
print(" Logging in...")
client.login("admin", PASSWORD)
print(" Logged in successfully")
else:
print(" Failed to connect to RiceDB server")
return
except Exception as e:
print(f" Connection error: {e}")
return
# Basic insert/search (same as basic_usage)
# ... simplified for brevity, just one insert/search
print("\n2 Test Insert...")
try:
result = client.insert(
node_id=1,
text="HTTP Test Document",
metadata={"test": "http"},
)
print(f" Inserted: {result.get('success')}")
except Exception as e:
print(f" Insert error: {e}")
print("\n3 Test Search...")
try:
results = client.search(query="test document", user_id=1)
print(f" Found {len(results)} results")
except Exception as e:
print(f" Search error: {e}")
client.disconnect()
if __name__ == "__main__":
main()