Skip to main content

API key permissions for the Django REST Framework

Project description

djangorestframework-api-key

API key permissions for the Django REST Framework.

python versions django versions drf versions

Introduction

djangorestframework-api-key is a powerful library for allowing server-side clients to safely use your API. These clients are typically third-party backends and services (i.e. machines) which do not have a user account but still need to interact with your API in a secure way.

Features

  • ✌️ Simple to use: create, view and revoke API keys via the admin site, or use built-in helpers to create API keys programmatically.
  • 🔒 As secure as possible: API keys are treated with the same level of care than user passwords. They are hashed using the default password hasher before being stored in the database, and only visible at creation.
  • 🎨 Customizable: satisfy specific business requirements by building your own customized API key models, permission classes and admin panels.

Should I use API keys?

There are important security aspects you need to consider before switching to an API key access control scheme. We've listed some of these in Security caveats, including serving your API over HTTPS.

Besides, see Why and when to use API keys for hints on whether API keys can fit your use case.

API keys are ideal in the following situations:

  • Blocking anonymous traffic.
  • Implementing API key-based throttling. (Note that Django REST Framework already has may built-in utilities for this use case.)
  • Identifying usage patterns by logging request information along with the API key.

They can also present enough security for authorizing internal services, such as your API server and an internal frontend application.

Please note that this package is NOT meant for authentication. You should NOT use this package to identify individual users, either directly or indirectly.

If you need server-to-server authentication, you may want to consider OAuth instead. Libraries such as django-oauth-toolkit can help.

Quickstart

Install the latest version with pip:

pip install djangorestframework-api-key

Add the app to your INSTALLED_APPS:

# settings.py

INSTALLED_APPS = [
  # ...
  "rest_framework",
  "rest_framework_api_key",
]

Run the included migrations:

python manage.py migrate

To learn how to configure permissions and manage API keys, head to the Documentation.

Changelog

See CHANGELOG.md.

Contributing

See CONTRIBUTING.md.

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

djangorestframework-api-key-1.3.0.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file djangorestframework-api-key-1.3.0.tar.gz.

File metadata

  • Download URL: djangorestframework-api-key-1.3.0.tar.gz
  • Upload date:
  • Size: 11.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for djangorestframework-api-key-1.3.0.tar.gz
Algorithm Hash digest
SHA256 c20c1f75cd94697e8418495bbdb548d9492c5ab6355420b252e6ef5706f3280a
MD5 e8184a9a6c4c8f0a2227a6a5299b11d2
BLAKE2b-256 75de9cd994ae2b7e16b4592f55ccaca44fe6c4df7be7c8c8af36830e1269444b

See more details on using hashes here.

File details

Details for the file djangorestframework_api_key-1.3.0-py3-none-any.whl.

File metadata

  • Download URL: djangorestframework_api_key-1.3.0-py3-none-any.whl
  • Upload date:
  • Size: 21.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for djangorestframework_api_key-1.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c9eb21e6575aaccbdc13497300809ca52d204569fe70d816455bc2670acee94a
MD5 af8872855c794762165208ea8ac54248
BLAKE2b-256 0b533c27841b7e866f79d57f4b592322fcf5e1caf7cf91e5f5770308ff21da59

See more details on using hashes here.

Supported by

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