Skip to main content

actiongate-fastapi

Gate FastAPI routes through ActionGate primitives.

pip install actiongate-fastapi

Route decorator

from fastapi import FastAPI
from actiongate import Engine, Gate, Policy
from actiongate_fastapi import gated_route

app = FastAPI()
ag = Engine()

@app.post("/search")
@gated_route(
    actiongate=ag,
    gate=Gate("api", "search", "global"),
    policy=Policy(max_calls=100, window=60),
)
async def search(query: str):
    return {"results": do_search(query)}

Returns 429 for rate limit and budget blocks. Returns 403 for policy violations.

Dependency injection

from fastapi import Depends
from actiongate_fastapi import gate_dependency

require_gate = gate_dependency(actiongate=ag)

@app.post("/search")
async def search(
    query: str,
    _=Depends(require_gate(
        gate=Gate("api", "search"),
        policy=Policy(max_calls=100, window=60),
    )),
):
    return {"results": do_search(query)}

Add more gates

pip install actiongate-fastapi[all]
from actiongate import Engine as AG, Gate, Policy
from budgetgate import Engine as BG, Ledger, Budget
from rulegate import Engine as RG, Rule, Ruleset, Context
from actiongate_fastapi import gated_route
from decimal import Decimal

ag, bg, rg = AG(), BG(), RG()

def no_pii(ctx: Context) -> bool:
    return "ssn" not in str(ctx.kwargs).lower()

@app.post("/search")
@gated_route(
    actiongate=ag,
    gate=Gate("api", "search", "global"),
    policy=Policy(max_calls=100, window=60),
    budgetgate=bg,
    ledger=Ledger("api", "search", "global"),
    budget=Budget(max_spend=Decimal("50.00"), window=3600),
    cost=Decimal("0.01"),
    rulegate=rg,
    rule=Rule("api", "search"),
    ruleset=Ruleset(predicates=(no_pii,)),
)
async def search(query: str):
    return {"results": do_search(query)}

Gates evaluate in order: ActionGate → BudgetGate → RuleGate → execute → AuditGate.

License

Apache-2.0. ActionGate and BudgetGate are Apache-2.0. RuleGate and AuditGate are BSL-1.1.

Release files for actiongate-fastapi 0.1.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 actiongate-fastapi 0.1.0
File Size Uploaded
actiongate_fastapi-0.1.0.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for actiongate-fastapi 0.1.0
File Interpreter ABI Platform
actiongate_fastapi-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 17.2 kB

Release files / actiongate_fastapi-0.1.0.tar.gz

Download URL actiongate_fastapi-0.1.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
2547f40148c2d865af5dd8c151fe2c3b77c763e7337db4c415c88dda6a8f0b10
BLAKE2b-256 checksum
How to use checksums
a91fb4af7a37d1d5920e5eb3752a104f04b1fa49eee1085be71d97b2e5e966ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / actiongate_fastapi-0.1.0-py3-none-any.whl

Download URL actiongate_fastapi-0.1.0-py3-none-any.whl
Size 8.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
597a131413ab22aceec1904f0768ce6dca96d59c1403238323b4e05fc7aaf9f6
BLAKE2b-256 checksum
How to use checksums
8320bfcbec31846356a4bf1e2d063c4f4b162787d45cb1f60b35e1600065444b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

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