django-data-shape
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47d938f774ef21d7061f16540ac5b61aac72aa315fee14d720818617d70b6d05
|
|
| MD5 |
5e3d29dd6493e722ce7759a46c32981f
|
|
| BLAKE2b-256 |
f8c32eebe299a9dc282349f75e01370843441a07e4f2446f7679efd56727bc37
|
Provenance
The following attestation bundles were made for django_data_shape-0.1.0.tar.gz:
Publisher:
release.yml on Artui/django-data-shape
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_data_shape-0.1.0.tar.gz -
Subject digest:
47d938f774ef21d7061f16540ac5b61aac72aa315fee14d720818617d70b6d05 - Sigstore transparency entry: 2678705372
- Sigstore integration time:
-
Permalink:
Artui/django-data-shape@a67453eb0dea0934cc70aefe9bd1c81e21e635ae -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Artui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a67453eb0dea0934cc70aefe9bd1c81e21e635ae -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_data_shape-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_data_shape-0.1.0-py3-none-any.whl
- Upload date:
- Size: 23.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b29c7673c7a146e1439e4406fa64f0343517805a653438893f425c467c8c7122
|
|
| MD5 |
fc0d2944acef8a0baec49081e1401c8d
|
|
| BLAKE2b-256 |
457a1084f7e45c97f0c3a49808e0207eff3122772ed2fe84a25b96a8562c0303
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_data_shape-0.1.0-py3-none-any.whl -
Subject digest:
b29c7673c7a146e1439e4406fa64f0343517805a653438893f425c467c8c7122 - Sigstore transparency entry: 2678705407
- Sigstore integration time:
-
Permalink:
Artui/django-data-shape@a67453eb0dea0934cc70aefe9bd1c81e21e635ae -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Artui
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a67453eb0dea0934cc70aefe9bd1c81e21e635ae -
Trigger Event:
push
-
Statement type: