{"id":23331755,"url":"https://github.com/koladev32/drf-simple-apikey","last_synced_at":"2025-12-27T21:54:16.257Z","repository":{"id":65692173,"uuid":"552020389","full_name":"koladev32/drf-simple-apikey","owner":"koladev32","description":"🔐 A simple package for API Key authentication in Django Rest with rotation integrated.","archived":false,"fork":false,"pushed_at":"2024-06-26T19:13:25.000Z","size":238,"stargazers_count":35,"open_issues_count":4,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-09-04T07:42:47.997Z","etag":null,"topics":["api","apikey-authentication","django","django-rest-framework","fernet"],"latest_commit_sha":null,"homepage":"https://djangorestframework-simple-apikey.readthedocs.io/en/latest/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koladev32.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-15T16:28:28.000Z","updated_at":"2024-08-14T22:51:46.000Z","dependencies_parsed_at":"2023-02-19T13:01:30.544Z","dependency_job_id":"aa1fecb2-009a-4fdf-ae27-d647963f15ef","html_url":"https://github.com/koladev32/drf-simple-apikey","commit_stats":{"total_commits":234,"total_committers":5,"mean_commits":46.8,"dds":0.2136752136752137,"last_synced_commit":"82398e4963a162beebf36ca19bdf773711a96817"},"previous_names":["koladev32/djangorestframework-simple-apikey","koladev32/drf-simple-apikey","koladev32/drf-apikey"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koladev32%2Fdrf-simple-apikey","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koladev32%2Fdrf-simple-apikey/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koladev32%2Fdrf-simple-apikey/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koladev32%2Fdrf-simple-apikey/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koladev32","download_url":"https://codeload.github.com/koladev32/drf-simple-apikey/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":232076577,"owners_count":18469236,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","apikey-authentication","django","django-rest-framework","fernet"],"created_at":"2024-12-20T22:44:44.289Z","updated_at":"2025-12-27T21:54:16.250Z","avatar_url":"https://github.com/koladev32.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django REST Framework Simple API Key 🔐\n\nDjango REST Framework Simple API Key is a fast and secure API Key authentication plugin for REST API built with [Django Rest Framework](https://www.django-rest-framework.org/).\n\n\u003cdiv\u003e\n  \u003ca href=\"https://badge.fury.io/py/drf-simple-apikey\"\u003e\n      \u003cimg src=\"https://badge.fury.io/py/drf-simple-apikey.svg\" alt=\"Version\"/\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/koladev32/drf-simple-apikey/actions/workflows/ci-cd.yml\"\u003e\n      \u003cimg src=\"https://github.com/koladev32/drf-simple-apikey/actions/workflows/ci-cd.yml/badge.svg\" alt=\"Testing\"/\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\nFor the full documentation, visit [https://djangorestframework-simple-apikey.readthedocs.io/en/latest/](https://djangorestframework-simple-apikey.readthedocs.io/en/latest/).\n\n## Package Renaming Notice\n\n**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:\n\n1. Replace the old package:\n   ```bash\n   pip uninstall djangorestframework-simple-apikey\n   pip install drf-simple-apikey\n   ```\n\nFor the full documentation, visit [https://djangorestframework-simple-apikey.readthedocs.io/en/latest/](https://djangorestframework-simple-apikey.readthedocs.io/en/latest/).\n\n## Introduction\n\nDjango 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.\n\n**Requirements:**\n- Python 3.10, 3.11, 3.12, or 3.13\n- Django 4.2.17+ or Django 5.x (up to 6.0)\n- Django REST Framework 3.15.2+\n\n### Benefits\n\nWhy should you use this package for your API Key authentication?\n\n* ⚡**️Fast**: We use the [fernet](https://cryptography.io/en/latest/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.\n    \n* 🔐 **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 Django `SECRET_KEY` setting, you are good to go.\n    \n* 🔧 **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_KEY` in the `settings.py` file of your Django project. It can be customized to fit your project needs.\n\n* 📝 **Well-typed**: The entire codebase includes comprehensive type annotations, making it easier to work with in modern Python development environments.\n    \n\n## Quickstart\n\n1 - Install with `pip`:\n\n```bash\npip install drf-simple-apikey\n```\n\n2 - Register the app in the `INSTALLED_APPS` in the `settings.py` file:\n\n```python\n# settings.py\n\nINSTALLED_APPS = [\n  # ...\n  \"rest_framework\",\n  \"drf_simple_apikey\",\n]\n```\n\n3- 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.\n\n```python\nDRF_API_KEY = {\n    \"FERNET_SECRET\": \"sVjomf7FFy351xRxDeJWFJAZaE2tG3MTuUv92TLFfOA=\"\n}\n```\n\n4 - Run migrations:\n\n```bash\npython manage.py migrate\n```\n\nIn your view then, you can add the authentication class and the permission class.\n\n\u003e ⚠️ **Important Note**: By default, authentication is performed using the `AUTH_USER_MODEL` specified in the settings.py file.\n\n```python\nfrom rest_framework import viewsets\n\nfrom drf_simple_apikey.backends import APIKeyAuthentication\nfrom rest_framework.response import Response\n\n\nclass FruitViewSets(viewsets.ViewSet):\n  http_method_names = [\"get\"]\n  authentication_classes = (APIKeyAuthentication,)\n\n  def list(self, request):\n    return Response([{\"detail\": True}], 200)\n```\n\n## Generate a Fernet Key\nWe'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). \n\n**Important ⛔️** : You should treat the `FERNET_KEY` security at the same level as the Django `SECRET_KEY`. 🫡\n\nTo generate the fernet key use the following command:\n\n```python\npython manage.py generate_fernet_key\n```\n\n## Rotation\n\nWe 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.\n\n## Demo\n\nYou can find a demo in project in the `example` directory. To run the project, you can :\n\n```shell\ncd example\npip install -r requirements.txt\n\npython manage.py migrate\npython manage.py runserver\n```\n\n## Changelog\n\nSee [CHANGELOG.md](https://github.com/koladev32/drf-simple-apikey/blob/main/CHANGELOG.md).\n\n## Contributing\n\nThank you for your interest in contributing to the project! Here's a guide to help you get started:\n\n- **Setup Development Environment:**  \n  ```bash\n  git clone https://github.com/koladev32/drf-simple-apikey.git\n  ```  \n  Use the command below to set up your environment:\n  ```\n  make install\n  ```\n\n- **Format the Code:**  \n  Before submitting any code, please ensure it is formatted according to our standards:\n  ```\n  make format\n  ```\n\n- **Check Code and Migrations:**  \n  Validate your changes against our checks:\n  ```\n  make check\n  ```\n\n- **Run Migrations:**  \n  If your changes include database migrations, run the following:\n  ```\n  make migrations\n  ```\n\n- **Run Tests:**  \n  Always make sure your changes pass all our tests:\n  ```\n  make test\n  ```\n\nSee [CONTRIBUTING.md](https://github.com/koladev32/drf-simple-apikey/blob/main/CONTRIBUTING.md).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoladev32%2Fdrf-simple-apikey","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoladev32%2Fdrf-simple-apikey","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoladev32%2Fdrf-simple-apikey/lists"}