Django RLS
A Django package that provides PostgreSQL Row Level Security (RLS) capabilities at the database level.
See CONTRIBUTING.md.
Security
See SECURITY.md.
Features
- 🔒 Database-level Row Level Security using PostgreSQL RLS
- 🏢 Tenant-based and user-based policies
- 🐍 Pythonic Policies: Define policies using standard Django
Qobjects - 🌳 Hierarchical RLS: Support for recursive CTEs and nested organizations
- ⚡ Context Processors: Inject dynamic context variables (e.g. user IP, session data)
- 🔧 Django 5.0, 5.1, 5.2 (LTS), and 6.0 support
- 🧪 Comprehensive test coverage
- 📖 Extensible policy system
- ⚡ Performance optimized
Quick Start
from django.db import models
from django.db.models import Q
from django_rls.models import RLSModel
from django_rls.policies import ModelPolicy, RLS
class Project(RLSModel):
name = models.CharField(max_length=100)
owner = models.ForeignKey(User, on_delete=models.CASCADE)
is_public = models.BooleanField(default=False)
class Meta:
rls_policies = [
# Pythonic Policy: Owner OR Public
ModelPolicy(
'access_policy',
filters=Q(owner=RLS.user_id()) | Q(is_public=True)
),
]
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, 5.2 (LTS), or 6.0
- 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.
Metadata
Release files for django-rls 2.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_rls-2.0.1.tar.gz | 23.5 kB | With provenance | Details for django_rls-2.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_rls-2.0.1-py3-none-any.whl | Python 3 | none | any | Details for django_rls-2.0.1-py3-none-any.whl |
Total release size: 51.0 kB
Release files / django_rls-2.0.1.tar.gz
| Download URL | django_rls-2.0.1.tar.gz |
|---|---|
| Size | 23.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d15f7b27012a61fbafc983e66105c1550b56cbc39b848e6190ef40d2431f5ad3
|
|
BLAKE2b-256 checksum How to use checksums |
a83d7f4f7c9928c4a0f3045e017bdc0c8f9bd5dfbc3a91c95e535f8f7f0bd7de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 1, 2026.
Transparency logRelease files / django_rls-2.0.1-py3-none-any.whl
| Download URL | django_rls-2.0.1-py3-none-any.whl |
|---|---|
| Size | 27.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2ec92524fcd6b2931d453f6ad21189c11f5238563fc6c3113f587734b4252b36
|
|
BLAKE2b-256 checksum How to use checksums |
1281d8bfe6624405ed04f538a915c44b5408097c8f5936df78b47d65c0fda4ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 1, 2026.
Transparency logSecurity for django-rls 2.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_rls-2.0.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.