Skip to main content

Mock data generator for Django, SQLAlchemy, and Pydantic models

Project description

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.

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

ars02bahadr_mock_data_generator-0.1.0.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

ars02bahadr_mock_data_generator-0.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file ars02bahadr_mock_data_generator-0.1.0.tar.gz.

File metadata

File hashes

Hashes for ars02bahadr_mock_data_generator-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7836ef98fa4396d1aa65f020425fd016d2e9294f0c0030d4ad34bf7926df5d79
MD5 914d67895a9b0b1dac8f10acc12816e5
BLAKE2b-256 d4aeb1ae6703d5e0a514c75297329a52ba6b292cd79506b3e84cb23d73ae4c40

See more details on using hashes here.

File details

Details for the file ars02bahadr_mock_data_generator-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ars02bahadr_mock_data_generator-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ed8f09edc2a9641a9e95854fc86cbb20145efb891da7dbbb2d11440dce8c7f50
MD5 0f71f5514fe1b8b573f048c860e0da88
BLAKE2b-256 757212a14cfe9d72c51ea0a199c148c6b9ce2bd3670720443dd6ba932312cba7

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