FastAPI-key-auth
Secure your FastAPI endpoints using API keys.
Report Bug
·
Request Feature
Table of Contents
About The Project
On deployment inject API keys authorized to use your service. Every call to a private
endpoint of your service has to include a header['x-api-key'] attribute that is
validated against the API keys in your environment.
If it is present, a request is authorized. If it is not FastAPI return 401 Unauthorized.
Use this either as a middleware, or as Dependency.
Built With
Getting Started
Installation
- Clone and install
git clone https://github.com/iwpnd/fastapi-key-auth.git uv sync
- Install with pip
pip install fastapi-key-auth
- Install with uv
uv add fastapi-key-auth
Usage
As Middleware:
from fastapi import FastAPI
from fastapi_key_auth import AuthorizerMiddleware
app = FastAPI()
app.add_middleware(AuthorizerMiddleware, public_paths=["/ping"], key_pattern="API_KEY_")
# optional use regex startswith
app.add_middleware(AuthorizerMiddleware, public_paths=["/ping", "^/users"])
As Dependency
from fastapi import FastAPI, Depends
from fastapi_key_auth import AuthorizerDependency
authorizer = AuthorizerDependency(key_pattern="API_KEY_")
# either globally or in a router
app = FastAPI(dependencies=[Depends(authorizer)])
License
Distributed under the MIT License. See LICENSE for more information.
Contact
Benjamin Ramser - @imwithpanda - ahoi@iwpnd.pw Project Link: https://github.com/iwpnd/fastapi-key-auth
Metadata
Release files for fastapi-key-auth 0.15.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi_key_auth-0.15.5.tar.gz | 86.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_key_auth-0.15.5-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 92.0 kB
Release files / fastapi_key_auth-0.15.5.tar.gz
| Download URL | fastapi_key_auth-0.15.5.tar.gz |
|---|---|
| Size | 86.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f84d0e65b8399747241d506a36e06a64cc90a9f483556f48e4a80cbe2ec9e973
|
|
BLAKE2b-256 checksum How to use checksums |
bb8ba300842501693d64647676ee6f6599f7869292cce94ea985a995be867bbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 May 17, 2025.
Transparency logRelease files / fastapi_key_auth-0.15.5-py3-none-any.whl
| Download URL | fastapi_key_auth-0.15.5-py3-none-any.whl |
|---|---|
| Size | 5.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a761917de22f8befe8a311163f3e8370325bb4e9d082e1bda4a7e485d19dd200
|
|
BLAKE2b-256 checksum How to use checksums |
42122bb6e2151a2d052c70f8d376682f6a60ba9e1535f7cb329389d5ab25eb93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
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 May 17, 2025.
Transparency log