Skip to main content

An O(1) memory-safe synthetic data generator and database seeder

Project description

MockForge Engine

O(1) memory-safe synthetic data generator and intelligent database seeder for Python.

MockForge Engine enables Data Engineers and Backend Developers to generate and stream millions of structurally accurate synthetic records directly into SQL databases without exhausting memory or writing boilerplate insertion logic.

Built with database introspection and fault-tolerant insertion strategies, MockForge automatically validates schemas, guards against constraint violations, and isolates bad records through a Dead Letter Queue (DLQ).


โœจ Features

๐Ÿš€ O(1) Memory Footprint

Generate and insert millions of records using Python generators (yield) without loading datasets into memory.

  • Stream 10M+ rows on commodity hardware
  • No intermediate files
  • No Out-Of-Memory crashes

๐Ÿง  Intelligent Pre-Flight Validation

Uses SQLAlchemy reflection to inspect target database schemas before inserting data.

  • Validates column existence
  • Checks datatype compatibility
  • Prevents runtime deployment failures

๐Ÿ›ก๏ธ Auto-Truncation Guardrails

Automatically detects database column limits and safely truncates generated strings in-memory.

  • Supports VARCHAR length detection
  • Prevents SQL overflow exceptions
  • Eliminates manual sanitization logic

โšก Fault-Tolerant Batch Insertion

Batch inserts are wrapped in nested SQL savepoints.

If a batch fails due to:

  • UNIQUE constraint violations
  • Duplicate primary keys
  • Invalid records

MockForge automatically degrades to row-by-row insertion, quarantines the bad records, and inserts the remaining valid data.


๐Ÿ“ฆ Dead Letter Queue (DLQ)

Failed records are automatically written to JSON for later inspection.

failed_rows.json

This enables:

  • Error auditing
  • Data quality debugging
  • Replay of failed records

๐ŸŒณ Deeply Nested Schema Support

Generate realistic data structures including:

  • Nested objects
  • Arrays
  • Enums
  • Regex-generated strings
  • Recursive JSON documents

๐Ÿ“ฆ Installation

pip install mockforge-engine

Requirements

  • Python 3.10+
  • SQLAlchemy 2.0+

โšก Quick Start

Define a Schema

schema = {
    "full_name": {"type": "name"},
    "role": {
        "type": "enum",
        "choices": ["Admin", "User", "Guest"]
    },
    "email": {"type": "email"},
    "age": {
        "type": "integer",
        "min": 18,
        "max": 99
    }
}

Generate and Stream Data

from mockforge import (
    DataEngine,
    DatabaseSeeder,
    SchemaMismatchError
)

try:
    engine = DataEngine(schema=schema)

    data_stream = engine.stream(count=50000)

    seeder = DatabaseSeeder(
        db_url="sqlite:///dev_database.db"
    )

    inserted = seeder.insert_stream(
        table_name="users",
        schema=schema,
        data_stream=data_stream,
        batch_size=10000
    )

    print(f"Inserted {inserted} records.")

except SchemaMismatchError as e:
    print(f"Pre-flight validation failed: {e}")

๐Ÿ›ก๏ธ Execution Modes

Best-Effort Mode (Default)

Continues inserting valid records even when some rows fail.

seeder.insert_stream(
    table_name="users",
    schema=schema,
    data_stream=data_stream,
    strict_mode=False,
    dlq_file="failed_rows.json"
)

Behavior

Batch Insert
      โ†“
Constraint Error
      โ†“
Row-by-Row Retry
      โ†“
Good Rows โ†’ Database
Bad Rows  โ†’ DLQ JSON

Strict Mode (All-or-Nothing)

Rolls back the entire transaction if a single row violates a constraint.

seeder.insert_stream(
    table_name="users",
    schema=schema,
    data_stream=data_stream,
    strict_mode=True
)

Ideal for:

  • CI/CD pipelines
  • Integration testing
  • Deterministic environments

๐Ÿ“– Schema Definition

Primitive Types

{
    "first_name": "name",
    "age": {
        "type": "integer",
        "min": 18,
        "max": 65
    },
    "is_active": "boolean"
}

Nested Objects

{
    "company_details": {
        "type": "object",
        "schema": {
            "company_name": "string",
            "established_date": "date"
        }
    }
}

Arrays

{
    "tags": {
        "type": "array",
        "size": [1, 5],
        "items": {
            "type": "string"
        }
    }
}

Regex-Based Generation

{
    "product_sku": {
        "type": "string",
        "regex": "^[A-Z]{3}-[0-9]{4}$"
    }
}

Example output:

ABC-4821
XYZ-1930
KLM-8891

๐Ÿ—๏ธ Architecture

JSON Schema
      โ†“
 DataEngine
      โ†“
 Generator Stream (yield)
      โ†“
 Batch Processor
      โ†“
 Database Reflection
      โ†“
 Transaction Manager
      โ†“
 โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
 โ”‚                             โ”‚
Success                     Failure
 โ”‚                             โ”‚
Database                  Dead Letter Queue

๐Ÿ”ง Built With

  • Faker
  • SQLAlchemy
  • rstr
  • Python Generators
  • SQL Savepoints & Nested Transactions

๐ŸŽฏ Use Cases

  • Database benchmarking
  • Integration testing
  • Local development environments
  • Data engineering pipelines
  • Performance testing
  • Synthetic data generation at scale

๐Ÿ“ˆ Why MockForge?

Feature MockForge Traditional Seed Scripts
O(1) Memory Usage โœ… โŒ
Streaming Inserts โœ… โŒ
Database Reflection โœ… โŒ
DLQ Support โœ… โŒ
Constraint Recovery โœ… โŒ
Nested Schema Generation โœ… Limited

๐Ÿ“„ License

MIT License

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

mockforge_engine-0.1.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

mockforge_engine-0.1.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file mockforge_engine-0.1.1.tar.gz.

File metadata

  • Download URL: mockforge_engine-0.1.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for mockforge_engine-0.1.1.tar.gz
Algorithm Hash digest
SHA256 15e1367c7bc2735e53829313cec6fa3c9d9cba9272b138a9a77d125d77bad240
MD5 51324e6e8585055e288169e12a4fdb87
BLAKE2b-256 4e3c3173df4e0a798be83cdc19933193ca460b9fef784fd20515e772c45d28e1

See more details on using hashes here.

File details

Details for the file mockforge_engine-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mockforge_engine-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 17326b7625fcfdb815858f9c834691fa2312824f891e800171480a5e139f6ba5
MD5 661ebb022886efaf5b74c74c653e6440
BLAKE2b-256 b0bf64c2088be31d26674735cdbbc00589e51a152770acfc0f0518f0a61fbf74

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