Rand Engine v2. Package with some methods to generate random data in different formats. Great to mock data while testing or developing.
Project description
🎲 Rand Engine
Generate millions of rows of synthetic data in seconds
High-performance random data generation for testing, development, and prototyping
Quick Start • Features • Examples • Documentation • Benchmarks
🎯 What is Rand Engine?
Rand Engine is a Python library that generates realistic synthetic data at scale through simple declarative specifications. Built on NumPy and Pandas for maximum performance.
Perfect for:
- 🧪 Testing ETL/ELT pipelines without production data
- 📊 Load testing and stress testing data systems
- 🎓 Learning data engineering without complex setups
- 🚀 Prototyping applications with realistic datasets
- 🔐 Demos and POCs without exposing sensitive data
🚀 Quick Start
Installation
pip install rand-engine
Generate Your First Dataset (3 Lines!)
from rand_engine.main.data_generator import DataGenerator
from rand_engine.examples.common_rand_specs import CommonRandSpecs
# Generate 1 million customer records in seconds
df = DataGenerator(CommonRandSpecs.customers(), seed=42).size(1_000_000).get_df()
print(df.head())
Output:
customer_id age city total_spent is_premium registration_date
0 uuid-001 42 São Paulo 1523.50 True 2023-05-12
1 uuid-002 28 Rio de Janeiro 872.33 False 2024-01-08
2 uuid-003 56 Belo Horizonte 4215.89 False 2022-11-23
That's it! You just generated 1 million rows of realistic customer data. 🎉
✨ Key Features
🐼 Pandas DataFramesfrom rand_engine.main.data_generator import DataGenerator
df = DataGenerator(spec, seed=42).size(1_000_000).get_df()
✅ All methods (common + advanced) |
⚡ Spark DataFramesfrom rand_engine.main.spark_generator import SparkGenerator
df = SparkGenerator(spark, F, spec).size(100_000_000).get_df()
✅ Native Spark generation |
🎁 17+ Pre-Built RandSpecs
No configuration needed! Start generating data immediately:
| CommonRandSpecs (Work Everywhere) | AdvancedRandSpecs (Pandas Only) |
|---|---|
customers() products() orders() |
employees() devices() invoices() |
transactions() sensors() users() |
shipments() network_devices() vehicles() |
real_estate() healthcare() |
# Use any pre-built spec instantly
from rand_engine.examples.common_rand_specs import CommonRandSpecs
from rand_engine.examples.advanced_rand_specs import AdvancedRandSpecs
df_orders = DataGenerator(CommonRandSpecs.orders()).size(50_000).get_df()
df_employees = DataGenerator(AdvancedRandSpecs.employees()).size(1_000).get_df()
📝 Write to Files
# Write to CSV, Parquet, JSON with compression
DataGenerator(spec).size(1_000_000).write() \
.format("parquet") \
.compression("snappy") \
.mode("overwrite") \
.save("./data/customers")
🌊 Stream Data
# Simulate real-time data streams
DataGenerator(spec).stream() \
.throughput(min=1000, max=5000) \
.format("json") \
.start("./data/stream/events")
💡 Usage Examples
1️⃣ Local Development (Pandas)
from rand_engine.main.data_generator import DataGenerator
from rand_engine.examples.common_rand_specs import CommonRandSpecs
# Generate and explore
df = DataGenerator(CommonRandSpecs.transactions(), seed=42).size(100_000).get_df()
print(df.describe())
2️⃣ Databricks / Spark Environments
from rand_engine.main.spark_generator import SparkGenerator
from rand_engine.examples.common_rand_specs import CommonRandSpecs
from pyspark.sql import functions as F
# Generate Spark DataFrame with 100M rows
df_spark = SparkGenerator(spark, F, CommonRandSpecs.orders()).size(100_000_000).get_df()
# Write to Delta Lake
df_spark.write.format("delta").mode("overwrite").save("/path/to/delta/table")
3️⃣ Custom Specifications
# Define your own data structure
custom_spec = {
"user_id": {
"method": "unique_ids",
"kwargs": {"strategy": "uuid4"}
},
"age": {
"method": "integers",
"kwargs": {"min": 18, "max": 80}
},
"salary": {
"method": "floats",
"kwargs": {"min": 30000, "max": 150000, "round": 2}
}
}
df = DataGenerator(custom_spec).size(50_000).get_df()
📖 Learn more: BUILD_RAND_SPECS.md | 50+ Examples
📊 Performance Benchmarks
Real-world performance tests across different environments:
| Environment | Dataset | Rows | Time | Throughput |
|---|---|---|---|---|
| Local (Python 3.12) | Customers | 1M | 81.5s | ~12K rows/sec |
| Databricks (Standard) | Customers | 1M | 7.4s | ~135K rows/sec |
| Databricks (Spark) | Orders | 100M | 19.4s | ~5.1M rows/sec |
| Databricks (Custom) | Custom Spec | 100M | 19.4s | ~5.1M rows/sec |
💡 Tip: Spark generation scales linearly with cluster size for massive datasets (100M+ rows).
🔑 Advanced Features
🔗 Constraints System - Referential Integrity
Generate multiple related tables with Primary Keys (PK) and Foreign Keys (FK):
from rand_engine.main.data_generator import DataGenerator
# Define specs with constraints
customers_spec = {
"customer_id": {"method": "unique_ids", "kwargs": {"strategy": "sequence"}},
"name": {"method": "distincts", "kwargs": {"distincts": ["Alice", "Bob", "Charlie"]}},
"constraints": {
"pk_customer": {"tipo": "PK", "fields": ["customer_id"]}
}
}
orders_spec = {
"order_id": {"method": "unique_ids", "kwargs": {"strategy": "sequence"}},
"customer_id": {"method": "integers", "kwargs": {"min": 1, "max": 1000}},
"amount": {"method": "floats", "kwargs": {"min": 10, "max": 1000, "round": 2}},
"constraints": {
"fk_customer": {
"tipo": "FK",
"fields": ["customer_id"],
"references": {"spec_name": "customers", "pk_name": "pk_customer"}
}
}
}
# Generate with referential integrity
generator = DataGenerator({"customers": customers_spec, "orders": orders_spec})
dfs = generator.size({"customers": 1000, "orders": 5000}).get_dfs()
📖 Complete guide: CONSTRAINTS.md
🎨 Advanced Methods - Correlated Data
Generate correlated columns for realistic patterns:
# Currency-Country correlations
orders_spec = {
"order_id": {"method": "unique_ids", "kwargs": {"strategy": "sequence"}},
"currency_country": {
"method": "distincts_map", # Correlated pairs
"splitable": True,
"cols": ["currency", "country"],
"sep": ";",
"kwargs": {"distincts": ["USD;US", "EUR;DE", "BRL;BR", "JPY;JP"]}
}
}
df = DataGenerator(orders_spec).size(10_000).get_df()
# Result: USD always paired with US, EUR with DE, etc.
Available Advanced Methods:
distincts_map- Correlated pairs (currency ↔ country)distincts_multi_map- Hierarchical combinations (dept → level → role)distincts_map_prop- Weighted correlated pairscomplex_distincts- Pattern-based strings (IPs, SKUs, URLs)
📖 Complete guide: BUILD_RAND_SPECS.md
💡 Quick Tips
🎯 For Data Engineers
|
🧪 For QA Engineers
|
📚 Documentation
| Document | Description |
|---|---|
| BUILD_RAND_SPECS.md | Complete guide to building custom specifications |
| EXAMPLES.md | 50+ production-ready examples |
| CONSTRAINTS.md | PK/FK system and referential integrity |
| API_REFERENCE.md | Full method reference |
| LOGGING.md | Logging configuration |
🧪 Testing
494 tests passing with comprehensive coverage:
pytest # Run all tests
pytest tests/test_2_data_generator.py -v # Test DataGenerator
pytest tests/test_3_spark_generator.py -v # Test SparkGenerator
pytest tests/test_8_consistency.py -v # Test constraints
📦 Requirements
- Python >= 3.10
- numpy >= 2.1.1
- pandas >= 2.2.2
- faker >= 28.4.1 (optional)
- duckdb >= 1.1.0 (optional)
🤝 Contributing
Contributions are welcome! Feel free to:
- 🐛 Report bugs via Issues
- 💡 Suggest features via Discussions
- 🔧 Submit pull requests
📞 Support
- GitHub Issues: Report bugs
- GitHub Discussions: Ask questions
- Email: marcourelioreislima@gmail.com
📄 License
MIT License - see LICENSE for details.
🌟 Star the project if you find it useful!
Built with ❤️ for Data Engineers and the data community
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 rand_engine-0.6.3.tar.gz.
File metadata
- Download URL: rand_engine-0.6.3.tar.gz
- Upload date:
- Size: 39.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bba903241f48a158e56df10846bb36a5deb23822bc6e1506e0f2fcd6ab0a2d68
|
|
| MD5 |
0e2d41808211ce3a2eaad21e4b198ebd
|
|
| BLAKE2b-256 |
f6e2acb620a0350eafd6cdc49b5b40f6af3b92de0b64cdd6a6fec8589519d46b
|
Provenance
The following attestation bundles were made for rand_engine-0.6.3.tar.gz:
Publisher:
auto_tag_publish_master.yml on marcoaureliomenezes/rand_engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rand_engine-0.6.3.tar.gz -
Subject digest:
bba903241f48a158e56df10846bb36a5deb23822bc6e1506e0f2fcd6ab0a2d68 - Sigstore transparency entry: 660057765
- Sigstore integration time:
-
Permalink:
marcoaureliomenezes/rand_engine@d6b3eec5ac35d5c925bb58a080ea360935db2461 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/marcoaureliomenezes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
auto_tag_publish_master.yml@d6b3eec5ac35d5c925bb58a080ea360935db2461 -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file rand_engine-0.6.3-py3-none-any.whl.
File metadata
- Download URL: rand_engine-0.6.3-py3-none-any.whl
- Upload date:
- Size: 50.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
594127164383116dadf7d6f8f96872bc999cc8a197d24d665655a6fd84f8a4fc
|
|
| MD5 |
15ea36fe409439d4557e9c3fe408b04a
|
|
| BLAKE2b-256 |
a86ee8d285f49c7ceb5b9d3179cae6c7aade5284442e54114633e5e4182bd713
|
Provenance
The following attestation bundles were made for rand_engine-0.6.3-py3-none-any.whl:
Publisher:
auto_tag_publish_master.yml on marcoaureliomenezes/rand_engine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rand_engine-0.6.3-py3-none-any.whl -
Subject digest:
594127164383116dadf7d6f8f96872bc999cc8a197d24d665655a6fd84f8a4fc - Sigstore transparency entry: 660057772
- Sigstore integration time:
-
Permalink:
marcoaureliomenezes/rand_engine@d6b3eec5ac35d5c925bb58a080ea360935db2461 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/marcoaureliomenezes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
auto_tag_publish_master.yml@d6b3eec5ac35d5c925bb58a080ea360935db2461 -
Trigger Event:
pull_request
-
Statement type: