Skip to main content

PostgreSQL Row Level Security (RLS) for Django applications

Project description

Django RLS

PyPI version PyPI - Downloads CI Documentation codecov Python Version Django Version License

A Django package that provides PostgreSQL Row Level Security (RLS) capabilities at the database level.

Features

  • 🔒 Database-level Row Level Security using PostgreSQL RLS
  • 🏢 Tenant-based and user-based policies
  • 🔧 Django 5.0, 5.1, and 5.2 (LTS) support
  • 🧪 Comprehensive test coverage
  • 📖 Extensible policy system
  • ⚡ Performance optimized

Quick Start

from django_rls.models import RLSModel
from django_rls.policies import TenantPolicy, UserPolicy

class TenantAwareModel(RLSModel):
    name = models.CharField(max_length=100)
    tenant = models.ForeignKey(Tenant, on_delete=models.CASCADE)
    
    class Meta:
        rls_policies = [
            TenantPolicy('tenant_policy', tenant_field='tenant'),
        ]

Installation

Install from PyPI:

pip install django-rls

Or install the latest development version:

pip install git+https://github.com/kdpisda/django-rls.git

Requirements

  • Python 3.10, 3.11, 3.12, or 3.13
  • Django 5.0, 5.1, or 5.2 (LTS)
  • PostgreSQL 12 or higher (tested with PostgreSQL 17)

Add to your Django settings:

INSTALLED_APPS = [
    # ... your apps
    'django_rls',
]

MIDDLEWARE = [
    # ... your middleware
    'django_rls.middleware.RLSContextMiddleware',
]

Documentation

Full documentation is available at django-rls.com

Quick Links

License

BSD 3-Clause License - see LICENSE file for details.

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

django_rls-0.3.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_rls-0.3.0-py3-none-any.whl (17.6 kB view details)

Uploaded Python 3

File details

Details for the file django_rls-0.3.0.tar.gz.

File metadata

  • Download URL: django_rls-0.3.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_rls-0.3.0.tar.gz
Algorithm Hash digest
SHA256 b19fb12aea426c0562f5b9c476ec9d8ef0a2f3f8ce4e308cb2a5aa32052b914b
MD5 4751871c88e2334cf5bb16db5a119850
BLAKE2b-256 5565e92238f91e353f8a6dc8e2fc92b8867ded5008d8c893d038ffb13e4bb50d

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_rls-0.3.0.tar.gz:

Publisher: release.yml on kdpisda/django-rls

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_rls-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: django_rls-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 17.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_rls-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d9dc4b914ca0597199c71c28bc254de25873725a608899c3a8948b91809fd53c
MD5 a54cfc43e5bc18baf37329a153ea39b4
BLAKE2b-256 79ac4d7887c25c8e940d87c92fd82178dc2b3c580d9716d91a5dbd4c98204662

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_rls-0.3.0-py3-none-any.whl:

Publisher: release.yml on kdpisda/django-rls

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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