Skip to main content

legant-sdk (Python)

Offline verifier + authorizer for Legant delegation tokens. Its only dependency is cryptography (Python ≥ 3.9).

from legant_sdk import fetch_jwks, Verifier, Action, fetch_revocation_feed

issuer = "https://auth.example.com"
keys = fetch_jwks(f"{issuer}/.well-known/jwks.json")

# Tier B (optional): reject revoked tokens offline, refreshed in the background.
feed = fetch_revocation_feed(f"{issuer}/.well-known/revoked", issuer, keys)
feed.start_polling(10.0, on_error=print)

verifier = Verifier(issuer, "https://my-api.example/", keys, feed=feed)

# Per request:
claims = verifier.verify(bearer_token)  # raises VerifyError / RevokedError on failure
claims.authorize(Action(scope="expenses:submit", amount=120, category="travel"))  # raises AuthorizeError on 403
print(claims.provenance())  # "user:alice -> agent:assistant"

verify raises VerifyError (or RevokedError when the token is in the feed); authorize raises AuthorizeError when a scope or constraint is denied. Catch them to return 401 / 403.

Guard an agent's tools — any framework

AgentGuard wraps any tool callable so every invocation is authorized against the agent's delegation token — offline, no callback. The wrapped function is a plain callable, so it drops into LangChain, CrewAI, LlamaIndex, AutoGen, or your own loop unchanged. A prompt-injected or buggy agent cannot exceed the scoped, revocable slice the token carries.

from legant_sdk import Verifier, AgentGuard

verifier = Verifier(issuer, "https://my-api.example/", keys, feed=feed)
guard = AgentGuard(verifier, token=agent_delegation_token)  # token may be a callable, to refresh

@guard.tool("expenses:submit", amount_arg="amount", category_arg="category")
def submit_expense(amount: float, category: str) -> str:
    ...  # only runs if the token permits this scope, amount, and category — else AuthorizeError

# LangChain: from langchain_core.tools import tool;  lc_tool = tool(submit_expense)
# CrewAI:    @tool("Submit expense")  def submit_expense(...): ...  then wrap with @guard.tool(...)

Or check inline without the decorator: guard.authorize("scope", amount=…) (raises) or guard.allowed("scope", amount=…) (returns a bool).

Test

python3 -m unittest discover -s tests    # runs the shared conformance vectors (see ../conformance)

Metadata

Release files for legant-sdk 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for legant-sdk 0.1.1
File Size Uploaded Provenance Actions
legant_sdk-0.1.1.tar.gz 13.0 kB Without provenance Details for legant_sdk-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for legant-sdk 0.1.1
File Interpreter ABI Platform Actions
legant_sdk-0.1.1-py3-none-any.whl Python 3 none any Details for legant_sdk-0.1.1-py3-none-any.whl

Total release size: 24.7 kB

Release files / legant_sdk-0.1.1.tar.gz

Download URL legant_sdk-0.1.1.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
57e279e9bbe17bd23125e054cb5b6ccb088d32d710c03117ec33e641686032d7
BLAKE2b-256 checksum
How to use checksums
05a060a2aad521ae93b75557bef3e1f710f6a8ae26c8d310e00a7a893840b376
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / legant_sdk-0.1.1-py3-none-any.whl

Download URL legant_sdk-0.1.1-py3-none-any.whl
Size 11.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0bd5b2bf3fb0a878f339940f98f934a0d992d088da3c43d45554ac6094247542
BLAKE2b-256 checksum
How to use checksums
f7ba4435625216eef0c3325ae56358cca44bdb5a98f6c1c916b4d7e77624d2b4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for legant-sdk 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page