Skip to main content

Django Perimeter

Perimeter is a Django app that provides middleware that allows you to 'secure the perimeter' of your django site outside of any existing auth process that you have.

Compatibility

This package now requires Python 3.12+ and Django 5.2-6.0.

For previous versions please refer to the relevant branch.

Why?

Most django sites have some kind of user registration and security model - a login process, decorators to secure certain URLs, user accounts - everything that comes with django.contrib.auth and associated apps.

Sometimes, however, you want to simply secure the entire site to prevent prying eyes - the classic example being before a site goes live. You want to erect a secure perimeter fence around the entire thing. If you have control over your front-end web server (e.g. Apache, Nginx) then this can be used to do this using their in-built access control features. However, if you are running your app on a hosting platform you may not have admin access to these parts. Even if you do have control over your webserver, you may not want to be re-configuring it every time you want to grant someone access.

That's when you need Perimeter.

Perimeter provides simple tokenised access control over your entire Django site (everything, including the admin site and login pages).

How does it work?

Once you have installed and enabled Perimeter, everyone requiring access will need an authorisation token (not authentication - there is nothing inherent in Perimeter to prevent people swapping / sharing tokens - that is an accepted use case).

Perimeter runs as middleware that will inspect the user's session for a token. If they have a valid token, then they continue to use the site uninterrupted. If they do not have a token, or the token is invalid (expired or set to inactive), then they are redirected to the Perimeter 'Gateway', where they must enter a valid token, along with their name and email (for auditing purposes - this is stored in the database).

To create a new token you need to head to the admin site, and create a new token under the Perimeter app. If you have PERIMETER_ENABLED set to True already you won't be able to access the admin site (as Perimeter covers everything except for the perimeter 'gateway' form), and so there is a management command (create_access_token) that you can use to create your first token. (This is analagous to the Django setup process where it prompts you to create a superuser.)

Setup

  1. Add "perimeter" to your installed apps.
  2. Add "perimeter.middleware.PerimeterAccessMiddleware" to the list of MIDDLEWARE_CLASSES
  3. Add the perimeter urls, including the "perimeter" namespace.
  4. Add PERIMETER_ENABLED = True to your settings file. This setting can be used to enable or disable Perimeter in different environments.

Settings:

    PERIMETER_ENABLED = True

    INSTALLED_APPS = (
        ...
        "perimeter",
        ...
    )

    # Perimeter's middleware must be after SessionMiddleware as it relies on
    # request.session
    MIDDLEWARE_CLASSES = [
        ...
        "django.contrib.sessions.middleware.SessionMiddleware",
        "perimeter.middleware.PerimeterAccessMiddleware",
        ...
    ]

Site urls:

    # in site urls
    urlpatterns = [
        ...
        # NB you must include the namespace, as it is referenced in the app
        path("perimeter/", include("perimeter.urls", namespace="perimeter")),
        ...
    ]

Tests

The app has a suite of tests, and a tox.ini file configured to run them when using tox (recommended).

Metadata

Release files for django-perimeter 0.18.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-perimeter 0.18.1
File Size Uploaded
django_perimeter-0.18.1.tar.gz 12.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-perimeter 0.18.1
File Interpreter ABI Platform
django_perimeter-0.18.1-py3-none-any.whl Python 3 none any Details

Total release size: 29.2 kB

Release files / django_perimeter-0.18.1.tar.gz

Download URL django_perimeter-0.18.1.tar.gz
Size 12.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5995ff9aa25265b626a93bc624d7ea0f99c61bb5b782c98541fd670cfa6829bb
BLAKE2b-256 checksum
How to use checksums
2ef73054fbb5d700735971fd0e8d2f6c5238ee5f873450164903cb371d688f7e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / django_perimeter-0.18.1-py3-none-any.whl

Download URL django_perimeter-0.18.1-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da38bdcb92a15cff056d7f905f285d9e864a469c59a6ebd5db3655185060a7be
BLAKE2b-256 checksum
How to use checksums
554d8e44e5d4a64366abf6754ac3e6ea061c6ff7feaccb5d1d20675c4d587ee4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

This release

0.18.1 This release

2 release files

0.17.0

2 release files

0.16.0

2 release files

0.15.0

2 release files

0.14.2

2 release files

0.14.1

2 release files

0.14

2 release files

0.12.1

2 release files

0.12

2 release files

0.11

2 release files

0.10

2 release files

0.9.1

2 release files

0.9

2 release files

0.8.1

2 release files

0.8

2 release files

0.7.1

1 release file

0.7

1 release file

0.6.7

3 release files

0.6.6

3 release files

0.6.5

3 release files

0.6.4

3 release files

0.6.3

3 release files

0.6.2

3 release files

0.6.1

3 release files

0.6

3 release files

0.5.1

3 release files

0.5

3 release files

0.4.2

3 release files

0.4.1

0.4

3 release files

0.3.7

3 release files

0.3.6

2 release files

0.3.5

3 release files

0.3

3 release files

0.2.1

3 release files

0.2

3 release files

0.1.1

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page