django-read-only
Disable Django database writes.
What it is and what it does
django-read-only is a Django package that enforces read-only mode on your database by intercepting and rejecting data modification queries. It works by inspecting executed queries at the Django database instrumentation layer and raising an exception when a write is detected. The package is designed for interactive sessions—particularly shell environments in production or staging—where developers need to run exploratory queries without risking accidental data changes.
You control read-only mode via a setting or environment variable, and can temporarily or permanently re-enable writes within a session using provided functions and context managers. It also integrates with IPython as an extension for quick toggling. The package uses a "fail closed" philosophy, meaning unknown query patterns are blocked to be safe. Note that it cannot intercept queries bypassing Django's ORM entirely or operations within stored procedures.
Use it for:
- Enable read-only mode in production shell sessions to prevent developers from accidentally modifying data during exploratory queries.
- Protect staging environments during interactive debugging by blocking write queries while allowing reads.
- Temporarily allow writes within a context manager to run a specific management command or data fix without disabling read-only mode globally.
- Use the IPython extension to quickly toggle read-only mode on and off during interactive development sessions.
- Enforce a safe-by-default policy where writes are disabled in interactive shells but remain enabled for automated processes like WSGI servers.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Prevents Django database write operations by intercepting and blocking data modification queries, with the ability to selectively re-enable writes within a session.
Yes. This is a lightweight, actively maintained package with no security vulnerabilities that solves a real operational safety problem—preventing accidental database modifications in interactive sessions. The low install friction (one dependency), permissive MIT license, and production-stable status make it a practical choice for teams running Django in production or staging environments where shell access is common.
Install
django-read-only on PyPI
pip
pip install django-read-onlyuv
uv add django-read-onlypoetry
poetry add django-read-onlyInstalling django-read-only
Before you install
Low friction installation with a single runtime dependency on Django. The package is actively maintained with recent releases and no known vulnerabilities.
License in practice
MIT license permits free use, modification, and distribution with minimal restrictions, making it suitable for both open-source and proprietary projects.
Quickstart
pip install django-read-only
# Add to INSTALLED_APPS in settings.py
INSTALLED_APPS = [..., "django_read_only", ...]
# Enable via environment variable or setting
DJANGO_READ_ONLY = True
# In shell, writes are now blocked; re-enable with:
import django_read_only
django_read_only.enable_writes()
Requires Django 4.2 to 6.0 and Python 3.9 or later. Cannot block queries executed directly through the underlying database connection or stored procedures.
Verify before relying
- Performance overhead of query inspection during read-only sessions is not quantified in the fact sheet.
- Compatibility with custom database backends or non-standard query patterns beyond standard Django ORM is unclear.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — django |
| Maintenance | actively maintained — 330 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 125,021/month — #11,841 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: django_read_only-1.21.0-py3-none-any.whl
Keywords: Django
Tags
More Database packages
psycopg2-binary is a PostgreSQL database…
copyleft · top 1,000 on PyPI
redisPython client library for connecting to and…
permissive · top 1,000 on PyPI
ydbYDB Python SDK is the official client library…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
sqlparsesqlparse tokenizes SQL text into a tree of…
permissive · top 1,000 on PyPI
dbt-adaptersProvides base adapter protocols and shared…
permissive · top 1,000 on PyPI
django-pgtriggerdjango-pgtrigger lets you define PostgreSQL…
permissive · top 5,000 on PyPI
django-pgmigratePrevents migration downtime by detecting and…
permissive · top 5,000 on PyPI
django-dirtyfieldsTracks which fields on a Django model instance…
permissive · top 15,000 on PyPI
django-guardiandjango-guardian adds per-object permission…
permissive · top 5,000 on PyPI
atomicwritesProvides a context manager for writing files…
permissive · top 5,000 on PyPI
django-zen-queriesPrevents unintended database queries in Django…
permissive · top 15,000 on PyPI
drf-access-policyDeclares access control rules for Django REST…
permissive · top 15,000 on PyPI
DrissionRecordBuffers and writes data to files (xlsx, csv,…
permissive · top 15,000 on PyPI
django-constanceDjango-constance lets you store and manage…
permissive · top 5,000 on PyPI
django-upgradeAutomatically modernizes Django project code by…
permissive · top 15,000 on PyPI