Skip to main content
DjanQuiltDB

DjanQuiltDB - Django Database Sharding

PyPI Supported Python versions Supported Django versions Supported PostgreSQL versions CI Documentation BSD-3-Clause licence

DjanQuiltDB is an extension to the Django web framework that provides helper functions to split a database based on top level hierarchy. It is specifically designed to support horizontal sharding not just within a single database cluster, but also across multiple database clusters, thus allowing you to scale database capacity both vertically and horizontally as your dataset grows.

This library attempts to combine the best of as many worlds as possible. Tenant-specific data is kept in tenant-specific PostgreSQL schemas, while data that is tenant-agnostic or shared can be kept in public schemas, so as to deduplicate. There are helpers to split data off from one shard to another, to migrate a shard across nodes, to synchronize changes across nodes, etc.

As the name suggests, this approach provides an interface to data, that may in reality be scattered across various schemas in various database clusters, and presents it as a coherent and easily accessible patchwork of tables, resulting in a database resembling a quilt.

Full documentation is at https://djanquiltdb.readthedocs.io/.

Installation

pip install djanquiltdb

Add it to INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'djanquiltdb',
    ...
)

Point every connection at the bundled backend, and routing at the router:

DATABASES = {
    'default': dj_database_url.parse(DATABASE_URL, engine='djanquiltdb.postgresql_backend'),
}

DATABASE_ROUTERS = ['djanquiltdb.router.DynamicDbRouter']

Then declare a shard model of your own and name it in the QUILT_DB setting:

# myapp/models.py
from djanquiltdb.models import BaseShard


class Shard(BaseShard):
    class Meta:
        app_label = 'myapp'

# settings.py
QUILT_DB = {
    'SHARD_CLASS': 'myapp.models.Shard',
}

Models are placed with the decorators in djanquiltdb.decorators; an undecorated model stays on the default node’s public schema. manage.py migrate is shard-aware, and applies each migration wherever its models live.

To declare Postgres views and functions the same way, install the extra:

pip install djanquiltdb[postgres-objects]

See the installation docs for the full set of settings, including the template schema every node needs, the mapping model, the session backend and the middleware.

Requirements

  • Python 3.14

  • Django 6.0 or 6.1

  • PostgreSQL 17 or 18

Development

This package is developed in the DjanQuiltDB repository beside its in-tree plugins, each shipped as a distribution of its own.

Code style

Ruff handles both linting and formatting. Enable the git hook once per clone:

pre-commit install

The same checks run over the whole tree with:

pre-commit run --all-files

Tests

Tox, run from the repository root, runs the suite against every Django and PostgreSQL version the package claims. It needs the PostgreSQL containers in the repository’s docker-compose.yml; see DOCKER.md at the repository root:

docker compose run --rm test tox -m core

The suite runs without any placement plugin installed: plugins carry suites of their own.

The test project reads its connection strings from packages/djanquiltdb/tests/secrets.json when that file exists, which is how a run outside the containers is pointed at your own databases:

cp packages/djanquiltdb/tests/secrets.json.example packages/djanquiltdb/tests/secrets.json

Building

docker compose run --no-deps --rm test tox -e core-build

The sdist and wheel are placed in packages/djanquiltdb/dist/ and checked with twine.

Documentation

The documentation lives in docs/ at the repository root, shared with the in-tree plugins. Build it with:

docker compose run --no-deps --rm test tox -e docs

Attribution

This is an independently maintained fork of the patchman-django-sharding library originally created and maintained by Patchman B.V. (2017-2023) and Cloud Linux Software, Inc. (2023-2025).

Metadata

Release files for djanquiltdb 4.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for djanquiltdb 4.0.1
File Size Uploaded
djanquiltdb-4.0.1.tar.gz 270.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for djanquiltdb 4.0.1
File Interpreter ABI Platform
djanquiltdb-4.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 391.0 kB

Release files / djanquiltdb-4.0.1.tar.gz

Download URL djanquiltdb-4.0.1.tar.gz
Size 270.3 kB
Tags Source
SHA-256 checksum
How to use checksums
68931e9625bf431f4f6635d5df69f6ccef45f25d7f5b0289d64785a9c4b84eaf
BLAKE2b-256 checksum
How to use checksums
accfe10f56475596080358d0ce298d93e418b310fff2fb1af495342a0e41830b
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 Oct 5, 2026.

Transparency log

Release files / djanquiltdb-4.0.1-py3-none-any.whl

Download URL djanquiltdb-4.0.1-py3-none-any.whl
Size 120.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9acddb404d92173d4303f3a23ec8aeeab64c6b0896ccf3076c2fe7731484c2b2
BLAKE2b-256 checksum
How to use checksums
bd9f10ce358b5bf0fb6d931311bb88a083b981257fe58276fb81fb0cc01ed840
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 Oct 5, 2026.

Transparency log

Release history Release notifications | RSS feed

4.2.0

2 release files

4.1.0

2 release files

This release

4.0.1 This release

2 release files

4.0.0

2 release files

3.1.2

2 release files

3.1.1

2 release files

3.1.0

2 release files

3.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page