Skip to main content

Topaz integration for FastAPI

Project description

FastAPI-Topaz

FastAPI middleware for Topaz authorization.

PyPI Python Version License Downloads

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.1.0.tar.gz (118.4 kB view details)

Uploaded Source

Built Distribution

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

fastapi_topaz-1.1.0-py3-none-any.whl (43.1 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_topaz-1.1.0.tar.gz.

File metadata

  • Download URL: fastapi_topaz-1.1.0.tar.gz
  • Upload date:
  • Size: 118.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for fastapi_topaz-1.1.0.tar.gz
Algorithm Hash digest
SHA256 0dd2840f558bc655c31ee7cde8ddc7f219baf813ccf370e2747b5d0908777060
MD5 ab8aae85d2f0c178b7e21c3c146b710a
BLAKE2b-256 341a1e25bb41593da5fbf7d1f49df0b2f779e79fc68476c2f9d67825a4be3ec1

See more details on using hashes here.

File details

Details for the file fastapi_topaz-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: fastapi_topaz-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for fastapi_topaz-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 80b5e09c87e14358af8ad83dd870b3abb37a19ede8287728f231467204f4867f
MD5 3d4b33ced71b6c2b77de9591f28e4a0f
BLAKE2b-256 f62a908c12b2fd6f1cb37c805a63eaeba8ffee6a0d6ee746a3873a96b91cf3bc

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