Official Python SDK for the Nexus Legal API v1 — multi-jurisdictional legal analysis with certainty locks, async jobs, signed webhooks, organizations and sub-keys.
Project description
nexus-legal
Official Python SDK for the Nexus Legal API v1 — multi-jurisdictional legal analysis with defensible certainty locks, vector case-law search, async jobs, signed webhooks, organizations and sub-keys.
pip install nexus-legal
Requires Python ≥ 3.9.
Quick start
import os
from nexus_legal import NexusClient
nexus = NexusClient(api_key=os.environ["NEXUS_API_KEY"])
result = nexus.analyze(
text="Por el presente contrato, el arrendador cede el uso…",
jurisdiction="ES",
legal_branch="civil",
)
print(result["analysis"])
print("Rate limit remaining:", result["rate_limit"]["remaining"])
Get an API key at /developers. Full docs at /developers/docs.
Features
- Synchronous — built on
requests. Async (httpx) coming in a future release. - Auto idempotency — every
POSTcarries an auto-generatedIdempotency-Key(UUID4) reused across retries → no double-charge. - Smart retries — 429 / 5xx with exponential backoff + jitter, honoring
Retry-After. - Typed errors —
RateLimitError,InsufficientCreditsError,IdempotencyConflictError,ValidationError,AuthenticationError,ServerError,TimeoutError. - Rate-limit telemetry — every response exposes
result["rate_limit"]. - Audit-trail parser —
extract_audit_trail()returns a structuredTypedDictwithout any YAML dependency. - Webhook signature verification —
verify_webhook_signature()for incoming HMAC-signed deliveries.
API surface
nexus = NexusClient(
api_key="nlk_...",
base_url="https://nexusquantum.legal", # default
timeout=120.0, # seconds
max_retries=3,
auto_idempotency=True,
)
# Sync
nexus.analyze(text=..., jurisdiction="ES", legal_branch="civil")
nexus.analyze_batch(documents=[...], concurrency=5)
# Sandbox (no credits)
nexus.sandbox.analyze(sample="providencia_aeat")
nexus.sandbox.metadata()
# Case-law search
nexus.jurisprudencia.search(query="...", jurisdiction="ES", top_k=5)
# Catalogs and usage
nexus.jurisdictions.list()
nexus.usage.get(from_="2026-04-01", to="2026-05-01", granularity="day")
nexus.usage.csv(from_="2026-04-01", to="2026-05-01")
# Async jobs
job = nexus.jobs.create(kind="analyze", payload={"text": ..., "jurisdiction": "ES"})
snap = nexus.jobs.get(job["jobId"])
final = nexus.jobs.run(kind="analyze", payload={...}) # poll helper
# Webhooks
wh = nexus.webhooks.create(url="https://example.com/hook", events=["analysis.completed"])
print("Secret:", wh["secret"]) # shown once
# Organizations + sub-keys
org = nexus.organizations.create(name="Mi Despacho LATAM")
sk = nexus.organizations.create_key(org["organization"]["id"], child_label="Despacho Vázquez")
Error handling
from nexus_legal import (
InsufficientCreditsError,
RateLimitError,
ValidationError,
)
try:
nexus.analyze(text=text, jurisdiction="ES")
except InsufficientCreditsError as e:
print(f"Need {e.required}, have {e.balance}")
except RateLimitError as e:
time.sleep(e.retry_after)
except ValidationError as e:
print(f"Bad request: {e}")
Webhook signature verification
import os
from nexus_legal import verify_webhook_signature
from flask import Flask, request
app = Flask(__name__)
@app.post("/nexus-webhook")
def webhook():
raw = request.get_data() # bytes, pre-parse
sig = request.headers.get("X-Nexus-Signature")
if not verify_webhook_signature(
raw_body=raw,
signature=sig,
secret=os.environ["WEBHOOK_SECRET"],
):
return ("invalid signature", 401)
payload = request.get_json()
# ...
Audit-trail parsing
from nexus_legal import extract_audit_trail
trail = extract_audit_trail(result["analysis"])
if trail and trail["levels_emitted"].get("L5-C", 0) > 0:
# Critical contractual risk — escalate to human reviewer
...
The parser handles levels_emitted, review_flags, modules_active, kill_switches_triggered, rag_sources, executive_summary and exposes the raw YAML in trail["raw"] for callers who want to re-parse with PyYAML.
Versioning
This SDK targets API v1.x and follows SemVer:
- MAJOR — drops support for an API breaking change.
- MINOR — new endpoints, new fields, new options.
- PATCH — bug fixes, doc improvements.
See the API changelog.
License
MIT — see LICENSE.
Built by Nexus Legal. Questions? Email support@nexusquantum.legal.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nexus_legal-0.1.1.tar.gz.
File metadata
- Download URL: nexus_legal-0.1.1.tar.gz
- Upload date:
- Size: 11.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e37ff5938497cc02f6f12df0d2f74b5a473b81c3e6b7b533563102d4c84157d8
|
|
| MD5 |
3fa67d5c0477ec32f11b9892327744cb
|
|
| BLAKE2b-256 |
86c603c058a39a446d350997f32887a0bcb1bdda8d4ac3329b10f0257f1f876e
|
File details
Details for the file nexus_legal-0.1.1-py3-none-any.whl.
File metadata
- Download URL: nexus_legal-0.1.1-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
506cd762e760e6e0c946f10599fd3ef8cf07bf7d5685dd9e9f622970061a8454
|
|
| MD5 |
f564ae053d7c799cd39711927ce7462d
|
|
| BLAKE2b-256 |
e0c47fa0db8d04ad1355a92c42eed265c43aa9e6d5b6554f7d578d2473e7eee9
|