Utility to generate synthetic fixture data for Django projects.
Project description
djseed
Generate reproducible JSON fixtures from existing Django models. The fixtures work out of the box with manage.py loaddata, making reseeding development and review databases painless.
Installation
From PyPI (recommended):
python -m pip install djseed
Or add to a Poetry project:
poetry add djseed
For local development, clone the repo and run poetry install; build with poetry build.
Requirements
- Python 3.10+
- Django (uses your project’s models and settings)
- Access to the same environment your project uses (virtualenv, Poetry env, etc.)
Quickstart (CLI)
djseed \
--pythonpath "/path/to/project/root" \
--settings config.settings.local \
--apps core feeds \
--count 300 \
--output seed_data.json
Then load the generated fixtures:
python manage.py flush # avoid FK integrity errors
python manage.py loaddata seed_data.json
Key options:
--settings: Django settings module (falls back toDJANGO_SETTINGS_MODULE).--pythonpath: prepend directories toPYTHONPATHbefore configuring Django.--apps: list of app labels to process (--apps core billing).--count: objects per model (default: 10).--output: destination JSON file (default:seed_data.json).--no-output: skip disk writes (useful if you only need the return value or--stdout).--stdout: send JSON to stdout for piping.--config: import custom modules afterdjango.setup()so you can register overrides.
Django-side configuration
Expose a DJSEED dictionary inside your settings module to tweak required or ignored fields:
# settings.py
DJSEED = {
"extra_required_fields": {
"*": {"created_at", "updated_at"},
"users.user": {"first_name", "last_name"},
},
"ignored_field_names": {
"*": {"created_by"},
},
"generic_foreign_keys": {
"feeds.notification": {
"content_object": {"feeds.like", "feeds.comment"},
},
},
"model_priorities": {
"core.user": 0,
"feeds.comment": 1,
"feeds.notification": 2,
},
"email_domain": "example.com", # default domain for generated emails
"default_password": "0000", # default password for hashable fields
}
Need to do it in code instead? Use the registry helpers:
from seeder import registry
registry.register_extra_required_fields("users.user", {"first_name"})
registry.register_ignored_field_names("*", {"created_by"})
registry.register_generic_foreign_key_models(
"feeds.notification", {"content_object": {"feeds.like", "feeds.comment"}}
)
registry.register_field_generator("users.user.cpf", my_cpf_generator) # model-specific
registry.register_field_type_generator(models.JSONField, my_json_generator)
For GenericForeignKey fields, list the fully-qualified model labels each field may point
to. djseed uses those hints to set the underlying content_type and object_id
fields with existing fixtures (when available) or with random database records.
Custom generators receive a faker instance and the Django field; return the value you want stored.
Custom generator registration is intentionally code-only (e.g., in the module passed via --config) to keep DJSEED settings minimal.
Tip: djseed works best against a migrated database. If tables are missing, it will fall back to generating everything in-memory and skip DB lookups.
- Conditional UniqueConstraints are ignored during generation to maximize combinations. Mirrored unique constraints (e.g.
user1,user2anduser2,user1) are deduplicated to reduce false collisions during fixture generation. The database will still enforce the actual constraints at load time.
Programmatic usage
from seeder import seed_all
fixtures = seed_all(
app_labels=["core", "feeds"],
count_per_model=15,
output_path="fixtures.json",
)
When output_path is provided (default seed_data.json), the file is written automatically. The function always returns the generated fixtures list so you can post-process or store it yourself.
Troubleshooting
- Make sure the command runs inside the same virtual environment as Django so apps and settings resolve correctly.
- If you see missing module errors, double-check
--pythonpathand--settings. - Use
--stdoutplusjq/rgfor quick inspection:djseed --stdout | jq '. | length'.
Project details
Release history Release notifications | RSS feed
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 djseed-0.1.3.tar.gz.
File metadata
- Download URL: djseed-0.1.3.tar.gz
- Upload date:
- Size: 20.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.4 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1322818948c3a6345baae3aa970619213e90eb6b278c7ea382de4a48bedf9078
|
|
| MD5 |
4233667041c79ad1ed80130cadb801e2
|
|
| BLAKE2b-256 |
49427f9b38f5a7c51ad4b7148e7135595797f38e60f4c95874b6c0a95b402f3d
|
File details
Details for the file djseed-0.1.3-py3-none-any.whl.
File metadata
- Download URL: djseed-0.1.3-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.4 Darwin/24.6.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a28301553dc710f84d113e9d6c8a08585190c11df0580ee066f4b0d69b0c27bd
|
|
| MD5 |
109614367ee8ca1a773e551a95dedf7b
|
|
| BLAKE2b-256 |
56a740e3daa0dbbaaf2da5428fa9bc36c5e6a244269bbdc96e2e70aaecd8693c
|