skillfed

django-read-only

Disable Django database writes.

django-read-only v1.21.0 125.0K downloads/30d#11,841 on PyPI111
Permissive license MIT Active released

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-only

uv

uv add django-read-only

poetry

poetry add django-read-only

Installing 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

Development Status :: 5 - Production/StableFramework :: Django :: 4.2Framework :: Django :: 5.0Framework :: Django :: 5.1Framework :: Django :: 5.2Framework :: Django :: 6.0Framework :: IPythonIntended Audience :: DevelopersNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonTyping :: Typed

Tags

django read-only modedisable django database writesprevent accidental database changesdjango query interceptionsafe exploratory queries djangodjango write protectiondatabase mutation blocking
django-extensiondatabase-safetyinteractive-shell

More Database packages

psycopg2-binary

psycopg2-binary is a PostgreSQL database…

copyleft · top 1,000 on PyPI

redis

Python client library for connecting to and…

permissive · top 1,000 on PyPI

ydb

YDB Python SDK is the official client library…

permissive · top 1,000 on PyPI

snowflake-connector-python

Connects Python applications to Snowflake data…

permissive · top 1,000 on PyPI

sqlparse

sqlparse tokenizes SQL text into a tree of…

permissive · top 1,000 on PyPI

dbt-adapters

Provides base adapter protocols and shared…

permissive · top 1,000 on PyPI

django-pgtrigger

django-pgtrigger lets you define PostgreSQL…

permissive · top 5,000 on PyPI

django-pgmigrate

Prevents migration downtime by detecting and…

permissive · top 5,000 on PyPI

django-dirtyfields

Tracks which fields on a Django model instance…

permissive · top 15,000 on PyPI

django-guardian

django-guardian adds per-object permission…

permissive · top 5,000 on PyPI

atomicwrites

Provides a context manager for writing files…

permissive · top 5,000 on PyPI

django-zen-queries

Prevents unintended database queries in Django…

permissive · top 15,000 on PyPI

drf-access-policy

Declares access control rules for Django REST…

permissive · top 15,000 on PyPI

DrissionRecord

Buffers and writes data to files (xlsx, csv,…

permissive · top 15,000 on PyPI

django-constance

Django-constance lets you store and manage…

permissive · top 5,000 on PyPI

django-upgrade

Automatically modernizes Django project code by…

permissive · top 15,000 on PyPI