Skip to main content

drf_api_key_auth

drf_api_key_auth is a Django REST Framework library designed for creating, managing, and securing API keys. It provides easy-to-use models, permissions, and throttling classes to manage API access effectively.

Installation

Install drf_api_key_auth using pip:

pip install drf_api_key_auth

Configuration After installation, you need to add drf_apikey to your INSTALLED_APPS in the Django settings.

INSTALLED_APPS = (
    ...
    'drf_apikey',
    ...
)

Next, set up the Django REST framework permissions in your Django settings:

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'drf_apikey.permissions.APIKeyPermission',
    ),
    'DEFAULT_THROTTLE_CLASSES': (
        'drf_apikey.throttling.APIKeyThrottle',
    ),
    'DEFAULT_THROTTLE_RATES': {
        'scope_long': '1000'    # Relates to monthly limits, should just be integer
    }
}

Example Request

Here's a basic example of making a request to a Django REST Framework view that is protected with drf_apikey permissions:

import requests

response = requests.get(
    url="http://0.0.0.0:8000/api/your_endpoint",
    headers={
        "X_API_KEY": "fd8b4a98c8f53035aeab410258430e2d86079c93",
    },
)

print(response.json())

in this example above, replace "http://0.0.0.0:8000/api/your_endpoint" with the actual endpoint you wish to access, and "fd8b4a98c8f53035aeab410258430e2d86079c93" with a valid API key.

Contributing

Contributions are welcome. Please read the contributing guide for more information.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Metadata

Release files for drf-api-key-auth 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for drf-api-key-auth 0.3.0
File Size Uploaded
drf_api_key_auth-0.3.0.tar.gz 6.2 kB Details

Release files / drf_api_key_auth-0.3.0.tar.gz

Download URL drf_api_key_auth-0.3.0.tar.gz
Size 6.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ee607989d6216a6f0792e35c3e7f1fbe9c717ea6cb112e38d79dc25fb60102a3
BLAKE2b-256 checksum
How to use checksums
b140446fc8458fef3cba2ba2a3509b48c4defc7e13d0540d54aef1dee41082a0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.3.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page