Skip to main content

title: Python SDK description: OathMesh token verification SDK for Python with FastAPI, Flask, and Django integration patterns. keywords: [oathmesh, python, fastapi, flask, django, jwt, machine-identity] audience: application-developers, platform-engineers, enterprise-teams

Docs Index

oathmesh

OathMesh Logo

OathMesh token verification SDK for Python.

Table of Contents

Installation

pip install oathmesh
# or
poetry add oathmesh

Requirements:

  • Python 3.9+
  • PyJWT >= 2.8.0
  • cryptography >= 41.0.0

Quick Start

from oathmesh import verify_token, VerifierConfig

config = VerifierConfig(
    audience="https://inventory.internal",
    trusted_issuers=["https://issuer.oathmesh.tech"],
)

caller = verify_token("OathMesh <token>", config)
print(caller.principal.subject)

Canonical header:

Authorization: OathMesh <token>

Framework Integrations

FastAPI

Use a dependency that calls verify_token(...) and raises HTTPException(401) on OathMeshError.

Flask

Use @app.before_request to verify request.headers.get("Authorization", "").

Django

Use a view decorator that verifies request.META.get("HTTP_AUTHORIZATION", "").

Configuration

from oathmesh import VerifierConfig, verify_raw_token, extract_token

config = VerifierConfig(
    audience="https://inventory.internal",
    trusted_issuers=["https://issuer.oathmesh.tech"],
    on_verified=lambda ctx: logger.info("allowed", extra={"sub": ctx.principal.subject}),
    on_denied=lambda err: logger.warning("denied", extra={"code": err.code, "step": err.step}),
)

token = extract_token(auth_header)
caller = verify_raw_token(token, config)

Verifier semantics:

  • Canonical and required header for verification is Authorization: OathMesh <token>.
  • extract_token returns None for non-OathMesh schemes.
  • If upstream sends Bearer, translate it to OathMesh before calling verifier APIs.
  • Verifier behavior is aligned with canonical Go step semantics for conformance-critical checks (including alg=none rejection, subject format validation, binding-required semantics, and future-iat rejection).
  • Parity is behavioral across language runtimes; implementations are intentionally language-native, not byte-identical.
  • revocation_list remains optional. Cross-SDK conformance currently marks Python revocation behavior as SKIP/N/A.

Error Handling

from oathmesh import OathMeshError

try:
    # verify...
    pass
except OathMeshError as err:
    print(err.code, err.message, err.fix, err.step)

Common codes: claim_missing:token, issuer_untrusted, audience_mismatch, signature_invalid, token_expired.

Troubleshooting

Symptom Likely cause Fix
claim_missing:token Missing/invalid header Send Authorization: OathMesh <token>
issuer_untrusted iss not in trusted_issuers Add exact issuer URL
audience_mismatch Token aud differs from audience Mint token with matching aud
token_expired TTL elapsed / clock skew Mint fresh token and sync clocks
signature_invalid JWKS/issuer mismatch Check issuer URL and JWKS reachability

Security Notes

  • Verify only tokens from trusted issuers you control.
  • Never log raw tokens or API keys.
  • Keep issuer TLS and JWKS endpoints reachable and authenticated.
  • Treat all claims as untrusted until verification succeeds.

Production Tips

  • Reuse verifier config objects across requests.
  • Log error code and step for operational triage.
  • Use short TTLs and rotate issuer keys safely.
  • Monitor deny rates by error code.

Metadata

Release files for oathmesh 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 oathmesh 0.1.1
File Size Uploaded
oathmesh-0.1.1.tar.gz 21.2 kB Details

Built distribution (wheel)

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

Total release size: 45.3 kB

Release files / oathmesh-0.1.1.tar.gz

Download URL oathmesh-0.1.1.tar.gz
Size 21.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f62e322f9e430b9ac4d85b7b5142b5b97a23921a8508b6094ab89d6e78461dc9
BLAKE2b-256 checksum
How to use checksums
5ae51b13d4ba81a1f48006c72922eecc2e274afa86304d83a0be8a00cb306c18
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

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

Download URL oathmesh-0.1.1-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
916cc8ce31776042d6621a74db464bab18ad959e87ebd1d846d59ebdf729af33
BLAKE2b-256 checksum
How to use checksums
11f985e08e857e366ca1deffa4f9e069bf5911bdc9ebd6c998d797b610ad06da
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.1

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