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.0.tar.gz (129.9 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.0-py3-none-any.whl (23.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_data_shape-0.1.0.tar.gz
  • Upload date:
  • Size: 129.9 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.0.tar.gz
Algorithm Hash digest
SHA256 47d938f774ef21d7061f16540ac5b61aac72aa315fee14d720818617d70b6d05
MD5 5e3d29dd6493e722ce7759a46c32981f
BLAKE2b-256 f8c32eebe299a9dc282349f75e01370843441a07e4f2446f7679efd56727bc37

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_data_shape-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_data_shape-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b29c7673c7a146e1439e4406fa64f0343517805a653438893f425c467c8c7122
MD5 fc0d2944acef8a0baec49081e1401c8d
BLAKE2b-256 457a1084f7e45c97f0c3a49808e0207eff3122772ed2fe84a25b96a8562c0303

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_data_shape-0.1.0-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

0.1.1

2 files

This release

0.1.0 This release

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