Skip to main content

Vengtoo Python SDK — authorization client for Vengtoo Cloud and the Vengtoo Agent

Project description

Vengtoo Python SDK

Python client for Vengtoo — works with both Vengtoo Cloud and the Vengtoo Agent.

Supports sync and async. Requires Python 3.9+.

Install

pip install vengtoo

Usage

Cloud Mode

from vengtoo import Vengtoo, Subject, Resource

client = Vengtoo(api_key="azx_...")

allowed = client.check(
    subject=Subject(id="user:123", type="user", roles=["editor"]),
    action="read",
    resource=Resource(type="document", id="doc:456"),
)

OAuth2 Client Credentials

For service-to-service auth, pass client_id and client_secret (secret is prefixed azx_cs_). The SDK exchanges credentials at the token endpoint, caches the JWT in memory, and refreshes ~60s before expiry. Both sync and async calls share the same cache.

client = Vengtoo(
    client_id="my-client-id",
    client_secret="azx_cs_...",
)

Equivalent curl for the underlying token exchange:

curl -X POST https://api.vengtoo.com/identity-srv/v1/oauth/token \
  -d grant_type=client_credentials \
  -d client_id=my-client-id \
  -d client_secret=azx_cs_...

Providing both api_key and OAuth credentials is rejected at construction. A bad client_id / client_secret surfaces as VengtooOAuthError (distinct from VengtooError) with a message pointing you at the OAuth exchange.

Agent Mode (local)

client = Vengtoo(base_url="http://localhost:8181")

Full Evaluate Response

from vengtoo import AuthorizeRequest, Action

resp = client.authorize(AuthorizeRequest(
    subject=Subject(id="user:123", type="user"),
    resource=Resource(type="document", id="doc:456"),
    action=Action(name="read"),
    context={"ip": "10.0.0.1"},
))
# resp.decision, resp.context.reason, resp.context.policy_id, resp.context.access_path

Async

allowed = await client.async_check(
    subject=Subject(id="user:123", type="user"),
    action="read",
    resource=Resource(type="document", id="doc:456"),
)

resp = await client.async_authorize(request)

FastAPI Dependency

from fastapi import FastAPI, Depends

app = FastAPI()
vengtoo = Vengtoo(api_key="azx_...")

@app.get("/documents/{id}")
async def get_doc(id: str, _=Depends(vengtoo.require("document", "read"))):
    return {"id": id}

The require() dependency extracts subject ID from the X-User-ID header by default. Customize with:

vengtoo.require("document", "read", subject_header="authorization-user-id")

Options

Vengtoo(
    api_key="azx_...",                    # API key for cloud mode
    base_url="http://localhost:8181",          # Custom URL (agent mode)
    timeout=5.0,                               # Request timeout in seconds (default: 10)
)

Types

Type Fields
Subject id, type, attributes, properties, roles
Resource id, type, attributes, properties
Action name, properties
AuthorizeRequest subject, resource, action, context
AuthorizeContext reason, reason_code, policy_id, access_path
AuthorizeResponse decision, context

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vengtoo-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vengtoo-0.1.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file vengtoo-0.1.0.tar.gz.

File metadata

  • Download URL: vengtoo-0.1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for vengtoo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 99f61a337e3d6b8f7473b60bf9eaaef0d781ce2e5b394eff5b9ce24469c3ee46
MD5 dee48505fe4298f2afc655a5f9c6ca8b
BLAKE2b-256 7f3f181c065939ec450147ceeba7ef0fd01bf98643b1cc3c1fd65cd2070b47bd

See more details on using hashes here.

File details

Details for the file vengtoo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vengtoo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.4

File hashes

Hashes for vengtoo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f9c85b2fd54859d44daa26d11204f6ff9dd51f87b449be3ee1b72c5150893ae5
MD5 4e2ca0380c0e188c68395b651fcf0e72
BLAKE2b-256 043596584f4ed2564445e820840cd959c5f2e5f685a37009729924ea44ccb548

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page