Skip to main content

teamusers Python SDK

This package verifies teamusers Ed25519 (EdDSA) access tokens, caches the service JWKS document, and provides local permission and ABAC authorization helpers. The verifier and middleware are synchronous; no event loop is required for ordinary SDK use.

Install

python -m pip install teamusers-sdk

For a checkout, install the local package instead:

python -m pip install ./sdk/python

NATS permission invalidation is optional:

python -m pip install 'teamusers-sdk[nats-py]'

Verification

from teamusers_sdk import Verifier

verifier = Verifier("https://iam.example.com", audience="orders")
claims = verifier.verify(access_token)

print(claims.subject, claims.kind, claims.perm_ver)

The second positional argument is the expected audience and defaults to "teamusers". A custom synchronous fetcher(url) can be supplied for an application HTTP transport or tests. cache_ttl is measured in seconds. Concurrent verification calls share one JWKS fetch, including a key-ID miss refresh.

Verifier.verify returns an immutable Claims object after checking the Ed25519 signature, issuer, expiration, exactly-one-entry audience, and required application claims.

Field Type Meaning
subject (sub) str Non-empty user or service subject
team str Optional team claim, or "" when absent
kind Literal["user", "service"] Subject kind
perm_ver (permVer) int Non-negative permission version
expiry (exp) datetime Expiration in UTC; exp exposes Unix seconds
audience (aud) str or tuple[str, ...] Verified JWT audience; lists must contain exactly one value

Verification failures use typed exceptions: JWKSFetchError for key retrieval, TokenVerificationError for signature/JOSE failures, and TokenClaimsError for invalid application claims. All inherit from SDKError.

Permissions

from teamusers_sdk import PermissionsClient

permissions = PermissionsClient(
    "https://iam.example.com",
    service_token="service-token",
)
entry = permissions.Get("user-id", claims.perm_ver)
allowed, reason = permissions.Allow(claims, "orders:read:team", {"team_id": "team-1"})

Permission entries are fetched from GET /authz/permissions/{userID}, cached for two minutes by default, and single-flighted per user. A token perm_ver mismatch bypasses the cached entry. Use Invalidate(user_id), InvalidateAll(), or Clear() after an application-side change. Check(subject, permission, resource) performs the authoritative POST /authz/check request.

Permission keys use resource:action:scope grammar. Actions and scopes may use their documented wildcards; a leading ! is an explicit deny and wins against a matching allow. Parse, Validate, String, Match, and MatchKeys are available in Go-shaped and Pythonic spellings.

Conditions and middleware

Conditions are compiled by CompileCondition without an expression-language dependency. The supported context is subject.id, subject.kind, resource.owner_id, resource.team_id, resource.attrs[...], and request.time, with boolean operators, comparisons, in, and scalar literals. Sources are limited to 4 KiB and unsupported or failed evaluations deny access.

from teamusers_sdk import Client, Require

client = Client(verifier, permissions)
check = Require(client, request, claims, "orders:read:team", {"team_id": "team-1"})

Authenticate(request, verifier) returns Claims or raises UnauthorizedError (HTTP 401). Require returns Claims or raises ForbiddenError (HTTP 403). Both accept the minimal request shape {"headers": ..., "method": ...}.

Event invalidation

subscription = permissions.SubscribePermissions(
    "nats://127.0.0.1:4222",
    lambda user_ids: print(user_ids),
)
# later
subscription.Close()

The optional subscription listens to iam.perm.changed, iam.user.disabled, and iam.role.updated, invalidating each event's user_ids. Tests and applications that already own a connection can inject a subscription source object with subscribe(subject, callback) instead of a URL. The missing optional dependency is reported as NATSUnavailableError when SubscribePermissions is called; importing the core SDK never requires NATS.

Release files for teamusers-sdk 0.1.0

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

Source distribution (sdist)

Source distribution for teamusers-sdk 0.1.0
File Size Uploaded
teamusers_sdk-0.1.0.tar.gz 26.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for teamusers-sdk 0.1.0
File Interpreter ABI Platform
teamusers_sdk-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 51.6 kB

Release files / teamusers_sdk-0.1.0.tar.gz

Download URL teamusers_sdk-0.1.0.tar.gz
Size 26.7 kB
Tags Source
SHA-256 checksum
How to use checksums
97443a42ddf6b311a202d1a1d6eec41f6dda0efb8298a4d58d5edd6ec2dc91f0
BLAKE2b-256 checksum
How to use checksums
95e7f4198bbcc5914de944361115f9b1df9d25f6d6b8f33ca14cc2b74c1c2401
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release files / teamusers_sdk-0.1.0-py3-none-any.whl

Download URL teamusers_sdk-0.1.0-py3-none-any.whl
Size 24.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7bb3ad2666faa20190b88f97332eb82ed397399cecc0d55fa7d10ffb37dbd7df
BLAKE2b-256 checksum
How to use checksums
7ed9e90ad04fb2e8c9403edb276ac4cbbb32ead661d768675e6851629fb68993
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 26, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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