Skip to main content

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

Python Tests License Version PyPI

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 DataFrames

from rand_engine.main.data_generator import DataGenerator

df = DataGenerator(spec, seed=42).size(1_000_000).get_df()

โœ… All methods (common + advanced)
โœ… Correlated columns
โœ… Complex patterns
โœ… PK/FK constraints

โšก Spark DataFrames

from rand_engine.main.spark_generator import SparkGenerator

df = SparkGenerator(spark, F, spec).size(100_000_000).get_df()

โœ… Native Spark generation
โœ… Databricks ready
โœ… Distributed at scale
โš ๏ธ Common methods only

๐ŸŽ 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") \
    .mode("overwrite") \
    .option("compression", "snappy") \
    .save("./data/customers")

๐Ÿ“– Complete guide: 3_WRITING_FILES.md

๐ŸŒŠ Stream Data

# Simulate real-time data streams
DataGenerator(spec).size(100).writeStream \
    .format("json") \
    .mode("overwrite") \
    .trigger(5) \
    .option("timeout", 60) \
    .start("./data/stream/events")

๐Ÿ“– Complete guide: 3_WRITING_FILES.md


๐Ÿ’ก 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: DataGenerator Guide | SparkGenerator Guide | 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: 4_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 pairs
  • complex_distincts - Pattern-based strings (IPs, SKUs, URLs)

๐Ÿ“– Complete guide: 1_DATA_GENERATOR.md | BUILD_RAND_SPECS.md


๐Ÿ’ก Quick Tips

๐ŸŽฏ For Data Engineers

  • Use seed for reproducible tests
  • Export to Parquet for large datasets
  • Use constraints for multi-table integrity
  • Stream mode for real-time testing

๐Ÿงช For QA Engineers

  • Start with pre-built specs
  • Generate edge cases with probabilities
  • Multiple seeds = multiple test scenarios
  • Test PK/FK relationships

๐Ÿ“š Documentation

Core Documentation

Document Description
1_DATA_GENERATOR.md Pandas-based data generation with all features
2_SPARK_GENERATOR.md Spark DataFrame generation at scale
3_WRITING_FILES.md Batch and streaming file writers
4_CONSTRAINTS.md PK/FK constraints with automatic cleanup

Additional Resources

Document Description
BUILD_RAND_SPECS.md Complete guide to building custom specifications
EXAMPLES.md 50+ production-ready examples
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


๐Ÿ“„ License

MIT License - see LICENSE for details.


๐ŸŒŸ Star the project if you find it useful!

Star History Chart

Built with โค๏ธ for Data Engineers and the data community

โฌ† Back to top

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

rand_engine-0.6.4.tar.gz (40.1 kB view details)

Uploaded Source

Built Distribution

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

rand_engine-0.6.4-py3-none-any.whl (50.9 kB view details)

Uploaded Python 3

File details

Details for the file rand_engine-0.6.4.tar.gz.

File metadata

  • Download URL: rand_engine-0.6.4.tar.gz
  • Upload date:
  • Size: 40.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rand_engine-0.6.4.tar.gz
Algorithm Hash digest
SHA256 7cef1b7090647937f3896380be96fe42be7a1ee37c9224ab0f85135bf821d8be
MD5 3bfef812c6a7a147d402619f6be200f9
BLAKE2b-256 ddab23f95db0a70700ea75fd04c27b2dc5df752156696f3295712cba24e2bd52

See more details on using hashes here.

Provenance

The following attestation bundles were made for rand_engine-0.6.4.tar.gz:

Publisher: auto_tag_publish_master.yml on marcoaureliomenezes/rand_engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rand_engine-0.6.4-py3-none-any.whl.

File metadata

  • Download URL: rand_engine-0.6.4-py3-none-any.whl
  • Upload date:
  • Size: 50.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rand_engine-0.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 07aec4e45ca9c12a8becffff879c6acb90cc9a537c1977040e227eb2365cb8dc
MD5 e7dac6e8d1fa810b0974eff6355332f0
BLAKE2b-256 df3a5fdce61db8a2fd13ebcc41d4d3a9aa71a42718cbdd7617ce7213e94698db

See more details on using hashes here.

Provenance

The following attestation bundles were made for rand_engine-0.6.4-py3-none-any.whl:

Publisher: auto_tag_publish_master.yml on marcoaureliomenezes/rand_engine

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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