Python bindings for the Hessra authorization system with Biscuit token verification and mTLS support
Project description
Hessra Python SDK
Python bindings for the Hessra authentication and authorization system.
Overview
This Python package provides bindings to the Rust-based Hessra SDK, enabling Python applications to:
- Verify Biscuit authorization tokens (locally and remotely)
- Manage service chain token attestation
- Handle mTLS-authenticated communication with Hessra services
- Configure and manage authorization settings
Note: This library is focused on token verification and service chain operations. Token creation is handled by the Hessra authorization service.
Installation
From PyPI
# With uv
uv add hessra-py
# With pip
pip install hessra-py
From Source
cd hessra-py
# Sync development dependencies (includes maturin)
uv sync --dev
# Build and install in development mode
uv run maturin develop
# Or build wheel and install
uv run maturin build --release
uv add target/wheels/hessra_py-*.whl
Requirements
- Python 3.8+ (recommended: Python 3.12)
- uv for Python package management
- Rust toolchain (for building from source)
Quick Start
The Python SDK connects to your Hessra authorization service using the same test certificates as the Rust SDK examples.
import hessra_py
# Load certificates (same as used in Rust SDK examples)
mtls_cert = open("../certs/client.crt").read()
mtls_key = open("../certs/client.key").read()
server_ca = open("../certs/ca-2030.pem").read()
# Create configuration
config = (hessra_py.HessraConfig.builder()
.base_url("test.hessra.net")
.port(443)
.protocol("http1")
.mtls_cert(mtls_cert)
.mtls_key(mtls_key)
.server_ca(server_ca)
.build())
# Create client and setup with public key
client = hessra_py.HessraClient(config)
client_with_key = client.setup_new()
# Verify a token locally (requires real Biscuit token)
client_with_key.verify_token_local(
token="<biscuit_token_base64>",
subject="uri:urn:test:argo-cli0",
resource="resource1",
operation="read"
)
# Create configuration from environment variables
config = hessra_py.HessraConfig.from_env()
# Or build configuration manually
config = (hessra_py.HessraConfig.builder()
.base_url("your-auth-service.com")
.port(443)
.protocol("http1")
.mtls_cert(your_client_cert)
.mtls_key(your_client_key)
.server_ca(your_server_ca)
.public_key(your_public_key)
.build())
# Create client
client = hessra_py.HessraClient(config)
# Setup client (fetches public key if needed)
client = client.setup_new()
# Verify a token locally
client.verify_token_local(
token="your_base64_token",
subject="user_id",
resource="api/endpoint",
operation="read"
)
# Verify token remotely via API
result = client.verify_token_remote(
token="your_base64_token",
subject="user_id",
resource="api/endpoint",
operation="read"
)
print(f"Verification result: {result}")
Service Chain Operations
For complex authorization flows involving multiple services:
# Attest a token with your service
attested_token = client.attest_service_chain_token(
token="original_token",
service="my-service"
)
# Verify a service chain token
service_chain_json = '''[
{
"component": "auth-service",
"public_key": "ed25519/public_key_1"
},
{
"component": "payment-service",
"public_key": "ed25519/public_key_2"
}
]'''
client.verify_service_chain_token_local(
token=attested_token,
subject="user_id",
resource="api/endpoint",
operation="read",
service_chain_json=service_chain_json,
component=None # Verify entire chain
)
Configuration
Environment Variables
The library supports loading configuration from environment variables:
export HESSRA_BASE_URL="your-service.com"
export HESSRA_PORT="443"
export HESSRA_PROTOCOL="http1"
export HESSRA_MTLS_CERT="$(cat client.crt)"
export HESSRA_MTLS_KEY="$(cat client.key)"
export HESSRA_SERVER_CA="$(cat ca.crt)"
export HESSRA_PUBLIC_KEY="$(cat public.key)"
export HESSRA_PERSONAL_KEYPAIR="$(cat personal.key)"
Then load with:
config = hessra_py.HessraConfig.from_env()
Builder Pattern
All configuration and client objects support a fluent builder pattern:
config = (hessra_py.HessraConfig.builder()
.base_url("service.com")
.port(443)
.protocol("http1") # or "http3"
.mtls_cert(cert_string)
.mtls_key(key_string)
.server_ca(ca_string)
.public_key(public_key_string)
.personal_keypair(keypair_string)
.build())
client = (hessra_py.HessraClient.builder()
.base_url("service.com")
.port(443)
# ... other configuration
.build())
Error Handling
All operations can raise HessraPyError:
try:
client.verify_token_local(token, subject, resource, operation)
print("Token is valid")
except hessra_py.HessraPyError as e:
print(f"Verification failed: {e}")
API Reference
HessraConfig
Configuration object for Hessra services.
Methods:
from_env()- Load from environment variablesbuilder()- Create configuration builder- Properties:
base_url,port,protocol,public_key
HessraClient
Main client for interacting with Hessra services.
Methods:
__init__(config)- Create client with configurationsetup_new()- Setup client and return new instance with public keyverify_token_local(token, subject, resource, operation)- Verify token locallyverify_token_remote(token, subject, resource, operation)- Verify token via APIget_public_key()- Fetch public key from serviceattest_service_chain_token(token, service)- Add service attestation to tokenverify_service_chain_token_local(...)- Verify service chain token locallyverify_service_chain_token_remote(...)- Verify service chain token via API
Examples
See the examples/ directory for complete usage examples:
basic_usage.py- Basic token verification and configurationtest_verification.py- Test suite demonstrating all features
Development
Building and testing the Python bindings:
# Clone and navigate to the project
cd hessra-py
# Initialize uv project and sync dependencies
uv sync --dev
# Build in development mode
uv run maturin develop
# Run example tests
uv run python examples/basic_usage.py
uv run python examples/test_verification.py
# Run tests with pytest (when available)
uv run pytest
# Build release wheel
uv run maturin build --release
# Check the built wheel
ls -la target/wheels/
Development Workflow
The Python bindings use uv for fast dependency management and maturin for building the Rust extension:
- Initial setup:
uv sync --devinstalls all development dependencies - Development builds:
uv run maturin developbuilds and installs for testing - Running examples:
uv run python examples/...executes Python scripts - Release builds:
uv run maturin build --releasecreates optimized wheels
Publishing and Releases
This package is published to PyPI independently from the main Hessra SDK. See RELEASE.md for the complete release process.
For Maintainers
To release a new version:
- Update version in
Cargo.toml - Commit changes and create a tag:
git tag hessra-py-v0.1.1 - Push the tag:
git push origin hessra-py-v0.1.1 - GitHub Actions will automatically build and publish to PyPI
License
Apache License 2.0 - See LICENSE file for details.
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 Distributions
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 hessra_py-0.2.1.tar.gz.
File metadata
- Download URL: hessra_py-0.2.1.tar.gz
- Upload date:
- Size: 150.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9acddbd4bd0da162de78c6d520ffb12c655ddf46bff927eae90ca0dcf475899a
|
|
| MD5 |
57d5846eb7ae0e997786d57872e0c845
|
|
| BLAKE2b-256 |
2d9e7baf769f9765b445929a1a7230b79681d898b961843120693bae30f74099
|
Provenance
The following attestation bundles were made for hessra_py-0.2.1.tar.gz:
Publisher:
publish-python.yml on Hessra-Labs/hessra-sdk.rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hessra_py-0.2.1.tar.gz -
Subject digest:
9acddbd4bd0da162de78c6d520ffb12c655ddf46bff927eae90ca0dcf475899a - Sigstore transparency entry: 444954203
- Sigstore integration time:
-
Permalink:
Hessra-Labs/hessra-sdk.rs@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Hessra-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hessra_py-0.2.1-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: hessra_py-0.2.1-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 2.9 MB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a0574bca20bc88763ea72513f7aab580a6103603cfcf461bdf02e6db22f4e07
|
|
| MD5 |
4695004015795f46962c96681780ff4b
|
|
| BLAKE2b-256 |
93cf822c74256f50250ef3998a24b3d805b83375dc10db8f5fc1edeb2d19efc1
|
Provenance
The following attestation bundles were made for hessra_py-0.2.1-cp38-abi3-win_amd64.whl:
Publisher:
publish-python.yml on Hessra-Labs/hessra-sdk.rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hessra_py-0.2.1-cp38-abi3-win_amd64.whl -
Subject digest:
0a0574bca20bc88763ea72513f7aab580a6103603cfcf461bdf02e6db22f4e07 - Sigstore transparency entry: 444954229
- Sigstore integration time:
-
Permalink:
Hessra-Labs/hessra-sdk.rs@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Hessra-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hessra_py-0.2.1-cp38-abi3-win32.whl.
File metadata
- Download URL: hessra_py-0.2.1-cp38-abi3-win32.whl
- Upload date:
- Size: 2.5 MB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4090838b2b914364c47d3785330d9e9e375075d322c995385c097adf16369e94
|
|
| MD5 |
3a75555827d753bb64d17b854c68ec1f
|
|
| BLAKE2b-256 |
b180af4d6d07d7316e4bdaeec76c07a16bd91309c7dc10efe1530d97b284b50a
|
Provenance
The following attestation bundles were made for hessra_py-0.2.1-cp38-abi3-win32.whl:
Publisher:
publish-python.yml on Hessra-Labs/hessra-sdk.rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hessra_py-0.2.1-cp38-abi3-win32.whl -
Subject digest:
4090838b2b914364c47d3785330d9e9e375075d322c995385c097adf16369e94 - Sigstore transparency entry: 444954244
- Sigstore integration time:
-
Permalink:
Hessra-Labs/hessra-sdk.rs@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Hessra-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hessra_py-0.2.1-cp38-abi3-manylinux_2_28_aarch64.whl.
File metadata
- Download URL: hessra_py-0.2.1-cp38-abi3-manylinux_2_28_aarch64.whl
- Upload date:
- Size: 3.5 MB
- Tags: CPython 3.8+, manylinux: glibc 2.28+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
745078529a406b85b9b6c8d7c10ba7cce39827af41d538736406846b31392d8f
|
|
| MD5 |
dbf4ec368248a514a2f2f4c9e098b7f8
|
|
| BLAKE2b-256 |
62399b7c6779dd307cecc55dd9c3e5dab716106cbe62f0e084689737a3727701
|
Provenance
The following attestation bundles were made for hessra_py-0.2.1-cp38-abi3-manylinux_2_28_aarch64.whl:
Publisher:
publish-python.yml on Hessra-Labs/hessra-sdk.rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hessra_py-0.2.1-cp38-abi3-manylinux_2_28_aarch64.whl -
Subject digest:
745078529a406b85b9b6c8d7c10ba7cce39827af41d538736406846b31392d8f - Sigstore transparency entry: 444954295
- Sigstore integration time:
-
Permalink:
Hessra-Labs/hessra-sdk.rs@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Hessra-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hessra_py-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: hessra_py-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 3.7 MB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf7af5c808a4a1aab028015744e19fc6867601f974e0e42411ef99a2ce7cd10e
|
|
| MD5 |
d9882cbe5ebf7f5f7f5bfa534c14f9b1
|
|
| BLAKE2b-256 |
5b0794d2954a14a4203dbf35208b0db9b664a17930ece3dc8cfa3ee0eedbafac
|
Provenance
The following attestation bundles were made for hessra_py-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
publish-python.yml on Hessra-Labs/hessra-sdk.rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hessra_py-0.2.1-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl -
Subject digest:
cf7af5c808a4a1aab028015744e19fc6867601f974e0e42411ef99a2ce7cd10e - Sigstore transparency entry: 444954265
- Sigstore integration time:
-
Permalink:
Hessra-Labs/hessra-sdk.rs@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Hessra-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hessra_py-0.2.1-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: hessra_py-0.2.1-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 3.1 MB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b7579e71fa18cf6148afe5cf087c707016a181f43fe0430c69c37ba2a12fbee
|
|
| MD5 |
ac1e37504c0f2c4476f904d4e4a5ce68
|
|
| BLAKE2b-256 |
293fbf57e35f114e170d75b78941759acfa2b4ca56f264d9a8bae24a783497f8
|
Provenance
The following attestation bundles were made for hessra_py-0.2.1-cp38-abi3-macosx_11_0_arm64.whl:
Publisher:
publish-python.yml on Hessra-Labs/hessra-sdk.rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hessra_py-0.2.1-cp38-abi3-macosx_11_0_arm64.whl -
Subject digest:
2b7579e71fa18cf6148afe5cf087c707016a181f43fe0430c69c37ba2a12fbee - Sigstore transparency entry: 444954310
- Sigstore integration time:
-
Permalink:
Hessra-Labs/hessra-sdk.rs@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Hessra-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file hessra_py-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: hessra_py-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 3.3 MB
- Tags: CPython 3.8+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8b06bf09594fd7916f70059d2303dedc456d20b22f8ccddd47f46ac32bbe07c
|
|
| MD5 |
3260d4cc5acf85ac3c7ed9b036a09495
|
|
| BLAKE2b-256 |
05b16b5c3aba2ba78464ec9fe7aca12865e0617d3c855cca2b38782de42984bb
|
Provenance
The following attestation bundles were made for hessra_py-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl:
Publisher:
publish-python.yml on Hessra-Labs/hessra-sdk.rs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hessra_py-0.2.1-cp38-abi3-macosx_10_12_x86_64.whl -
Subject digest:
a8b06bf09594fd7916f70059d2303dedc456d20b22f8ccddd47f46ac32bbe07c - Sigstore transparency entry: 444954334
- Sigstore integration time:
-
Permalink:
Hessra-Labs/hessra-sdk.rs@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Hessra-Labs
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-python.yml@e4c4a7a25d7b53f6a60a39490f72e42d9c4a60a2 -
Trigger Event:
workflow_dispatch
-
Statement type: