Skip to main content

🎭 Intelligent test data generation for Django applications with advanced field introspection

Project description

django-fakegen

A Django package for generating smart fake data for your models. It leverages Faker to automatically populate Django models with realistic data, supporting a wide range of field types, including relations.

GitHub


Features

  • Generate fake data for any Django model, including related fields
  • Supports bulk generation
  • Customizable via field overrides
  • CLI integration via Django management command

Installation

pip install django-fakegen

Add django_fakegen to your INSTALLED_APPS if needed (not strictly required for management command usage).

Example:

# settings.py

INSTALLED_APPS = [
    # ...
    'django_fakegen',
    # ...
]

Usage

Command Line

Generate 10 fake instances for a model:

python manage.py fakegen app_label.ModelName

Generate a custom number of instances:

python manage.py fakegen app_label.ModelName --count 50

Programmatic Usage

You can use the registry directly in your code:

from django_fakegen.registry import registry

# Generate a single instance
instance = registry.generate_instance(MyModel)

# Generate multiple instances
instances = registry.bulk_generate('app_label.ModelName', count=20)

Supported Fields

django-fakegen supports the following Django field types:

Field Type Generator Behavior
CharField Title-like string, respects max_length
TextField Realistic text, up to 250 chars
IntegerField Random integer (0-100)
PositiveIntegerField Random integer (0-100)
FloatField Random float (5 digits left, 2 right)
BooleanField Random boolean
DateTimeField Random datetime (this year)
DateField Random date (this year)
TimeField Random time
EmailField Random email address
ForeignKey Random related instance
OneToOneField Random related instance
ManyToManyField List of 3 random related instances

Example

Suppose you have a model:

from django.db import models

class Author(models.Model):
    name = models.CharField(max_length=100)
    email = models.EmailField()

class Book(models.Model):
    title = models.CharField(max_length=200)
    description = models.TextField()
    published = models.BooleanField()
    author = models.ForeignKey(Author, on_delete=models.CASCADE)

You can generate fake data for Book (and related Author) with:

python manage.py fakegen myapp.Book --count 5

Or programmatically:

from django_fakegen.registry import registry
books = registry.bulk_generate('myapp.Book', count=5)

Extending

You can add your own field generators by subclassing BaseFieldGenerator and adding them to the registry.

Contributing

Contributions are welcome! If you'd like to help improve django-fakegen, please open an issue or submit a pull request on GitHub.

License

MIT

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

django_fakegen-3.4.4.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

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

django_fakegen-3.4.4-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file django_fakegen-3.4.4.tar.gz.

File metadata

  • Download URL: django_fakegen-3.4.4.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for django_fakegen-3.4.4.tar.gz
Algorithm Hash digest
SHA256 a9cc2401c842fa75b9fe963ac4ea121412320c7ded272ecace44958296ba9b83
MD5 500a822469ec08b57edf6a0dd5c8005a
BLAKE2b-256 c03f52ce34ba302f08ce8927f79f3857d7bdb3caf0bb76a77351bd2b39f1f0f5

See more details on using hashes here.

File details

Details for the file django_fakegen-3.4.4-py3-none-any.whl.

File metadata

  • Download URL: django_fakegen-3.4.4-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for django_fakegen-3.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2fc88c6f42dee5d089ed41fcc2fae5f41b978d05e0b7ddefb3520e16769d8dae
MD5 787d75ed3f3de605f5f699225c17a76a
BLAKE2b-256 b152778015e1650d741b87fb155c8be60b2597153ba468712d41400f1cd1aef5

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