Skip to main content

konklav-fastapi

Konklav route policies for FastAPI.

Declare an operation's requirements as a RoutePolicy on routes, routers and include_router; install KonklavRoutes once with your started RelyingClient from konklav-relying, and every request is decided by the relying core with one call.

from fastapi import APIRouter
from konklav_fastapi import KonklavRoutes, RoutePolicy, TenantToken

router = APIRouter(dependencies=[RoutePolicy(tenant_actions={"project:read"})])


@router.get("/projects/{project}", dependencies=[RoutePolicy(scope_actions={"project": {"document:read"}})])
async def read_project(project: str, token: TenantToken) -> dict[str, str]:
    return {"project": project, "subject": token.sub}

A handler that decides more than its route policy states injects RequestDecider. Its decisions reuse the route's verified presentation and are made with the route decision's route authority, so a route requiring user:manage_data, which the catalog says vouches for user:write, lets the handler's user:write decision allow, while a route requiring user:write still forbids a subject who doesn't hold it:

from konklav_fastapi import RequestDecider


@router.post("/users/{user}/data", dependencies=[RoutePolicy(tenant_actions={"user:manage_data"})])
async def manage_data(user: str, decider: RequestDecider) -> dict[str, bool]:
    decision = await decider.decide_typed({"tenant": ["user:write"]})
    return {"write": decision.allowed}

Startup validation refuses routes without a policy, policies that can't be decided, and token dependencies the policy doesn't match. Each operation's merged policy is published in OpenAPI as x-konklav-policy.

RoutePacing(pacing) paces routes whose response time could reveal whether a record exists, such as invites and password resets: declared before the RoutePolicy, it answers no sooner than floor ± jitter, also for denials and errors. PacingMiddleware paces every answer for chosen paths, including those FastAPI gives before any dependency runs:

from datetime import timedelta

from konklav_relying import Pacing
from konklav_fastapi import PacingMiddleware, RoutePacing

pacing = Pacing(floor=timedelta(milliseconds=800), jitter=timedelta(milliseconds=200))
router = APIRouter(dependencies=[RoutePacing(pacing), RoutePolicy(tenant_actions={"member:invite"})])
app.add_middleware(PacingMiddleware, pacing=pacing, paths={"/password-resets"})

RouteRateLimit(limit, "{token:sub}/{path:project}") limits routes with a konklav_relying.RateLimit, keyed by path parameters, token claims or {client:address} (honouring trusted_proxies). Refused requests, and RateLimited raised in handlers, are answered with 429 and Retry-After.

Versions

The package has the same version as the Konklav server it was released with, and requires konklav-relying of that version. It is supported only against a server of the same version.

Metadata

Release files for konklav-fastapi 1.13.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for konklav-fastapi 1.13.0
File Size Uploaded Provenance Actions
konklav_fastapi-1.13.0.tar.gz 20.6 kB With provenance Details for konklav_fastapi-1.13.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for konklav-fastapi 1.13.0
File Interpreter ABI Platform Actions
konklav_fastapi-1.13.0-py3-none-any.whl Python 3 none any Details for konklav_fastapi-1.13.0-py3-none-any.whl

Total release size: 45.9 kB

Release files / konklav_fastapi-1.13.0.tar.gz

Download URL konklav_fastapi-1.13.0.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4f80dd4080b26b3cd86e6b6313a67c674755f3d6aaa6e620544dca6b7744352c
BLAKE2b-256 checksum
How to use checksums
788cd0d17bff6803fc6d53cb933f24edd6df4ee7c6a7b6daa0bdba8ec60ed7af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Release files / konklav_fastapi-1.13.0-py3-none-any.whl

Download URL konklav_fastapi-1.13.0-py3-none-any.whl
Size 25.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
514c1c4edc7465b4be0017075be6851300728bac6d68f82ca3e410224ba29978
BLAKE2b-256 checksum
How to use checksums
d7646d9041054e2d652de4e6e6e9cc701c68e72b2819d4f1a5d7a70ee7823004
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

Security for konklav-fastapi 1.13.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for konklav_fastapi-1.13.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page