Django REST Framework Simple API Key 🔐
Django REST Framework Simple API Key is a fast and secure API Key authentication plugin for REST API built with Django Rest Framework.
For the full documentation, visit https://djangorestframework-simple-apikey.readthedocs.io/en/latest/.
Package Renaming Notice
Notice: The djangorestframework-simple-apikey package is being renamed to drf-simple-apikey to improve usability and align with common naming conventions. Please update your installations:
- Replace the old package:
pip uninstall djangorestframework-simple-apikey pip install drf-simple-apikey
For the full documentation, visit https://djangorestframework-simple-apikey.readthedocs.io/en/latest/.
Introduction
Django REST Simple Api Key is a package built upon Django, Django REST Framework, and the fernet cryptography module to generate, encrypt, and decrypt API keys. It provides fast, secure and customizable API Key authentication.
Requirements:
- Python 3.10, 3.11, 3.12, or 3.13
- Django 4.2.17+ or Django 5.x (up to 6.0)
- Django REST Framework 3.15.2+
Benefits
Why should you use this package for your API Key authentication?
-
⚡️Fast: We use the fernet cryptography module to generate, encrypt, and decrypt API keys. Besides the security facade, it is blazing fast allowing you to treat requests quickly and easily.
-
🔐 Secure: Fernet guarantees that a message encrypted using it cannot be manipulated or read without the key, which we call
FERNET_KEY. The package includes comprehensive security features like timing attack protection, HTTPS enforcement, IP validation, and audit logging. As long as you treat the fernet key at the same level you treat the DjangoSECRET_KEYsetting, you are good to go. -
🔧 Customizable: The models, authentication backend, and permissions classes can be rewritten and fit your needs. We do our best to extend Django classes and methods, so you can easily extend our classes and methods.😉 Your Api Key authentication settings are kept in a single configuration dictionary named
DRF_API_KEYin thesettings.pyfile of your Django project. It can be customized to fit your project needs. -
📝 Well-typed: The entire codebase includes comprehensive type annotations, making it easier to work with in modern Python development environments.
Quickstart
1 - Install with pip:
pip install drf-simple-apikey
2 - Register the app in the INSTALLED_APPS in the settings.py file:
# settings.py
INSTALLED_APPS = [
# ...
"rest_framework",
"drf_simple_apikey",
]
3- Add the FERNET_KEY setting in your DRF_API_KEY configuration dictionary. You can easily generate a fernet key using the python manage.py generate_fernet_key command. Keep in mind that the fernet key plays a huge role in the api key authentication system.
DRF_API_KEY = {
"FERNET_SECRET": "sVjomf7FFy351xRxDeJWFJAZaE2tG3MTuUv92TLFfOA="
}
4 - Run migrations:
python manage.py migrate
In your view then, you can add the authentication class and the permission class.
⚠️ Important Note: By default, authentication is performed using the
AUTH_USER_MODELspecified in the settings.py file.
from rest_framework import viewsets
from drf_simple_apikey.backends import APIKeyAuthentication
from rest_framework.response import Response
class FruitViewSets(viewsets.ViewSet):
http_method_names = ["get"]
authentication_classes = (APIKeyAuthentication,)
def list(self, request):
return Response([{"detail": True}], 200)
Generate a Fernet Key
We've made it easier for you by creating a custom Django command to quickly generate a fernet key, which is a crucial component in the authentication system. Make sure to keep the key secure and store it somewhere safely (ie: environment variable).
Important ⛔️ : You should treat the FERNET_KEY security at the same level as the Django SECRET_KEY. 🫡
To generate the fernet key use the following command:
python manage.py generate_fernet_key
Rotation
We implement an API key rotation strategy for this package. To learn more about it, refer to the documentation at https://djangorestframework-simple-apikey.readthedocs.io/en/latest/rotation.html.
Demo
You can find a demo in project in the example directory. To run the project, you can :
cd example
pip install -r requirements.txt
python manage.py migrate
python manage.py runserver
Changelog
See CHANGELOG.md.
Contributing
Thank you for your interest in contributing to the project! Here's a guide to help you get started:
-
Setup Development Environment:
git clone https://github.com/koladev32/drf-simple-apikey.git
Use the command below to set up your environment:
make install -
Format the Code:
Before submitting any code, please ensure it is formatted according to our standards:make format -
Check Code and Migrations:
Validate your changes against our checks:make check -
Run Migrations:
If your changes include database migrations, run the following:make migrations -
Run Tests:
Always make sure your changes pass all our tests:make test
See CONTRIBUTING.md.
Metadata
Release files for drf-simple-apikey 2.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| drf_simple_apikey-2.4.1.tar.gz | 32.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| drf_simple_apikey-2.4.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 63.3 kB
Release files / drf_simple_apikey-2.4.1.tar.gz
| Download URL | drf_simple_apikey-2.4.1.tar.gz |
|---|---|
| Size | 32.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a9d909a3c09858557dd31f31c1a1bed2677b29b2c1dc3db981113f965c601278
|
|
BLAKE2b-256 checksum How to use checksums |
09c056b39e5f210658aeb58dcaee50dfe43e238fe94b1b8689e318826ebf96bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 3, 2026.
Transparency logRelease files / drf_simple_apikey-2.4.1-py2.py3-none-any.whl
| Download URL | drf_simple_apikey-2.4.1-py2.py3-none-any.whl |
|---|---|
| Size | 30.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
c6f0f1f71b9c52cb162b12052c037895b7e6b166bc20755f2e1c7744ab79821d
|
|
BLAKE2b-256 checksum How to use checksums |
e3d882d9e86ad4443d0007618e02bcfdec5786d7e61fa78dddc1d66b29485a8b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 3, 2026.
Transparency log