Skip to main content

A Django app for generating fake data using Faker.

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).

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.3.3.tar.gz (6.8 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.3.3-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_fakegen-3.3.3.tar.gz
  • Upload date:
  • Size: 6.8 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.3.3.tar.gz
Algorithm Hash digest
SHA256 2187146a3e1de67dd51dfc96212499728cf5eaa9c9e8d2be1aa4f12528777ec4
MD5 c20f6094a2c211699d7c2de775117dee
BLAKE2b-256 3acbac70c75ae6c9ed843995496ce7ce691d1b902e9eaa01f8dc99aa991381c7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_fakegen-3.3.3-py3-none-any.whl
  • Upload date:
  • Size: 10.2 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.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 22b18ad09ead209f44eb7e9e4775a03cda37f2b8259c50295090f47c900e0a7b
MD5 9c57418fd540320d005b1a67f70c1a08
BLAKE2b-256 577ce22506d46e3fb7ec84142cea7d8dbeda4667787574da110bddb2ddaf84d9

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