Skip to main content

Django rest library for creating, managing and securing API keys

Project description

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.

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

drf_api_key_auth-0.3.0.tar.gz (6.2 kB view details)

Uploaded Source

File details

Details for the file drf_api_key_auth-0.3.0.tar.gz.

File metadata

  • Download URL: drf_api_key_auth-0.3.0.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.6

File hashes

Hashes for drf_api_key_auth-0.3.0.tar.gz
Algorithm Hash digest
SHA256 ee607989d6216a6f0792e35c3e7f1fbe9c717ea6cb112e38d79dc25fb60102a3
MD5 9572cb53fc040ba0da86aa31ec83826f
BLAKE2b-256 b140446fc8458fef3cba2ba2a3509b48c4defc7e13d0540d54aef1dee41082a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page