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
VARCHARlength 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:
UNIQUEconstraint 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15e1367c7bc2735e53829313cec6fa3c9d9cba9272b138a9a77d125d77bad240
|
|
| MD5 |
51324e6e8585055e288169e12a4fdb87
|
|
| BLAKE2b-256 |
4e3c3173df4e0a798be83cdc19933193ca460b9fef784fd20515e772c45d28e1
|
File details
Details for the file mockforge_engine-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mockforge_engine-0.1.1-py3-none-any.whl
- Upload date:
- Size: 8.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
17326b7625fcfdb815858f9c834691fa2312824f891e800171480a5e139f6ba5
|
|
| MD5 |
661ebb022886efaf5b74c74c653e6440
|
|
| BLAKE2b-256 |
b0bf64c2088be31d26674735cdbbc00589e51a152770acfc0f0518f0a61fbf74
|