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
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 | |
|---|---|---|---|
| flask_api_key_decorator-0.1.3.tar.gz | 2.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_api_key_decorator-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
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
|