Gate FastAPI routes through ActionGate primitives.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file actiongate_fastapi-0.1.0.tar.gz.
File metadata
- Download URL: actiongate_fastapi-0.1.0.tar.gz
- Upload date:
- Size: 8.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2547f40148c2d865af5dd8c151fe2c3b77c763e7337db4c415c88dda6a8f0b10
|
|
| MD5 |
a317a5f66eb29820d8308778f479227f
|
|
| BLAKE2b-256 |
a91fb4af7a37d1d5920e5eb3752a104f04b1fa49eee1085be71d97b2e5e966ef
|
File details
Details for the file actiongate_fastapi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: actiongate_fastapi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 8.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
597a131413ab22aceec1904f0768ce6dca96d59c1403238323b4e05fc7aaf9f6
|
|
| MD5 |
abc247a45fbf2e9fed1f756759b1ec57
|
|
| BLAKE2b-256 |
8320bfcbec31846356a4bf1e2d063c4f4b162787d45cb1f60b35e1600065444b
|