-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvaliditi.py
More file actions
32 lines (28 loc) · 1.57 KB
/
Copy pathvaliditi.py
File metadata and controls
32 lines (28 loc) · 1.57 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
"""Thin HTTP client for the Validiti API. Pure stdlib. Contains NO Validiti engine — it only calls your
endpoints. MIT-licensed convenience wrapper."""
import json, urllib.request
class Validiti:
def __init__(self, base_url, api_key):
self.base = base_url.rstrip("/")
self.key = api_key
def _post(self, path, payload):
req = urllib.request.Request(
self.base + path,
data=json.dumps(payload).encode(),
headers={"Authorization": f"Bearer {self.key}", "Content-Type": "application/json"},
)
with urllib.request.urlopen(req) as r:
return json.load(r)
def _get(self, path):
req = urllib.request.Request(self.base + path, headers={"Authorization": f"Bearer {self.key}"})
with urllib.request.urlopen(req) as r:
return json.load(r)
# AI
def ask(self, query): return self._post("/ask", {"query": query})
def sense(self, record_id, field, new): return self._post("/sense", {"record_id": record_id, "field": field, "new": new})
# REST
def compute(self, op, scope=None, **params): return self._post("/compute", {"op": op, "scope": scope, **params})
def verify(self, envelope): return self._post("/verify", {"envelope": envelope})
def intake(self, obj): return self._post("/intake", {"object": obj})
def search(self, query, bucket=None): return self._post("/_validiti/search", {"query": query, "bucket": bucket})
def health(self): return self._get("/health")