Flask API Key Decorator
A simple decorator for requiring an API key in order to access flask endpoints or methods.
It checks for an API key and adds the requirement to the swagger documentation.
Installation
pip install flask-api-key-decorator
Usage
Import the library
from require_api_key import require_api_key
Use it to decorate your Flask routes:
@app.route('/')
@require_api_key
def home():
return "Hello, World!"
By default, the decorator looks for the API key in the 'x-api-key' header. If you want to use a different header, you can specify it using the header_name parameter:
@app.route('/')
@require_api_key(header_name='custom-header')
def home():
return "Hello, World!"
Setting the API key
The API key can be set in two ways:
- As an environment variable named
API_KEY - As an argument to the decorator
@app.route('/')
@require_api_key(key='your-api-key')
def home():
return "Hello, World!"
To set multiple API keys, separate them with a comma.
export API_KEY=your-api-key-1,your-api-key-2
License
MIT (see LICENSE.md
Metadata
Release files for flask-api-key-decorator 0.1.3
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 |
|---|---|---|---|---|
| flask_api_key_decorator-0.1.3.tar.gz | 2.8 kB | Without provenance | Details for flask_api_key_decorator-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| flask_api_key_decorator-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for flask_api_key_decorator-0.1.3-py3-none-any.whl |
Total release size: 6.6 kB
Release files / flask_api_key_decorator-0.1.3.tar.gz
| Download URL | flask_api_key_decorator-0.1.3.tar.gz |
|---|---|
| Size | 2.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a587931806ec5447a1573ac37da4a41a95edbf84c90891b18f098b2618c218fa
|
|
BLAKE2b-256 checksum How to use checksums |
a6b5fc5e90395a4e7a5d1a84bf588c44248ec6af1b61bb2373a819bbc55ecfb1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Release files / flask_api_key_decorator-0.1.3-py3-none-any.whl
| Download URL | flask_api_key_decorator-0.1.3-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4acdf1ba573f1ee63a7f384244adfcdc9db566ec8366b225d6bc33aa857e572
|
|
BLAKE2b-256 checksum How to use checksums |
9e1f5182ba59ac56aba62ce33958e4bcad5f6224f429068d344b52deffd041f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.5
|
Security for flask-api-key-decorator 0.1.3
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.