Simple FastAPI declarative endpoint-level access control, somewhat inspired by Pyramid.
Installation
Requirements: Python 3.10+ · FastAPI 0.104.1+ · PyJWT 2.12.1+
pip install missil
Why use Missil?
Permission checks tend to look the same across every protected endpoint: extract the token, verify it, find the area, check the level. Missil moves all of that out of your route functions and into a single declarative line per endpoint — keeping your business logic clean and your access rules explicit and auditable at a glance.
Because permissions are stored as numeric levels per business area, a single token can express fine-grained access across multiple areas of your application without requiring separate tokens or custom middleware.
Quick example
import missil
from fastapi import FastAPI, Response
app = FastAPI()
SECRET_KEY = "..."
# 1. Declare a bearer — reads token from cookie or Authorization header
bearer = missil.TokenBearer("Authorization", SECRET_KEY, permissions_key="permissions")
# 2. Declare business areas as typed attributes
class AppAreas(missil.AreasBase):
finances: missil.Area
it: missil.Area
areas = AppAreas(bearer)
# 3. Protect endpoints — one dependency, no boilerplate
@app.get("/finances/report", dependencies=[areas.finances.READ])
def finances_report(): ...
@app.get("/finances/edit", dependencies=[areas.finances.WRITE])
def finances_edit(): ...
@app.get("/it/admin", dependencies=[areas.it.ADMIN])
def it_admin(): ...
# 4. Issue a token at login
@app.post("/login")
def login(response: Response):
claims = {
"sub": "user123",
"permissions": {"finances": missil.WRITE, "it": missil.READ},
}
token = missil.encode_jwt_token(claims, SECRET_KEY, expiration_hours=8)
response.set_cookie("Authorization", f"Bearer {token}", httponly=True)
return {"msg": "logged in"}
Permission hierarchy
| Level | Constant | Satisfies |
|---|---|---|
| 0 | READ |
READ |
| 1 | WRITE |
READ, WRITE |
| 2 | ADMIN |
READ, WRITE, ADMIN |
Higher levels automatically satisfy lower requirements — a user with ADMIN access can reach READ and WRITE protected endpoints without extra entries.
Bearers
Choose the bearer that matches how your client sends the token:
| Bearer | Token source |
|---|---|
TokenBearer |
Cookie → falls back to Authorization header |
CookieTokenBearer |
Cookie only |
HeaderTokenBearer |
Authorization header only |
License
This project is licensed under the terms of the MIT license.
Metadata
Release files for missil 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| missil-0.2.1.tar.gz | 15.7 kB | Without provenance | Details for missil-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| missil-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for missil-0.2.1-py3-none-any.whl |
Total release size: 30.1 kB
Release files / missil-0.2.1.tar.gz
| Download URL | missil-0.2.1.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7ca40fd170e09badcc574eae775da632a14347c13ef8dac7b553f05aad8146ed
|
|
BLAKE2b-256 checksum How to use checksums |
e2969ba8f787adc949fb6b7cbcd02f84aaaeecd77c5086a0f12d4cd84a9e273d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.26.7 CPython/3.12.2 Linux/6.6.87.2-microsoft-standard-WSL2
|
Release files / missil-0.2.1-py3-none-any.whl
| Download URL | missil-0.2.1-py3-none-any.whl |
|---|---|
| Size | 14.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c92b043523effc57d52a5de18220b0764b809fc7bc252857bbf51c88b3e3387
|
|
BLAKE2b-256 checksum How to use checksums |
1f2b933001eb72a2d49c18b0903f71886367d831e8ffe0e4f50790dbcca8e070
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
pdm/2.26.7 CPython/3.12.2 Linux/6.6.87.2-microsoft-standard-WSL2
|
Security for missil 0.2.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.