Skip to main content

Topaz integration for FastAPI

Project description

FastAPI-Topaz

FastAPI middleware for Topaz authorization.

PyPI Python Version License Downloads

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": [...]}

Documentation

Full documentation following the Diataxis framework available at jmanteau.github.io/fastapi-topaz.

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

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

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-0.1.tar.gz (102.0 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-0.1-py3-none-any.whl (36.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for fastapi_topaz-0.1.tar.gz
Algorithm Hash digest
SHA256 ec8ba417c633d73b767a358f903805ea44a2f2d93538fdf49c6b7a7e6f759a35
MD5 4ebbda3f56ea488d71e86910c1f20ce0
BLAKE2b-256 7a6857bac2513f5ccb7fce0fe54e93c84cece1f9d8e27a2551462fc30c30f7a3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastapi_topaz-0.1-py3-none-any.whl
  • Upload date:
  • Size: 36.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-0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 32723b5b398cb33c2056b1c67b9f3a2d5c07e48ce31a581f7ea39228f70dbe83
MD5 31571a81979770a786ab5d40462fc196
BLAKE2b-256 396c9b2d6280a2c2901d200c31d2744eccfb3e95621536dcfac87051b6494a43

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