fastapi-cognito
AWS Cognito JWT authentication library for FastAPI
Decision gist · record as of 2026-08-14
Yes, if you are building a FastAPI application backed by AWS Cognito and need straightforward JWT validation. The library is permissively licensed, has low install friction, and supports modern Python versions. However, maintenance is aging (last commit 495 days ago), so evaluate whether the package's feature set meets your needs and whether you are comfortable with slower response to issues. No known security vulnerabilities as of the query date.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires AWS Cognito service credentials (region, userpool ID, app client ID) and Python >=3.8.
- Low install friction with a pure-Python wheel.
- Maintenance status is aging—last commit was 495 days ago—but the repository remains active and the package supports current Python versions through 3.13.
License · maintenance · safety
MIT (permissive) — MIT license is permissive; you may use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.
last release 2025-04-06 (495 days) · last repo commit 2025-04-06 · 71 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 85,409 downloads/mo, #13,924 on PyPI
Alternatives
Verify before relying
pip install fastapi-cognito
from fastapi import FastAPI, Depends
from fastapi_cognito import CognitoAuth, CognitoSettings, CognitoToken
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
userpools: dict = {"default": {"region": "us-east-1", "userpool_id": "...", "app_client_id": "..."}}
settings = Settings()
cognito = CognitoAuth(settings=CognitoSettings.from_global_settings(settings))
app = FastAPI()
@app.get("/")
def protected(auth: CognitoToken = Depends(cognito.auth_required)):
return {"message": "authenticated"}
- Whether the package handles token refresh or only validates existing tokens.
- Performance characteristics when validating tokens from multiple userpools concurrently.
- Whether custom JWKS URLs work reliably with self-hosted or local Cognito implementations.
What it is and what it does
fastapi-cognito is a FastAPI middleware library that integrates AWS Cognito JWT authentication into your application. It handles the mechanics of fetching Cognito's public keys, validating token signatures, checking expiration, and parsing token claims—letting you protect endpoints with a simple dependency injection pattern. The library supports multiple Cognito userpools, optional authentication, custom token models for extended claims, and both HTTP and WebSocket connections.
You configure it by providing your Cognito region, userpool ID, and app client ID (either in code, YAML, or JSON), then use it as a FastAPI dependency on any route. It does not handle user sign-up or sign-in; it assumes tokens are issued by Cognito and focuses entirely on validation and parsing. The package relies on fastapi, pydantic, pyyaml, aiofile, async-lru, joserfc, and httpx to manage async I/O, settings, and cryptographic verification.
Use it for
- Protect FastAPI endpoints with Cognito JWT tokens, extracting user identity and claims for authorization logic.
- Support optional authentication on public endpoints that may also serve authenticated users with different responses.
- Validate tokens from multiple Cognito userpools in a single application, routing by userpool name.
- Extend token validation with custom token models to parse application-specific claims beyond standard Cognito fields.
- Secure WebSocket connections by validating Cognito tokens during the handshake.
- Use custom JWKS URLs for local development with cognito-local or other Cognito-compatible identity providers.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you are building a FastAPI application backed by AWS Cognito and need straightforward JWT validation.
The library is permissively licensed, has low install friction, and supports modern Python versions. However, maintenance is aging (last commit 495 days ago), so evaluate whether the package's feature set meets your needs and whether you are comfortable with slower response to issues. No known security vulnerabilities as of the query date.
Install
fastapi-cognito on PyPI
Before you install
Low install friction with a pure-Python wheel. Maintenance status is aging—last commit was 495 days ago—but the repository remains active and the package supports current Python versions through 3.13.
Requires AWS Cognito service credentials (region, userpool ID, app client ID) and Python >=3.8.
License in practice
MIT license is permissive; you may use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.
Quickstart
pip install fastapi-cognito
from fastapi import FastAPI, Depends
from fastapi_cognito import CognitoAuth, CognitoSettings, CognitoToken
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
userpools: dict = {"default": {"region": "us-east-1", "userpool_id": "...", "app_client_id": "..."}}
settings = Settings()
cognito = CognitoAuth(settings=CognitoSettings.from_global_settings(settings))
app = FastAPI()
@app.get("/")
def protected(auth: CognitoToken = Depends(cognito.auth_required)):
return {"message": "authenticated"}
Verify before relying
- Whether the package handles token refresh or only validates existing tokens.
- Performance characteristics when validating tokens from multiple userpools concurrently.
- Whether custom JWKS URLs work reliably with self-hosted or local Cognito implementations.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release <4.0,>=3.8 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 8 packagesfastapipydanticpydantic-settingspyyamlaiofileasync-lrujoserfchttpx |
| Maintenance | Aging 495 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 85,409 / month, #13,924 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Framework :: FastAPIIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9 |
Evidence: fastapi_cognito-2.9.0-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “fastapi cognito jwt authentication”
- fastapi-cognitoDecodes, validates, and parses AWS Cognito JWT tokens in FastAPI…
- fastapi-cloudauthIntegrates FastAPI applications with cloud authentication services…
- axioms-fastapiAdds OAuth2/OIDC JWT token validation and claim-based authorization…
Give your agent the search over MCP, or paste the wish link into any chat.
More Security packages
Provides Python bindings to the FreeDesktop.org Secret Service API for securely storing and retrieving passwords and secrets through GNOME Keyring, KWallet, or KeePassXC.
MSAL for Python handles OAuth2 and OpenID Connect authentication with Microsoft identity services, managing token acquisition, caching, and refresh for applications integrating with Microsoft Entra ID, Microsoft Accounts, and Azure AD B2C.
joserfc implements JOSE standards (JWS, JWE, JWK, JWT, and related RFCs) for signing, encrypting, and managing JSON-based cryptographic tokens in Python.
Authlib provides a complete implementation of OAuth 1.0, OAuth 2.0, and OpenID Connect 1.0 for building both authentication clients and servers, with built-in support for JWS, JWK, JWA, and JWT standards.
Provides low-level CFFI bindings to the official Argon2 password hashing algorithm for use by libraries and applications that need direct access to Argon2 without higher-level abstractions.
ADAL for Python authenticates applications with Azure Active Directory to obtain tokens for accessing Azure AD-protected resources.
Install only if maintaining existing code that already depends on it, and plan a migration.
See also cognitojwt · Flask-Cognito · fastapi-cloudauth · axioms-fastapi · pycognito · warrant · fastapi-login · Flask-AWSCognito · spiffe · propelauth-fastapi