Simple Flask decorator for requiring an API key
Project description
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
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_api_key_decorator-0.1.3.tar.gz.
File metadata
- Download URL: flask_api_key_decorator-0.1.3.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a587931806ec5447a1573ac37da4a41a95edbf84c90891b18f098b2618c218fa
|
|
| MD5 |
392632c86bfbe72051ef82db7426af85
|
|
| BLAKE2b-256 |
a6b5fc5e90395a4e7a5d1a84bf588c44248ec6af1b61bb2373a819bbc55ecfb1
|
File details
Details for the file flask_api_key_decorator-0.1.3-py3-none-any.whl.
File metadata
- Download URL: flask_api_key_decorator-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c4acdf1ba573f1ee63a7f384244adfcdc9db566ec8366b225d6bc33aa857e572
|
|
| MD5 |
a24e47c7cde5cbef245f95aa3dadae48
|
|
| BLAKE2b-256 |
9e1f5182ba59ac56aba62ce33958e4bcad5f6224f429068d344b52deffd041f5
|