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.0.tar.gz (107.8 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.0-py3-none-any.whl (38.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_topaz-1.0.tar.gz
  • Upload date:
  • Size: 107.8 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.0.tar.gz
Algorithm Hash digest
SHA256 66716d7978eceb2c53d2b661fccccfa1481d720dc4711faddd1ccab84d8437bb
MD5 8445db6cb4b810923ebd8f899f8543cf
BLAKE2b-256 dca86d0f93b8a687211d0be8c228afb06ebf3306b8efba2d3b4c7ccbdef312c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_topaz-1.0-py3-none-any.whl
  • Upload date:
  • Size: 38.3 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 150fe75916768d5c51f44b15eaed9ac748ac8dd4e990028b2ea9dd5f31ad50bd
MD5 61341f0c87d75b56b4c378a0559e2c18
BLAKE2b-256 808f0af2d963c0b2e705e71f197316f0dc561eca008f4f10c19c2b9f49dbb12f

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