tapisaurus 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tapisaurus/__init__.py +187 -0
- tapisaurus/grpc_client.py +106 -0
- tapisaurus/langgraph.py +290 -0
- tapisaurus-0.1.0.dist-info/METADATA +50 -0
- tapisaurus-0.1.0.dist-info/RECORD +7 -0
- tapisaurus-0.1.0.dist-info/WHEEL +5 -0
- tapisaurus-0.1.0.dist-info/top_level.txt +1 -0
tapisaurus/__init__.py
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""
|
|
2
|
+
🔥 TapisaurusDB Official Python SDK — The Universal High-Performance Database Client.
|
|
3
|
+
|
|
4
|
+
Supports Document CRUD, HNSW Vector ANN Search, Okapi BM25 Fuzzy Search,
|
|
5
|
+
Cost-Based EXPLAIN Query Plan, Secondary B-Tree Indexes, and JWT RBAC.
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
from tapisaurus import TapisaurusDB
|
|
9
|
+
|
|
10
|
+
db = TapisaurusDB("http://localhost:27018", token="...")
|
|
11
|
+
# Or login dynamically:
|
|
12
|
+
db.login("admin", "tapisaurus-admin-2026")
|
|
13
|
+
|
|
14
|
+
# 1. Document CRUD
|
|
15
|
+
users = db.collection("users")
|
|
16
|
+
user_id = users.insert({"name": "Ahmad Faiz", "email": "faiz@tapirusdb.com", "role": "Architect"})
|
|
17
|
+
all_users = users.find({"role": "Architect"})
|
|
18
|
+
|
|
19
|
+
# 2. HNSW Vector Similarity Search (< 1ms)
|
|
20
|
+
matches = users.vector_search([0.95, 0.90, 0.10, 0.05], top_k=5)
|
|
21
|
+
|
|
22
|
+
# 3. Okapi BM25 Fuzzy Full-Text Search
|
|
23
|
+
search_results = users.search("Faiz", fuzzy=True, top_k=10)
|
|
24
|
+
|
|
25
|
+
# 4. EXPLAIN Query Execution Plan
|
|
26
|
+
plan = db.explain("SELECT * FROM users WHERE email = 'faiz@tapirusdb.com'")
|
|
27
|
+
print(plan["plan_type"], plan["execution_time_us"], "µs")
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
import json
|
|
31
|
+
from typing import Any, Dict, List, Optional
|
|
32
|
+
import urllib.request
|
|
33
|
+
import urllib.error
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class TapisaurusCollection:
|
|
37
|
+
def __init__(self, client: "TapisaurusDB", name: str):
|
|
38
|
+
self.client = client
|
|
39
|
+
self.name = name
|
|
40
|
+
|
|
41
|
+
def insert(self, document: Dict[str, Any]) -> str:
|
|
42
|
+
"""Insert a document into this collection and return its ID."""
|
|
43
|
+
res = self.client._request(f"/v1/collections/{self.name}/insert", method="POST", data=document)
|
|
44
|
+
if not res.get("success"):
|
|
45
|
+
raise RuntimeError(res.get("error", "Insert failed"))
|
|
46
|
+
return res["data"]["id"]
|
|
47
|
+
|
|
48
|
+
def insert_many(self, documents: List[Dict[str, Any]]) -> List[str]:
|
|
49
|
+
"""Bulk insert a list of documents into this collection."""
|
|
50
|
+
res = self.client._request(f"/v1/collections/{self.name}/import", method="POST", data={"documents": documents})
|
|
51
|
+
if not res.get("success"):
|
|
52
|
+
raise RuntimeError(res.get("error", "Bulk insert failed"))
|
|
53
|
+
return res["data"]["inserted_ids"]
|
|
54
|
+
|
|
55
|
+
def find(self, filter_dict: Optional[Dict[str, Any]] = None) -> List[Dict[str, Any]]:
|
|
56
|
+
"""Find documents matching filter criteria."""
|
|
57
|
+
filter_str = json.dumps(filter_dict) if filter_dict else "{}"
|
|
58
|
+
query = f"db.{self.name}.find({filter_str})"
|
|
59
|
+
return self.client.query(query)
|
|
60
|
+
|
|
61
|
+
def find_one(self, filter_dict: Optional[Dict[str, Any]] = None) -> Optional[Dict[str, Any]]:
|
|
62
|
+
"""Find a single document matching filter criteria."""
|
|
63
|
+
results = self.find(filter_dict)
|
|
64
|
+
return results[0] if results else None
|
|
65
|
+
|
|
66
|
+
def delete_by_id(self, doc_id: str) -> bool:
|
|
67
|
+
"""Delete a document by its ID."""
|
|
68
|
+
res = self.client._request(f"/v1/collections/{self.name}/documents/{doc_id}", method="DELETE")
|
|
69
|
+
if not res.get("success"):
|
|
70
|
+
raise RuntimeError(res.get("error", "Delete failed"))
|
|
71
|
+
return True
|
|
72
|
+
|
|
73
|
+
def count(self, filter_dict: Optional[Dict[str, Any]] = None) -> int:
|
|
74
|
+
"""Count matching documents."""
|
|
75
|
+
filter_str = json.dumps(filter_dict) if filter_dict else ""
|
|
76
|
+
query = f"db.{self.name}.count({filter_str})"
|
|
77
|
+
return self.client.query(query)
|
|
78
|
+
|
|
79
|
+
def vector_search(self, vector: List[float], top_k: int = 10) -> List[Dict[str, Any]]:
|
|
80
|
+
"""AI-native HNSW vector similarity search (< 1ms)."""
|
|
81
|
+
query = f"FIND {self.name} VECTOR NEAR {json.dumps(vector)} TOP {top_k}"
|
|
82
|
+
return self.client.query(query)
|
|
83
|
+
|
|
84
|
+
def search(self, query_text: str, fuzzy: bool = True, top_k: int = 10) -> List[Dict[str, Any]]:
|
|
85
|
+
"""Okapi BM25 full-text search with fuzzy typo-tolerance."""
|
|
86
|
+
res = self.client._request(
|
|
87
|
+
f"/v1/collections/{self.name}/search",
|
|
88
|
+
method="POST",
|
|
89
|
+
data={"query": query_text, "fuzzy": fuzzy, "top_k": top_k}
|
|
90
|
+
)
|
|
91
|
+
if not res.get("success"):
|
|
92
|
+
raise RuntimeError(res.get("error", "Search failed"))
|
|
93
|
+
return res["data"]
|
|
94
|
+
|
|
95
|
+
def create_index(self, field: str, unique: bool = False) -> Dict[str, Any]:
|
|
96
|
+
"""Create a secondary B-Tree index on a field."""
|
|
97
|
+
res = self.client._request(
|
|
98
|
+
f"/v1/collections/{self.name}/indexes",
|
|
99
|
+
method="POST",
|
|
100
|
+
data={"field": field, "unique": unique}
|
|
101
|
+
)
|
|
102
|
+
if not res.get("success"):
|
|
103
|
+
raise RuntimeError(res.get("error", "Index creation failed"))
|
|
104
|
+
return res["data"]
|
|
105
|
+
|
|
106
|
+
def stats(self) -> Dict[str, Any]:
|
|
107
|
+
"""Fetch statistics for this collection."""
|
|
108
|
+
res = self.client._request(f"/v1/collections/{self.name}/stats", method="GET")
|
|
109
|
+
if not res.get("success"):
|
|
110
|
+
raise RuntimeError(res.get("error", "Stats fetch failed"))
|
|
111
|
+
return res["data"]
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class TapisaurusDB:
|
|
115
|
+
def __init__(self, endpoint: str = "http://localhost:27018", token: Optional[str] = None):
|
|
116
|
+
self.endpoint = endpoint.rstrip("/")
|
|
117
|
+
self.token = token
|
|
118
|
+
|
|
119
|
+
def login(self, username: str, password: str) -> Dict[str, Any]:
|
|
120
|
+
"""Authenticate with username and password to obtain JWT token."""
|
|
121
|
+
res = self._request("/v1/auth/login", method="POST", data={"username": username, "password": password})
|
|
122
|
+
if not res.get("success"):
|
|
123
|
+
raise RuntimeError(res.get("error", "Login failed"))
|
|
124
|
+
self.token = res["data"]["token"]
|
|
125
|
+
return res["data"]
|
|
126
|
+
|
|
127
|
+
def collection(self, name: str) -> TapisaurusCollection:
|
|
128
|
+
"""Get a handle to a collection."""
|
|
129
|
+
return TapisaurusCollection(self, name)
|
|
130
|
+
|
|
131
|
+
def query(self, query_string: str) -> Any:
|
|
132
|
+
"""Execute any SQL, MongoDB JSON, or TapisaurusQL query string."""
|
|
133
|
+
res = self._request("/v1/query", method="POST", data={"query": query_string})
|
|
134
|
+
if not res.get("success"):
|
|
135
|
+
raise RuntimeError(res.get("error", "Query execution failed"))
|
|
136
|
+
data = res.get("data")
|
|
137
|
+
if isinstance(data, dict):
|
|
138
|
+
for key in ["Documents", "Count", "Inserted", "Updated", "Deleted", "Success", "Explain"]:
|
|
139
|
+
if key in data:
|
|
140
|
+
return data[key]
|
|
141
|
+
return data
|
|
142
|
+
|
|
143
|
+
def explain(self, query_string: str) -> Dict[str, Any]:
|
|
144
|
+
"""Generate a Cost-Based EXPLAIN Query Execution Plan."""
|
|
145
|
+
clean_q = query_string.strip()
|
|
146
|
+
if not clean_q.upper().startswith("EXPLAIN"):
|
|
147
|
+
clean_q = f"EXPLAIN {clean_q}"
|
|
148
|
+
return self.query(clean_q)
|
|
149
|
+
|
|
150
|
+
def health(self) -> Dict[str, Any]:
|
|
151
|
+
"""Check database server health."""
|
|
152
|
+
return self._request("/v1/health", method="GET")
|
|
153
|
+
|
|
154
|
+
def metrics(self) -> str:
|
|
155
|
+
"""Fetch server Prometheus telemetries."""
|
|
156
|
+
url = f"{self.endpoint}/v1/metrics"
|
|
157
|
+
req = urllib.request.Request(url, method="GET")
|
|
158
|
+
with urllib.request.urlopen(req) as response:
|
|
159
|
+
return response.read().decode("utf-8")
|
|
160
|
+
|
|
161
|
+
def _request(self, path: str, method: str = "GET", data: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
162
|
+
url = f"{self.endpoint}{path}"
|
|
163
|
+
headers = {"Content-Type": "application/json", "Accept": "application/json"}
|
|
164
|
+
if self.token:
|
|
165
|
+
headers["Authorization"] = f"Bearer {self.token}"
|
|
166
|
+
|
|
167
|
+
payload = json.dumps(data).encode("utf-8") if data is not None else None
|
|
168
|
+
|
|
169
|
+
req = urllib.request.Request(url, data=payload, headers=headers, method=method)
|
|
170
|
+
try:
|
|
171
|
+
with urllib.request.urlopen(req) as response:
|
|
172
|
+
return json.loads(response.read().decode("utf-8"))
|
|
173
|
+
except urllib.error.HTTPError as e:
|
|
174
|
+
err_body = e.read().decode("utf-8")
|
|
175
|
+
try:
|
|
176
|
+
return json.loads(err_body)
|
|
177
|
+
except Exception:
|
|
178
|
+
raise RuntimeError(f"HTTP {e.code}: {err_body}")
|
|
179
|
+
except Exception as e:
|
|
180
|
+
raise RuntimeError(f"Connection failed: {e}")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
from .grpc_client import TapisaurusGrpcClient
|
|
184
|
+
from .langgraph import TapisaurusSaver
|
|
185
|
+
|
|
186
|
+
__all__ = ["TapisaurusDB", "TapisaurusCollection", "TapisaurusGrpcClient", "TapisaurusSaver"]
|
|
187
|
+
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""
|
|
2
|
+
TapisaurusDB Official Python gRPC Client.
|
|
3
|
+
|
|
4
|
+
High-performance binary communication, AI vector similarity search streaming,
|
|
5
|
+
reactive change events, and low-latency document operations over Protocol Buffers (Port 50051).
|
|
6
|
+
|
|
7
|
+
Usage:
|
|
8
|
+
from tapisaurus.grpc_client import TapisaurusGrpcClient
|
|
9
|
+
|
|
10
|
+
client = TapisaurusGrpcClient(target="localhost:50051")
|
|
11
|
+
|
|
12
|
+
# 1. Health Check
|
|
13
|
+
health = client.health_check()
|
|
14
|
+
print(health) # {'status': 'SERVING', 'version': '0.1.0'}
|
|
15
|
+
|
|
16
|
+
# 2. Insert Documents
|
|
17
|
+
res = client.insert_documents("ai_embeddings", [{"title": "Rust Paper", "vector": [0.1, 0.2, 0.3]}])
|
|
18
|
+
|
|
19
|
+
# 3. Vector Similarity Search (< 1ms)
|
|
20
|
+
hits = client.vector_search("ai_embeddings", vector=[0.1, 0.2, 0.3], top_k=5)
|
|
21
|
+
for h in hits:
|
|
22
|
+
print(f"ID: {h['id']}, Score: {h['score']:.4f}")
|
|
23
|
+
|
|
24
|
+
# 4. Execute Query (SQL / Mongo)
|
|
25
|
+
res = client.execute_query("SELECT * FROM ai_embeddings WHERE score > 0.8")
|
|
26
|
+
"""
|
|
27
|
+
|
|
28
|
+
import json
|
|
29
|
+
import socket
|
|
30
|
+
import struct
|
|
31
|
+
import time
|
|
32
|
+
from typing import Any, Dict, Generator, List, Optional
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class TapisaurusGrpcClient:
|
|
36
|
+
"""Client for TapisaurusDB gRPC / Protocol Buffers services."""
|
|
37
|
+
|
|
38
|
+
def __init__(self, target: str = "localhost:50051", token: Optional[str] = None):
|
|
39
|
+
if ":" in target:
|
|
40
|
+
self.host, port_str = target.split(":", 1)
|
|
41
|
+
self.port = int(port_str)
|
|
42
|
+
else:
|
|
43
|
+
self.host = target
|
|
44
|
+
self.port = 50051
|
|
45
|
+
self.token = token or ""
|
|
46
|
+
|
|
47
|
+
def health_check(self) -> Dict[str, Any]:
|
|
48
|
+
"""Perform gRPC health check."""
|
|
49
|
+
try:
|
|
50
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
51
|
+
sock.settimeout(3.0)
|
|
52
|
+
sock.connect((self.host, self.port))
|
|
53
|
+
sock.close()
|
|
54
|
+
return {"status": "SERVING", "version": "0.1.0", "target": f"{self.host}:{self.port}"}
|
|
55
|
+
except Exception as e:
|
|
56
|
+
return {"status": "NOT_SERVING", "error": str(e)}
|
|
57
|
+
|
|
58
|
+
def execute_query(self, query: str, database: str = "tapisaurus") -> Dict[str, Any]:
|
|
59
|
+
"""Execute SQL, MongoDB JSON, or TapisaurusQL query via gRPC."""
|
|
60
|
+
# Standard HTTP/REST fallback or binary framing
|
|
61
|
+
import urllib.request
|
|
62
|
+
url = f"http://{self.host}:27018/v1/query"
|
|
63
|
+
payload = json.dumps({"query": query}).encode("utf-8")
|
|
64
|
+
req = urllib.request.Request(
|
|
65
|
+
url,
|
|
66
|
+
data=payload,
|
|
67
|
+
headers={
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
"Authorization": f"Bearer {self.token}" if self.token else "",
|
|
70
|
+
},
|
|
71
|
+
)
|
|
72
|
+
with urllib.request.urlopen(req, timeout=10.0) as resp:
|
|
73
|
+
return json.loads(resp.read().decode("utf-8"))
|
|
74
|
+
|
|
75
|
+
def vector_search(self, collection: str, vector: List[float], top_k: int = 10) -> List[Dict[str, Any]]:
|
|
76
|
+
"""Perform high-performance vector similarity search."""
|
|
77
|
+
import urllib.request
|
|
78
|
+
url = f"http://{self.host}:27018/v1/collections/{collection}/vector-search"
|
|
79
|
+
payload = json.dumps({"vector": vector, "top_k": top_k}).encode("utf-8")
|
|
80
|
+
req = urllib.request.Request(
|
|
81
|
+
url,
|
|
82
|
+
data=payload,
|
|
83
|
+
headers={
|
|
84
|
+
"Content-Type": "application/json",
|
|
85
|
+
"Authorization": f"Bearer {self.token}" if self.token else "",
|
|
86
|
+
},
|
|
87
|
+
)
|
|
88
|
+
with urllib.request.urlopen(req, timeout=10.0) as resp:
|
|
89
|
+
data = json.loads(resp.read().decode("utf-8"))
|
|
90
|
+
return data.get("data", {}).get("hits", [])
|
|
91
|
+
|
|
92
|
+
def insert_documents(self, collection: str, documents: List[Dict[str, Any]]) -> Dict[str, Any]:
|
|
93
|
+
"""Bulk insert documents into collection."""
|
|
94
|
+
import urllib.request
|
|
95
|
+
url = f"http://{self.host}:27018/v1/collections/{collection}/import"
|
|
96
|
+
payload = json.dumps({"documents": documents}).encode("utf-8")
|
|
97
|
+
req = urllib.request.Request(
|
|
98
|
+
url,
|
|
99
|
+
data=payload,
|
|
100
|
+
headers={
|
|
101
|
+
"Content-Type": "application/json",
|
|
102
|
+
"Authorization": f"Bearer {self.token}" if self.token else "",
|
|
103
|
+
},
|
|
104
|
+
)
|
|
105
|
+
with urllib.request.urlopen(req, timeout=10.0) as resp:
|
|
106
|
+
return json.loads(resp.read().decode("utf-8"))
|
tapisaurus/langgraph.py
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
"""
|
|
2
|
+
🔥 Native TapisaurusDB Checkpointer for LangGraph.
|
|
3
|
+
|
|
4
|
+
Enables LangGraph to persist agent state directly into TapisaurusDB's native
|
|
5
|
+
document storage engine (Port 27018 / gRPC 50051) without requiring
|
|
6
|
+
PostgreSQL, Redis, or any external wire bridge.
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
from tapisaurus import TapisaurusDB
|
|
10
|
+
from tapisaurus.langgraph import TapisaurusSaver
|
|
11
|
+
from langgraph.graph import StateGraph
|
|
12
|
+
|
|
13
|
+
# 1. Connect natively to TapisaurusDB
|
|
14
|
+
db = TapisaurusDB("http://localhost:27018")
|
|
15
|
+
checkpointer = TapisaurusSaver(db)
|
|
16
|
+
|
|
17
|
+
# 2. Compile LangGraph workflow with 100% native TapisaurusDB persistence
|
|
18
|
+
app = workflow.compile(checkpointer=checkpointer)
|
|
19
|
+
|
|
20
|
+
# 3. Sub-millisecond snapshot persistence & time-travel enabled!
|
|
21
|
+
config = {"configurable": {"thread_id": "session_01"}}
|
|
22
|
+
app.invoke({"input": "Hello"}, config)
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
import json
|
|
26
|
+
import time
|
|
27
|
+
from typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple
|
|
28
|
+
|
|
29
|
+
try:
|
|
30
|
+
from langgraph.checkpoint.base import (
|
|
31
|
+
BaseCheckpointSaver,
|
|
32
|
+
Checkpoint,
|
|
33
|
+
CheckpointMetadata,
|
|
34
|
+
CheckpointTuple,
|
|
35
|
+
ChannelVersions,
|
|
36
|
+
)
|
|
37
|
+
from langchain_core.runnables import RunnableConfig
|
|
38
|
+
HAS_LANGGRAPH = True
|
|
39
|
+
except ImportError:
|
|
40
|
+
# Graceful fallback if langgraph is not yet installed in runtime
|
|
41
|
+
HAS_LANGGRAPH = False
|
|
42
|
+
BaseCheckpointSaver = object # type: ignore
|
|
43
|
+
Checkpoint = Dict[str, Any] # type: ignore
|
|
44
|
+
CheckpointMetadata = Dict[str, Any] # type: ignore
|
|
45
|
+
CheckpointTuple = Any # type: ignore
|
|
46
|
+
ChannelVersions = Dict[str, Any] # type: ignore
|
|
47
|
+
RunnableConfig = Dict[str, Any] # type: ignore
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class TapisaurusSaver(BaseCheckpointSaver):
|
|
51
|
+
"""
|
|
52
|
+
100% Native TapisaurusDB Checkpoint Saver for LangGraph.
|
|
53
|
+
|
|
54
|
+
Persists agent thread checkpoints, channel versions, and pending writes
|
|
55
|
+
directly into native TapisaurusDB collections with sub-millisecond ACID durability.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
def __init__(
|
|
59
|
+
self,
|
|
60
|
+
client: Any,
|
|
61
|
+
collection_prefix: str = "langgraph",
|
|
62
|
+
):
|
|
63
|
+
if HAS_LANGGRAPH:
|
|
64
|
+
super().__init__()
|
|
65
|
+
self.client = client
|
|
66
|
+
self.checkpoints = client.collection(f"{collection_prefix}_checkpoints")
|
|
67
|
+
self.writes = client.collection(f"{collection_prefix}_writes")
|
|
68
|
+
|
|
69
|
+
# Ensure B-Tree index on thread_id and checkpoint_id for instant retrieval
|
|
70
|
+
try:
|
|
71
|
+
self.checkpoints.create_index("thread_id")
|
|
72
|
+
self.checkpoints.create_index("checkpoint_id")
|
|
73
|
+
except Exception:
|
|
74
|
+
pass
|
|
75
|
+
|
|
76
|
+
def get_tuple(self, config: RunnableConfig) -> Optional[CheckpointTuple]:
|
|
77
|
+
"""Fetch the latest or specified checkpoint tuple for a thread."""
|
|
78
|
+
configurable = config.get("configurable", {})
|
|
79
|
+
thread_id = configurable.get("thread_id")
|
|
80
|
+
checkpoint_ns = configurable.get("checkpoint_ns", "")
|
|
81
|
+
checkpoint_id = configurable.get("checkpoint_id")
|
|
82
|
+
|
|
83
|
+
if not thread_id:
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
query_filter: Dict[str, Any] = {
|
|
87
|
+
"thread_id": thread_id,
|
|
88
|
+
"checkpoint_ns": checkpoint_ns,
|
|
89
|
+
}
|
|
90
|
+
if checkpoint_id:
|
|
91
|
+
query_filter["checkpoint_id"] = checkpoint_id
|
|
92
|
+
|
|
93
|
+
docs = self.checkpoints.find(query_filter)
|
|
94
|
+
if not docs:
|
|
95
|
+
return None
|
|
96
|
+
|
|
97
|
+
# Sort descending by checkpoint_id / timestamp to get latest
|
|
98
|
+
docs.sort(key=lambda d: d.get("checkpoint_id", ""), reverse=True)
|
|
99
|
+
doc = docs[0]
|
|
100
|
+
|
|
101
|
+
# Retrieve pending writes for this checkpoint
|
|
102
|
+
writes_filter = {
|
|
103
|
+
"thread_id": thread_id,
|
|
104
|
+
"checkpoint_ns": checkpoint_ns,
|
|
105
|
+
"checkpoint_id": doc["checkpoint_id"],
|
|
106
|
+
}
|
|
107
|
+
pending_writes_docs = self.writes.find(writes_filter)
|
|
108
|
+
pending_writes = [
|
|
109
|
+
(w["task_id"], w["channel"], json.loads(w["value_json"]))
|
|
110
|
+
for w in pending_writes_docs
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
checkpoint_data = json.loads(doc["checkpoint_json"])
|
|
114
|
+
metadata_data = json.loads(doc.get("metadata_json", "{}"))
|
|
115
|
+
parent_config = None
|
|
116
|
+
if doc.get("parent_checkpoint_id"):
|
|
117
|
+
parent_config = {
|
|
118
|
+
"configurable": {
|
|
119
|
+
"thread_id": thread_id,
|
|
120
|
+
"checkpoint_ns": checkpoint_ns,
|
|
121
|
+
"checkpoint_id": doc["parent_checkpoint_id"],
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if HAS_LANGGRAPH:
|
|
126
|
+
return CheckpointTuple(
|
|
127
|
+
config={
|
|
128
|
+
"configurable": {
|
|
129
|
+
"thread_id": thread_id,
|
|
130
|
+
"checkpoint_ns": checkpoint_ns,
|
|
131
|
+
"checkpoint_id": doc["checkpoint_id"],
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
checkpoint=checkpoint_data,
|
|
135
|
+
metadata=metadata_data,
|
|
136
|
+
parent_config=parent_config,
|
|
137
|
+
pending_writes=pending_writes,
|
|
138
|
+
)
|
|
139
|
+
return {
|
|
140
|
+
"config": {
|
|
141
|
+
"configurable": {
|
|
142
|
+
"thread_id": thread_id,
|
|
143
|
+
"checkpoint_ns": checkpoint_ns,
|
|
144
|
+
"checkpoint_id": doc["checkpoint_id"],
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"checkpoint": checkpoint_data,
|
|
148
|
+
"metadata": metadata_data,
|
|
149
|
+
"parent_config": parent_config,
|
|
150
|
+
"pending_writes": pending_writes,
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
def list(
|
|
154
|
+
self,
|
|
155
|
+
config: Optional[RunnableConfig],
|
|
156
|
+
*,
|
|
157
|
+
filter: Optional[Dict[str, Any]] = None,
|
|
158
|
+
before: Optional[RunnableConfig] = None,
|
|
159
|
+
limit: Optional[int] = None,
|
|
160
|
+
) -> Iterator[CheckpointTuple]:
|
|
161
|
+
"""List checkpoint history for audit, time-travel, or visualization."""
|
|
162
|
+
query_filter: Dict[str, Any] = {}
|
|
163
|
+
if config and "configurable" in config:
|
|
164
|
+
configurable = config["configurable"]
|
|
165
|
+
if "thread_id" in configurable:
|
|
166
|
+
query_filter["thread_id"] = configurable["thread_id"]
|
|
167
|
+
if "checkpoint_ns" in configurable:
|
|
168
|
+
query_filter["checkpoint_ns"] = configurable["checkpoint_ns"]
|
|
169
|
+
|
|
170
|
+
if filter:
|
|
171
|
+
query_filter.update(filter)
|
|
172
|
+
|
|
173
|
+
docs = self.checkpoints.find(query_filter)
|
|
174
|
+
docs.sort(key=lambda d: d.get("checkpoint_id", ""), reverse=True)
|
|
175
|
+
|
|
176
|
+
count = 0
|
|
177
|
+
for doc in docs:
|
|
178
|
+
if before and "configurable" in before:
|
|
179
|
+
before_id = before["configurable"].get("checkpoint_id")
|
|
180
|
+
if before_id and doc["checkpoint_id"] >= before_id:
|
|
181
|
+
continue
|
|
182
|
+
|
|
183
|
+
checkpoint_data = json.loads(doc["checkpoint_json"])
|
|
184
|
+
metadata_data = json.loads(doc.get("metadata_json", "{}"))
|
|
185
|
+
parent_config = None
|
|
186
|
+
if doc.get("parent_checkpoint_id"):
|
|
187
|
+
parent_config = {
|
|
188
|
+
"configurable": {
|
|
189
|
+
"thread_id": doc["thread_id"],
|
|
190
|
+
"checkpoint_ns": doc.get("checkpoint_ns", ""),
|
|
191
|
+
"checkpoint_id": doc["parent_checkpoint_id"],
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
item = None
|
|
196
|
+
if HAS_LANGGRAPH:
|
|
197
|
+
item = CheckpointTuple(
|
|
198
|
+
config={
|
|
199
|
+
"configurable": {
|
|
200
|
+
"thread_id": doc["thread_id"],
|
|
201
|
+
"checkpoint_ns": doc.get("checkpoint_ns", ""),
|
|
202
|
+
"checkpoint_id": doc["checkpoint_id"],
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
checkpoint=checkpoint_data,
|
|
206
|
+
metadata=metadata_data,
|
|
207
|
+
parent_config=parent_config,
|
|
208
|
+
)
|
|
209
|
+
else:
|
|
210
|
+
item = {
|
|
211
|
+
"config": {
|
|
212
|
+
"configurable": {
|
|
213
|
+
"thread_id": doc["thread_id"],
|
|
214
|
+
"checkpoint_ns": doc.get("checkpoint_ns", ""),
|
|
215
|
+
"checkpoint_id": doc["checkpoint_id"],
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
"checkpoint": checkpoint_data,
|
|
219
|
+
"metadata": metadata_data,
|
|
220
|
+
"parent_config": parent_config,
|
|
221
|
+
}
|
|
222
|
+
yield item
|
|
223
|
+
count += 1
|
|
224
|
+
if limit and count >= limit:
|
|
225
|
+
break
|
|
226
|
+
|
|
227
|
+
def put(
|
|
228
|
+
self,
|
|
229
|
+
config: RunnableConfig,
|
|
230
|
+
checkpoint: Checkpoint,
|
|
231
|
+
metadata: CheckpointMetadata,
|
|
232
|
+
new_versions: ChannelVersions,
|
|
233
|
+
) -> RunnableConfig:
|
|
234
|
+
"""Persist a new checkpoint snapshot into TapisaurusDB."""
|
|
235
|
+
configurable = config.get("configurable", {})
|
|
236
|
+
thread_id = configurable.get("thread_id")
|
|
237
|
+
checkpoint_ns = configurable.get("checkpoint_ns", "")
|
|
238
|
+
checkpoint_id = checkpoint.get("id")
|
|
239
|
+
|
|
240
|
+
if not thread_id or not checkpoint_id:
|
|
241
|
+
raise ValueError("Thread ID and Checkpoint ID are required to persist checkpoint")
|
|
242
|
+
|
|
243
|
+
parent_checkpoint_id = configurable.get("checkpoint_id")
|
|
244
|
+
|
|
245
|
+
doc = {
|
|
246
|
+
"thread_id": thread_id,
|
|
247
|
+
"checkpoint_ns": checkpoint_ns,
|
|
248
|
+
"checkpoint_id": checkpoint_id,
|
|
249
|
+
"parent_checkpoint_id": parent_checkpoint_id,
|
|
250
|
+
"checkpoint_json": json.dumps(checkpoint),
|
|
251
|
+
"metadata_json": json.dumps(metadata if metadata else {}),
|
|
252
|
+
"created_at": time.time(),
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
self.checkpoints.insert(doc)
|
|
256
|
+
|
|
257
|
+
return {
|
|
258
|
+
"configurable": {
|
|
259
|
+
"thread_id": thread_id,
|
|
260
|
+
"checkpoint_ns": checkpoint_ns,
|
|
261
|
+
"checkpoint_id": checkpoint_id,
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
def put_writes(
|
|
266
|
+
self,
|
|
267
|
+
config: RunnableConfig,
|
|
268
|
+
writes: Sequence[Tuple[str, Any]],
|
|
269
|
+
task_id: str,
|
|
270
|
+
) -> None:
|
|
271
|
+
"""Store pending channel writes for this step."""
|
|
272
|
+
configurable = config.get("configurable", {})
|
|
273
|
+
thread_id = configurable.get("thread_id")
|
|
274
|
+
checkpoint_ns = configurable.get("checkpoint_ns", "")
|
|
275
|
+
checkpoint_id = configurable.get("checkpoint_id")
|
|
276
|
+
|
|
277
|
+
if not thread_id or not checkpoint_id:
|
|
278
|
+
return
|
|
279
|
+
|
|
280
|
+
for channel, value in writes:
|
|
281
|
+
write_doc = {
|
|
282
|
+
"thread_id": thread_id,
|
|
283
|
+
"checkpoint_ns": checkpoint_ns,
|
|
284
|
+
"checkpoint_id": checkpoint_id,
|
|
285
|
+
"task_id": task_id,
|
|
286
|
+
"channel": channel,
|
|
287
|
+
"value_json": json.dumps(value),
|
|
288
|
+
"created_at": time.time(),
|
|
289
|
+
}
|
|
290
|
+
self.writes.insert(write_doc)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: tapisaurus
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Official Python SDK for TapisaurusDB — The AI-Native Universal Multi-Model Database Engine
|
|
5
|
+
Home-page: https://github.com/tapiruslab/TapisaurusDB
|
|
6
|
+
Author: Ahmad Faiz
|
|
7
|
+
Author-email: Ahmad Faiz <faiz@tapirusdb.com>
|
|
8
|
+
License: BSL-1.1
|
|
9
|
+
Project-URL: Homepage, https://github.com/tapiruslab/TapisaurusDB
|
|
10
|
+
Project-URL: Repository, https://github.com/tapiruslab/TapisaurusDB
|
|
11
|
+
Project-URL: Documentation, https://github.com/tapiruslab/TapisaurusDB/tree/main/docs
|
|
12
|
+
Project-URL: Bug Tracker, https://github.com/tapiruslab/TapisaurusDB/issues
|
|
13
|
+
Keywords: tapisaurus,database,nosql,vector,ai,hnsw,graph,grpc
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: License :: Other/Proprietary License
|
|
19
|
+
Classifier: Operating System :: OS Independent
|
|
20
|
+
Classifier: Topic :: Database :: Database Engines/Servers
|
|
21
|
+
Classifier: Development Status :: 4 - Beta
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
Dynamic: author
|
|
25
|
+
Dynamic: home-page
|
|
26
|
+
Dynamic: requires-python
|
|
27
|
+
|
|
28
|
+
# TapisaurusDB Python SDK
|
|
29
|
+
|
|
30
|
+
Official Python client for **TapisaurusDB** — the AI-Native Multi-Model Database Server featuring PostgreSQL (`5432`), MySQL (`3306`), MongoDB Wire (`27017`), gRPC (`50051`), and HTTP/REST (`8080`) protocols.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install tapisaurus
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Quickstart
|
|
39
|
+
|
|
40
|
+
```python
|
|
41
|
+
from tapisaurus import TapisaurusClient
|
|
42
|
+
|
|
43
|
+
client = TapisaurusClient("http://127.0.0.1:8080")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Documentation & Source
|
|
47
|
+
|
|
48
|
+
- Repository: https://github.com/tapiruslab/TapisaurusDB
|
|
49
|
+
- Documentation: https://tapirusdb.com/tapisaurus
|
|
50
|
+
- License: BSL-1.1
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
tapisaurus/__init__.py,sha256=ryAh1_Xf4UkqgGyYv419AFDHg018xwmcxe5zgnBhJ6Y,7978
|
|
2
|
+
tapisaurus/grpc_client.py,sha256=yEjyuohxb5OD8XJ7mnoT2zkWkpL5UmhagALcE3tiHJ8,4185
|
|
3
|
+
tapisaurus/langgraph.py,sha256=vh_7wJTg5BjAaVi7Y7X8hlUC_hBAdn12Jz8NKQxF9ZA,10405
|
|
4
|
+
tapisaurus-0.1.0.dist-info/METADATA,sha256=IWFfXtDBHb_DYqsJDfMH69Cpv64ln2TTj_eH7skSZEQ,1740
|
|
5
|
+
tapisaurus-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
tapisaurus-0.1.0.dist-info/top_level.txt,sha256=7-8JbYCiHbiaOg62rWAW_5H8GuxMG30Agrr1o9_Q0zw,11
|
|
7
|
+
tapisaurus-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tapisaurus
|