Skip to main content

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 to DJANGO_SETTINGS_MODULE).
  • --pythonpath: prepend directories to PYTHONPATH before 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 after django.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,user2 and user2,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 --pythonpath and --settings.
  • Use --stdout plus jq/rg for quick inspection: djseed --stdout | jq '. | length'.

Project details


Download files

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

Source Distribution

djseed-0.1.4.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

djseed-0.1.4-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file djseed-0.1.4.tar.gz.

File metadata

  • Download URL: djseed-0.1.4.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.4 Darwin/24.6.0

File hashes

Hashes for djseed-0.1.4.tar.gz
Algorithm Hash digest
SHA256 65ba9e81fa80019f42285bf2d2c6f4a41db16b96ca80ba7837d502a311100310
MD5 9155e3dc58fd7f9fc24caf73beb35e32
BLAKE2b-256 842bda67d3fa830b95e8f86375079f830585a181eaccf8f01736d133ac6a9bd9

See more details on using hashes here.

File details

Details for the file djseed-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: djseed-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 21.9 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

Hashes for djseed-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4cfff8e96e713ceced6e8d99c8619a41c6f498218c272024872f898a11530a
MD5 2e5f219e4786789d4e0cbb288eee93ca
BLAKE2b-256 c5ffdc745d9f204bf126fc2cc4cca3467c7c220366534b1697de5eaea61b4de2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page