
Security News
OWASP 2025 Top 10 Adds Software Supply Chain Failures, Ranked Top Community Concern
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.
fastapi-simple-security
Advanced tools
API key based security package for FastAPI, focused on simplicity of use:
sqlite backend, working with both header and query parametersFastAPI and the python standard libraryThis module cannot be used for any kind of distributed deployment. It's goal is to help have some basic security features for simple one-server API deployments, mostly during development.
pip install fastapi_simple_security
from fastapi_simple_security import api_key_router, api_key_security
from fastapi import Depends, FastAPI
app = FastAPI()
app.include_router(api_key_router, prefix="/auth", tags=["_auth"])
@app.get("/secure", dependencies=[Depends(api_key_security)])
async def secure_endpoint():
return {"message": "This is a secure endpoint"}
Resulting app is:

Start your API and check the logs for the automatically generated secret key if you did not provide one through environment variables.

Go to /docs on your API and inform this secret key in the Authorize/Secret header box.
All the administrator endpoints only support header security to make sure the secret key is not inadvertently
shared when sharing an URL.

Then, you can use /auth/new to generate a new API key.

And finally, you can use this API key to access the secure endpoint.

You can of course automate API key acquisition through python with requests and directly querying the endpoints.
If you do so, you can hide the endpoints from your API documentation with the environment variable
FASTAPI_SIMPLE_SECURITY_HIDE_DOCS.
Environment variables:
FASTAPI_SIMPLE_SECURITY_SECRET: Secret administrator key
FASTAPI_SIMPLE_SECURITY_HIDE_DOCS: Whether or not to hide the API key related endpoints from the documentation
FASTAPI_SIMPLE_SECURITY_DB_LOCATION: Location of the local sqlite database file
sqlite.db in the running directory by defaultFAST_API_SIMPLE_SECURITY_AUTOMATIC_EXPIRATION: Duration, in days, until an API key is deemed expired
poetry install
poetry shell
pre-commit install
pytest
The attached docker image runs a test app on localhost:8080 with secret key TEST_SECRET. Run it with:
docker-compose build && docker-compose up
FAQs
API key-based security for FastAPI
We found that fastapi-simple-security demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.

Security News
Socket CTO Ahmad Nassri discusses why supply chain attacks now target developer machines and what AI means for the future of enterprise security.