--- id: django-read-only version: "1.21.0" license: MIT license_treatment: permissive maintenance: active --- # django-read-only — Disable Django database writes. License: permissive · Maintenance: active · Downloads: 125.0K/mo ## 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 above — 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 pip install django-read-only uv add django-read-only 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_current - Install friction: low - Maintenance: active - Downloads: 125.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags django read-only mode, disable django database writes, prevent accidental database changes, django query interception, safe exploratory queries django, django write protection, database mutation blocking, django-extension, database-safety, interactive-shell [View on SkillFed](https://skillfed.io/packages/django-read-only) · [View on PyPI](https://pypi.org/project/django-read-only/)