Skip to main content

Web API permissions for the Django REST Framework

Project description

djangorestframework-api-key travis

🔐 Web API permissions for the Django REST Framework.

This project is based on (yet not a fork of) the unmaintained django-rest-framework-api-key project.

Supported versions

  • Python: 3.4, 3.5, 3.6, 3.7
  • Django: 1.11 (not on Python 3.7), 2.0
  • Django REST Framework: 3.8+

Install

  • Install from PyPI:
$ pip install djangorestframework-api-key
  • Add to your INSTALLED_APPS:
INSTALLED_APPS = [
  # ...,
  'rest_framework_api_key',
]

Run the included migrations:

$ python manage.py migrate

Usage

Also see example project.

Permission classes

This package provides permission classes to allow external clients to use your API.

The HasAPIKey permission class requires all clients to provide a valid API key, regardless of whether they provide authentication details.

If you want to allow clients to provide either an API key or authentication credentials, use the utility HasAPIKeyOrIsAuthenticated permission class instead.

As with every permission class, you can either use them globally:

# settings.py

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': [
        'rest_framework_api_key.HasAPIKey',
    ]
}

or on a per-view basis:

# views.py
from rest_framework_api_key.permissions import HasAPIKey
from rest_framework.views import APIView

class UserListView(APIView):
    permission_classes = (HasAPIKey,)
    # ...

Refer to DRF Docs - Setting the permission policy for more information on using permission classes.

Development

Install

Installing locally requires Pipenv and Python 3.7.

  1. Fork the repo
  2. Clone it on your local
  3. Install dependencies with Pipenv: $ pipenv install
  4. Activate using $ pipenv shell

Tests

Run the tests using:

$ python runtests.py

Generating migrations

This package includes migrations. To regenerate them in case of changes without setting up a Django project, run:

$ python makemigrations.py rest_framework_api_key

CI/CD

Travis CI is in use to automatically:

  • Test the package on supported versions of Python and Django.
  • Deploy tagged commits to PyPI.

Refer to .travis.yml for more information.

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-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

  • Download URL: djangorestframework-api-key-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for djangorestframework-api-key-0.1.0.tar.gz
Algorithm Hash digest
SHA256 71dfeb6ba8e5eaf6afbb5b5191af6c97c81022a051ae6dc37ad3205013f324c3
MD5 4fcd02acf16044c040fc43bb59877441
BLAKE2b-256 580fef870a17a4c22ea8b93387403beb167eddb03284aa406a6fe00f220a535c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: djangorestframework_api_key-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/40.0.0 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.7.0

File hashes

Hashes for djangorestframework_api_key-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18a0dbe4a0613c6d41e85dbd2a53405080e222d1d86ea5b33502877e7f86e33c
MD5 d1d9c21a32a5c9ee7a4e210fcaa1f9cb
BLAKE2b-256 1802dd15783d8bf46dc2976306c2b2e51479afa4508d84f52760b7d22dad7871

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