Skip to main content

django-data-shape

CI PyPI Python versions Django versions Docs Coverage Ruff License

A realistically shaped test database from Django models.

Declare the shape of your data -- cardinality, value skew, foreign-key fan-out as a distribution with a long tail, and where related rows physically sit -- then load it by COPY and ANALYZE it, so the query planner makes the same choices it will make in production.

It exists because a plan over ten rows is a lie, and because the loop it replaces is not merely smaller: uniform fan-out makes the planner always right, and generating children parent-by-parent clusters them perfectly, which flatters every index scan. A test database can be wrong in the flattering direction, and usually is.

Install

pip install django-data-shape[postgres]

Use

import datetime

from django_data_shape import Sequential, Shape, Skew, Table, Uniform, build

shape = Shape(
    Table(
        Order,
        rows=1_000_000,
        status=Skew({"complete": 0.98, "pending": 0.015, "cancelled": 0.005}),
        total=Uniform(0, 500, places=2),
        created_at=Sequential(
            datetime.datetime(2020, 1, 1, tzinfo=datetime.timezone.utc),
            datetime.timedelta(seconds=3),
        ),
    ),
    seed=1234,
)

build(shape)

build() generates the rows, loads them with COPY, moves the identity sequence past the keys it assigned, and runs ANALYZE so the planner can see the shape. It raises on any backend that is not PostgreSQL rather than degrading quietly.

Status

Early. This release covers single tables. Foreign-key fan-out as a distribution, physical placement, per-group invariants and template-database reuse are the releases after it; declaring a relation raises today rather than generating ids that point at nothing.

Full documentation: https://artui.github.io/django-data-shape/

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_data_shape-0.1.1.tar.gz (133.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_data_shape-0.1.1-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file django_data_shape-0.1.1.tar.gz.

File metadata

  • Download URL: django_data_shape-0.1.1.tar.gz
  • Upload date:
  • Size: 133.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for django_data_shape-0.1.1.tar.gz
Algorithm Hash digest
SHA256 60b57bddbc96d32dfa661e634a434228af64839f5b6bade53dd7fc6effba8f39
MD5 e65db7a26ae632c7803cdabba363c033
BLAKE2b-256 ff1f51e74724d9b2b6433c5fc23209868e3a4e1001219ff2e5b06077991579f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_data_shape-0.1.1.tar.gz:

Publisher: release.yml on Artui/django-data-shape

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_data_shape-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_data_shape-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b50335cafbc2ce23693558a54a3abcc3ca2d130d5ca966f70a2dc0d95e76c47
MD5 c22a2041e0c3cea79f889f14bd5a71ea
BLAKE2b-256 980b6531b83b61de4816df3afc50ffc04bcd9897de38d0d6b8bea10cad85f644

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_data_shape-0.1.1-py3-none-any.whl:

Publisher: release.yml on Artui/django-data-shape

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.21.0

2 files

0.20.0

2 files

0.19.0

2 files

0.18.1

2 files

0.18.0

2 files

0.17.1

2 files

0.17.0

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

This release

0.1.1 This release

2 files

0.1.0

2 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