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.
Relations
Table(
Order,
rows=2_000_000,
# A distribution, not a number: giving every parent ten children is the one
# shape in which the planner is never wrong, because its n_distinct average
# is then the truth.
company=FanOut(Zipf(1.2), childless=0.35),
...
)
The parents can be rows this package built or rows your own code did -- their real keys are read, not assumed, so the ORM can own the small tables while this owns the large ones.
Status
Early. Single tables and the model graph. Derived fields, collections copied along a join, per-group invariants and template-database reuse come next.
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.2.0.tar.gz.
File metadata
- Download URL: django_data_shape-0.2.0.tar.gz
- Upload date:
- Size: 146.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c2441e50fffc6d3dc2d9bba12d6ddfdc07a19910afdf254d64c2082fbcbd0a1
|
|
| MD5 |
f1068b9b70613e1fdedfe064ea2e9034
|
|
| BLAKE2b-256 |
a25a4bc06356e00b7991cc9d1c7bebcd598f58056d4a1c0196583be928cbf28a
|
Provenance
The following attestation bundles were made for django_data_shape-0.2.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.2.0.tar.gz -
Subject digest:
9c2441e50fffc6d3dc2d9bba12d6ddfdc07a19910afdf254d64c2082fbcbd0a1 - Sigstore transparency entry: 2680192075
- Sigstore integration time:
-
Permalink:
Artui/django-data-shape@674ac99c0ff5e0cda25bd27879e321c2459f6b8f -
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@674ac99c0ff5e0cda25bd27879e321c2459f6b8f -
Trigger Event:
push
-
Statement type:
File details
Details for the file django_data_shape-0.2.0-py3-none-any.whl.
File metadata
- Download URL: django_data_shape-0.2.0-py3-none-any.whl
- Upload date:
- Size: 35.0 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 |
50839bbe9b167547c178e6a2c9b0aeae5224a9d2c96b56d10a854088713ea6ac
|
|
| MD5 |
4a98fe7bc8921d18a220b84962ecfe00
|
|
| BLAKE2b-256 |
6ab646a0ca6a4df7801b830d3d047d328203890c0afdfbab6f72e378119480d2
|
Provenance
The following attestation bundles were made for django_data_shape-0.2.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.2.0-py3-none-any.whl -
Subject digest:
50839bbe9b167547c178e6a2c9b0aeae5224a9d2c96b56d10a854088713ea6ac - Sigstore transparency entry: 2680192095
- Sigstore integration time:
-
Permalink:
Artui/django-data-shape@674ac99c0ff5e0cda25bd27879e321c2459f6b8f -
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@674ac99c0ff5e0cda25bd27879e321c2459f6b8f -
Trigger Event:
push
-
Statement type: