skillfed

django-pgviews-redux

Create and manage Postgres SQL Views in Django

django-pgviews-redux v1.2.0 234.5K downloads/30d#9,021 on PyPI81
License unclear Active released

What it is and what it does

django-pgviews-redux is a Django extension that brings PostgreSQL views into the ORM as first-class model-like objects. Instead of writing raw SQL or using database triggers outside Django, you define views by subclassing `pg.View`, specify the underlying SQL, and manage them through Django migrations just like regular models. The package handles view creation, updates, and deletion automatically during migrations, and provides a `sync_pgviews` management command for manual synchronization.

It supports both regular views and materialized views (which cache results for faster queries). Materialized views can be refreshed manually or via signals, and on PostgreSQL 9.4+ can use concurrent refresh to avoid blocking reads. The package also handles view dependencies, ensuring dependent views are created in the correct order, and provides utilities to drop and recreate views when upstream table columns change—a common migration pain point.

Use it for:

  • Create read-only aggregated or filtered views of your data that behave like queryable Django models without duplicating data.
  • Build materialized views to cache expensive query results and refresh them on demand or via signals when source data changes.
  • Manage complex SQL views alongside your Django models in migrations, keeping schema definitions in Python code.
  • Handle PostgreSQL-specific view dependencies and concurrent refresh patterns without writing raw migration operations.
  • Query views using the Django ORM (filtering, ordering, pagination) just like regular models, without raw SQL in application code.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Adds first-class PostgreSQL view support to Django's ORM, allowing you to define, manage, and query database views as Django models.

Yes, if you use PostgreSQL and need to manage views within Django's ORM and migration system. The package is actively maintained, supports current Django and Python versions, and has no known vulnerabilities. The main caveat is the unclear license status—verify the actual license in the repository before adopting. Install friction is low and the feature set is well-documented.

Install

django-pgviews-redux on PyPI

pip

pip install django-pgviews-redux

uv

uv add django-pgviews-redux

poetry

poetry add django-pgviews-redux

Installing django-pgviews-redux

Before you install

Low install friction with a single runtime dependency on django. Active maintenance with recent commits (2026-08-10) and support for modern Python versions (3.10–3.14) and Django versions (5.2, 6.0).

License in practice

License status is unclear; the package has no SPDX identifier or raw license declaration in its metadata. Verify the actual license terms in the repository before adopting.

Quickstart

pip install django-pgviews-redux

# In settings.py, add 'django_pgviews' to INSTALLED_APPS

from django_pgviews import view as pg
from django.db import models

class PreferredCustomer(pg.View):
    name = models.CharField(max_length=100)
    sql = "SELECT id, name FROM myapp_customer WHERE is_preferred IS TRUE"
    class Meta:
        managed = False

# Then run: python manage.py migrate

Requires PostgreSQL as the database backend; views are PostgreSQL-specific and cannot be used with other database engines.

Verify before relying

  • Whether the package is licensed under an open-source license compatible with your project (license metadata is absent).
  • Performance characteristics of materialized view refresh operations under concurrent load.
  • Compatibility with custom Django migration autodetectors beyond the documented subclassing pattern.

Package facts

License not declared (unclear)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — django
Maintenance actively maintained — 156 days since the last release
Last repo commit
First released
Downloads 234,483/month — #9,021 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: django_pgviews_redux-1.2.0-py3-none-any.whl

Keywords: django, views, materialized views, postgres

Development Status :: 5 - Production/StableFramework :: DjangoFramework :: Django :: 5.2Framework :: Django :: 6.0Programming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

postgres views django ormsql views django modelsmaterialized views djangopostgresql view managementdjango database viewspostgres view migrationsdjango pgviews
django-extensionpostgres-viewsorm-integration

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

dj-materialized-views

Manages PostgreSQL materialized views through a…

permissive · top 15,000 on PyPI

sqlalchemy-views

Adds CreateView and DropView SQL constructs to…

permissive · top 15,000 on PyPI

django-postgres-extra

Extends Django's ORM to expose…

permissive · top 15,000 on PyPI

django-multitenant

Adds multi-tenant database support to Django by…

permissive · top 15,000 on PyPI

alembic_utils

Extends Alembic to autogenerate database…

permissive · top 5,000 on PyPI

schemainspect

Inspects PostgreSQL database schemas to extract…

permissive · top 15,000 on PyPI

django-pg-migration-tools

Provides safer, production-ready Django…

permissive · top 15,000 on PyPI

django-pgtrigger

django-pgtrigger lets you define PostgreSQL…

permissive · top 5,000 on PyPI

django-pg-zero-downtime-migrations

Provides a Django database backend for…

permissive · top 15,000 on PyPI

django-add-default-value

Provides a Django migration operation to set…

permissive · top 15,000 on PyPI