Topaz integration for FastAPI
Project description
FastAPI-Topaz
FastAPI middleware for Topaz authorization.
Full documentation following the Diataxis framework available at jmanteau.github.io/fastapi-topaz.
Installation
pip install fastapi-topaz
Quick Start
from fastapi import Depends, FastAPI, Request
from fastapi_topaz import (
AuthorizerOptions,
Identity,
IdentityType,
TopazConfig,
require_policy_allowed,
)
config = TopazConfig(
authorizer_options=AuthorizerOptions(url="localhost:8282"),
policy_path_root="myapp",
identity_provider=lambda req: Identity(
type=IdentityType.IDENTITY_TYPE_SUB,
value=req.state.user_id,
),
policy_instance_name="myapp",
)
app = FastAPI()
@app.get("/documents")
async def list_documents(
request: Request,
_: None = Depends(require_policy_allowed(config, "myapp.GET.documents")),
):
return {"documents": [...]}
Features
| Feature | Description |
|---|---|
| Policy-based authorization | require_policy_allowed() |
| ReBAC (relationship-based) | require_rebac_allowed() |
| Fetch + authorize | get_authorized_resource() |
| Bulk filtering | filter_authorized_resources() |
| Decision caching | Configurable TTL cache |
| Circuit breaker | Graceful degradation |
| Audit logging | Structured JSON logging |
| Observability | Prometheus metrics, OpenTelemetry tracing |
Documentation
| Section | Focus | Description |
|---|---|---|
| Tutorials | Learning-Oriented | Step-by-step guides to get started |
| How-To Guides | Task-Oriented | Solve specific problems |
| Reference | Information-Oriented | API and CLI specifications |
| Explanation | Understanding-Oriented | Architecture and concepts |
Requirements
- Python 3.9+
- FastAPI 0.100+
- Running Topaz instance
Links
License
Apache 2.0
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
fastapi_topaz-1.0.1.tar.gz
(109.6 kB
view details)
Built Distribution
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 fastapi_topaz-1.0.1.tar.gz.
File metadata
- Download URL: fastapi_topaz-1.0.1.tar.gz
- Upload date:
- Size: 109.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1eb1986822d4d84f6e36d085ed84b4aed15683b0e6f88f1941846ba0d4605d75
|
|
| MD5 |
34c94f1dcfaaf5db03b40442ff2edffa
|
|
| BLAKE2b-256 |
7e65d71dfdf4ae1157c3be21c0e97949f6e4d5a5c37be78c8151ac391c3f3aa9
|
File details
Details for the file fastapi_topaz-1.0.1-py3-none-any.whl.
File metadata
- Download URL: fastapi_topaz-1.0.1-py3-none-any.whl
- Upload date:
- Size: 38.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
54cac2a9c90a4f36805fbfcba605cb1e04dbaafa66d1bc4728db22aa5f4679a2
|
|
| MD5 |
57aa32f8b91d64048419ea887be1b1cb
|
|
| BLAKE2b-256 |
e08bd368e5c5423a6dd59a2cdfba7ad645da23fa3488730f316f3c88907648a5
|