Skip to main content

MockDataGenerator 🚀

Python Version License: MIT PyPI version FastAPI Django Flask

A powerful, developer-friendly Python library for generating realistic mock data from complex Python models. Supports FastAPI (Pydantic), Django ORM, and Flask (SQLAlchemy) frameworks while preserving intricate relationships like One-to-One, One-to-Many, Many-to-Many, and recursive self-references.

✨ Key Features

  • 🔧 Framework Support: Full compatibility with FastAPI (Pydantic models), Django ORM, and SQLAlchemy declarative models
  • 🔗 Relationship Management: Automatically resolves foreign key relationships, ensuring data consistency across tables
  • 🎯 Smart Data Types: Recognizes and generates appropriate data for fields like Turkish phone numbers, IBAN, UUID, EmailStr, HttpUrl, and more
  • 🔄 Recursive Relationships: Handles self-referencing structures (e.g., Manager → Employee, Parent → Category)
  • 📤 Flexible Output: Exports generated data directly to JSON files
  • 🌍 Localization: Supports multiple locales (tr_TR, en_US, etc.) for culturally appropriate data
  • 🎮 Interactive Mode: CLI with interactive prompts for customization
  • ⚡ Fast & Efficient: Optimized generation algorithms for large datasets

📦 Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Install from Source

git clone https://github.com/yourusername/mock-data-generator.git
cd mock-data-generator
pip install -r requirements.txt

Optional Dependencies

For full framework support, install optional packages:

pip install django sqlalchemy  # For Django and SQLAlchemy models

Project Structure

mock-data-generator/
├── mock_generator/
│   ├── __init__.py
│   ├── cli.py                 # Command-line interface
│   ├── scanner.py             # Model file scanning
│   ├── analyzer.py            # Model analysis
│   ├── generator.py           # Mock data generation
│   ├── relationship_resolver.py # Relationship handling
│   ├── exporters.py           # Data export utilities
│   └── field_mappers/         # Framework-specific mappers
│       ├── django_mapper.py
│       ├── pydantic_mapper.py
│       └── sqlalchemy_mapper.py
├── examples/                  # Usage examples
│   ├── django_example/
│   ├── fastapi_example/
│   └── sqlalchemy_example/
├── pyproject.toml             # Project configuration
├── requirements.txt           # Dependencies
└── README.md

🚀 Usage

Command Line Interface

Generate mock data from your model files:

python -m mock_generator.cli generate --file path/to/your/models.py --locale tr_TR --interactive

CLI Options

  • --file: Path to your model file (required)
  • --output: Output directory (default: ./output)
  • --interactive: Enable interactive mode for customization
  • --locale: Data locale (default: en_US, supports tr_TR, etc.)

Example Usage Scenarios

1. FastAPI (Pydantic) Models

models.py

from pydantic import BaseModel, EmailStr
from typing import Optional

class Department(BaseModel):
    id: int
    name: str
    budget: float

class Employee(BaseModel):
    id: int
    name: str
    email: EmailStr
    department_id: int
    salary: Optional[float] = None

Generate Data:

python -m mock_generator.cli generate --file models.py --locale tr_TR

2. Django ORM Models

models.py

from django.db import models

class OrgDivision(models.Model):
    name = models.CharField(max_length=100)
    parent = models.ForeignKey('self', null=True, on_delete=models.CASCADE)

class StaffAssociate(models.Model):
    name = models.CharField(max_length=100)
    division = models.ForeignKey(OrgDivision, on_delete=models.CASCADE)
    supervisor = models.ForeignKey('self', null=True, on_delete=models.CASCADE)

class EnterpriseTask(models.Model):
    title = models.CharField(max_length=200)
    assignees = models.ManyToManyField(StaffAssociate)
    division = models.ForeignKey(OrgDivision, on_delete=models.CASCADE)

Generate Data:

python -m mock_generator.cli generate --file models.py --locale tr_TR --interactive

This handles complex relationships: StaffAssociate belongs to OrgDivision, has a supervisor (self-reference), and participates in Many-to-Many relationships with EnterpriseTask.

3. Flask/SQLAlchemy Models

models.py

from sqlalchemy import Column, Integer, String, ForeignKey, Float
from sqlalchemy.orm import declarative_base, relationship

Base = declarative_base()

class CloudServer(Base):
    __tablename__ = 'servers'
    id = Column(Integer, primary_key=True)
    name = Column(String(100))
    ip_address = Column(String(15))

class Tag(Base):
    __tablename__ = 'tags'
    id = Column(Integer, primary_key=True)
    name = Column(String(50))

class BackupLog(Base):
    __tablename__ = 'backup_logs'
    id = Column(Integer, primary_key=True)
    server_id = Column(Integer, ForeignKey('servers.id'))
    tag_id = Column(Integer, ForeignKey('tags.id'))
    size_gb = Column(Float)

Generate Data:

python -m mock_generator.cli generate --file models.py --locale tr_TR

📊 Generated Output

The tool generates JSON files for each model, preserving relationships:

{
  "OrgDivision": [
    {"id": 1, "name": "Engineering", "parent_id": null},
    {"id": 2, "name": "Backend", "parent_id": 1}
  ],
  "StaffAssociate": [
    {"id": 1, "name": "Ahmet Yılmaz", "division_id": 1, "supervisor_id": null},
    {"id": 2, "name": "Mehmet Kaya", "division_id": 2, "supervisor_id": 1}
  ],
  "EnterpriseTask": [
    {"id": 1, "title": "Implement API", "division_id": 1, "assignees": [1, 2]}
  ]
}

🤝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Faker for realistic data generation
  • Click for CLI framework
  • Rich for beautiful terminal output
  • Pydantic for data validation

Türkçe Özet

MockDataGenerator, FastAPI (Pydantic), Django ve Flask (SQLAlchemy) modellerinden otomatik olarak ilişkisel mock veriler üreten güçlü bir Python kütüphanesidir. One-to-One, One-to-Many, Many-to-Many ve kendi kendine referanslı yapıları koruyarak JSON formatında veri üretir. CLI arayüzü ile kolay kullanım sağlar ve Türkçe dahil çeşitli dillerde lokalize veri desteği sunar.

Metadata

Release files for ars02bahadr-mock-data-generator 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ars02bahadr-mock-data-generator 0.1.0
File Size Uploaded Provenance Actions
ars02bahadr_mock_data_generator-0.1.0.tar.gz 14.2 kB Without provenance Details for ars02bahadr_mock_data_generator-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ars02bahadr-mock-data-generator 0.1.0
File Interpreter ABI Platform Actions
ars02bahadr_mock_data_generator-0.1.0-py3-none-any.whl Python 3 none any Details for ars02bahadr_mock_data_generator-0.1.0-py3-none-any.whl

Total release size: 32.4 kB

Release files / ars02bahadr_mock_data_generator-0.1.0.tar.gz

Download URL ars02bahadr_mock_data_generator-0.1.0.tar.gz
Size 14.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7836ef98fa4396d1aa65f020425fd016d2e9294f0c0030d4ad34bf7926df5d79
BLAKE2b-256 checksum
How to use checksums
d4aeb1ae6703d5e0a514c75297329a52ba6b292cd79506b3e84cb23d73ae4c40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.13

Release files / ars02bahadr_mock_data_generator-0.1.0-py3-none-any.whl

Download URL ars02bahadr_mock_data_generator-0.1.0-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ed8f09edc2a9641a9e95854fc86cbb20145efb891da7dbbb2d11440dce8c7f50
BLAKE2b-256 checksum
How to use checksums
757212a14cfe9d72c51ea0a199c148c6b9ce2bd3670720443dd6ba932312cba7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.13

Security for ars02bahadr-mock-data-generator 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page