A Python library for API key validation
Project description
API Key Gateway
A Python library that provides an @apikey_login decorator to validate API keys with service-aware authentication.
Features
- Automatically adds
--apikey/-aCLI parameter to decorated functions - Validates API keys using argon2id hashing algorithm for strong security
- Service-aware validation: Keys are scoped to specific services
- Fetches valid public keys from a remote JSON endpoint
- Easy to use decorator interface with service parameter
Installation
uv install apikey-gateway
Usage
The apikey_login decorator requires a service parameter to scope keys to specific services.
from apikey_gateway import apikey_login
@apikey_login(service="media-match")
def media_app():
print("API key validated for media-match service!")
# Your media application logic here
@apikey_login(service="analytics")
def analytics_app():
print("API key validated for analytics service!")
# Your analytics application logic here
if __name__ == "__main__":
media_app() # or analytics_app()
Run with:
python app.py --apikey your-secret-key
How It Works
- The application specifies the
servicename when using the@apikey_logindecorator - The user provides a secret API key via the
--apikey/-aCLI parameter - The library computes an argon2id hash (public key) from the secret key
- It fetches the list of valid public keys from
https://api.jsonbin.io/v3/b/691ec6a543b1c97be9b8ea6d - Valid keys are filtered to only those belonging to the specified service
- If the computed public key matches any valid service-specific public key, access is granted
JSON Format
The remote JSON follows a service-aware structure where keys are organized by service name:
Service-Aware Structure
{
"service1": {
"key_id_1": "argon2id_hash_here",
"key_id_2": "another_hash_here"
},
"service2": "single_key_hash_here"
}
- Top-level keys are service names
- Each service can have either multiple keys (as a dictionary) or a single key (as a string)
- The library automatically handles both formats when fetching keys
License
MIT
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 apikey_gateway-1.0.2.tar.gz.
File metadata
- Download URL: apikey_gateway-1.0.2.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15038d47c9fc778ba5ecf6b18d92fc4a7fabec75534738926173e8943127f9a7
|
|
| MD5 |
deb5ecb8bb0f432780dcbd55c7b16d8e
|
|
| BLAKE2b-256 |
cba8739defee6875ed1e59f5f56f4f8be9a440c2b0c514f451b133d2d1cd5288
|
File details
Details for the file apikey_gateway-1.0.2-py3-none-any.whl.
File metadata
- Download URL: apikey_gateway-1.0.2-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
295faf51f386a38b3f75c9fb3344f77fdce78cbd39d936158513a4be3699f188
|
|
| MD5 |
5156f46485ae47a4d4a228aeb40a7ab6
|
|
| BLAKE2b-256 |
7d6ae47625e8450777db07cd7a824430d1fac98e8f7c341e4c3a6a02f878b8fa
|