# LAMH client SDK (Python 3.8+, no dependencies) — © 2026 Mubtakarat for Information Technology. Free to use with a LAMH subscription. # This is the only code customers receive. It contains no Lamh engine logic: it calls the hosted API. """ from lamh_client import Lamh lamh = Lamh(os.environ["LAMH_API_KEY"]) # base_url defaults to https://api.mubtkrat.ai Guide: https://lamh.mubtkrat.ai/docs/en/ lamh.sync([{"doc_id": "refund-policy", "chunks": ["...", "..."]}]) # keep Lamh in step with your sources out = lamh.certify(retrieved_chunks, lang="ar") # before every model call prompt_context = out["context"] # validity notes already included """ import json import urllib.error import urllib.request class LamhError(Exception): def __init__(self, status, code, message): super().__init__(f"{status} {code}: {message}") self.status, self.code = status, code class Lamh: def __init__(self, api_key: str, base_url: str = "https://api.mubtkrat.ai", timeout: float = 10.0): self.key, self.base, self.timeout = api_key, base_url.rstrip("/"), timeout def _call(self, method, path, body=None): data = json.dumps(body, ensure_ascii=False).encode("utf-8") if body is not None else None req = urllib.request.Request(self.base + path, data=data, method=method, headers={"Authorization": f"Bearer {self.key}", "Content-Type": "application/json"}) try: with urllib.request.urlopen(req, timeout=self.timeout) as r: return json.loads(r.read()) except urllib.error.HTTPError as e: try: err = json.loads(e.read())["error"] except Exception: err = {"code": "http_error", "message": str(e)} raise LamhError(e.code, err["code"], err["message"]) from None def sync(self, documents, delete=()): return self._call("PUT", "/v1/documents", {"documents": list(documents), "delete": list(delete)}) def certify(self, chunks, lang="en"): return self._call("POST", "/v1/certify", {"chunks": list(chunks), "lang": lang}) def usable(self, chunks, lang="en"): """Only chunks that may reach the model, with current text.""" return [c for c in self.certify(chunks, lang)["certificates"] if c["verdict"] != "BLOCKED"] def root(self): return self._call("GET", "/v1/root") def usage(self): return self._call("GET", "/v1/usage") def registry(self, sector=None): return self._call("GET", "/v1/registry" + (f"?sector={sector}" if sector else ""))