Skip to main content

FastAPI-key-auth

Secure your FastAPI endpoints using API keys.
Report Bug · Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. License
  5. Contact

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

  1. Clone and install
    git clone https://github.com/iwpnd/fastapi-key-auth.git
    uv sync
    
  2. Install with pip
    pip install fastapi-key-auth
    
  3. 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)

Source distribution for fastapi-key-auth 0.15.5
File Size Uploaded
fastapi_key_auth-0.15.5.tar.gz 86.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fastapi-key-auth 0.15.5
File Interpreter ABI Platform
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 log

Release 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

Release history Release notifications | RSS feed

This release

0.15.5 This release

2 release files

0.15.4

2 release files

0.14.0

2 release files

0.12.0

2 release files

0.11.0

2 release files

0.10.2

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.6

2 release files

0.7.5

2 release files

0.7.4

2 release files

0.7.3

2 release files

0.7.2

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

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