Skip to main content

Deterministic test DataFrame builder with optional PySpark export

Project description

dfgenerator

Lightweight helpers to build deterministic test datasets for Pandas and PySpark, with Faker-powered generators, YAML-based reusable configs, and JSON Schema support.

Features

  • 🎲 Deterministic data generation with seed support for reproducible tests
  • 📊 Multiple input formats: YAML configs, JSON Schema, Spark/Iceberg DataFrames, or programmatic Python API
  • 🌍 Multi-locale support with Faker integration (50+ locales)
  • 🔗 Relational data with primary/foreign key support for joinable datasets
  • 📤 Multiple export formats: CSV, JSON, Pandas DataFrame, PySpark DataFrame
  • 🎯 Smart inference from JSON Schema formats, property names, and existing Spark DataFrames
  • Spark/Iceberg support - Generate test data from production schemas
  • 🚀 CLI and Python API for flexible usage

Quick Start

From Spark/Iceberg DataFrame

from pyspark.sql import SparkSession
from dfgenerator import build_from_spark

# Load production Iceberg table
spark = SparkSession.builder.getOrCreate()
prod_df = spark.read.format("iceberg").load("prod.users")

# Generate test data with same schema
test_data = build_from_spark(prod_df, rows=100, seed=42)

# Export for testing
test_data.to_file("test_users.csv")
test_df = test_data.to_spark(spark)

From JSON Schema

# Generate data from a JSON Schema file
dfgenerator --schema user.schema.json --rows 100 --seed 42 --output users.csv
from dfgenerator import build_from_jsonschema

schema = {
    "type": "object",
    "properties": {
        "id": {"type": "integer"},
        "email": {"type": "string", "format": "email"},
        "age": {"type": "integer", "minimum": 18, "maximum": 65}
    }
}

dataset = build_from_jsonschema(schema, rows=100, seed=42)
dataset.to_file("users.csv")

From YAML Config

dfgenerator --config people.yaml --rows 50 --output people.json

Programmatic API

from dfgenerator import DataFrameBuilder, RowTemplate, ColumnSpec, sequence, choices

template = RowTemplate([
    ColumnSpec("id", sequence(1)),
    ColumnSpec("city", choices(["Paris", "Berlin", "Boston"])),
])

dataset = DataFrameBuilder().from_template(template, 10).build()
df = dataset.to_pandas()

Architecture

dfgenerator uses a lightweight adapter pattern for extensibility:

  • Core Domain: Pure business logic for data generation
  • Input Adapters: YAML, JSON Schema, Spark DataFrames (easily extensible!)
  • Output Adapters: CSV, JSON, Pandas, PySpark

Want to add support for Protobuf, Avro, or GraphQL schemas? Just create a new adapter!

See docs/ARCHITECTURE.md for details.

Documentation

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

dfgenerator-0.1.1.tar.gz (19.7 kB view details)

Uploaded Source

Built Distribution

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

dfgenerator-0.1.1-py3-none-any.whl (28.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dfgenerator-0.1.1.tar.gz
  • Upload date:
  • Size: 19.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dfgenerator-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3154e4bb1aee36194145c7e108f29c6c334485c0c3f7fc8bfa97ed1349ef515a
MD5 83ea4c370e728b510020e9f342beb61b
BLAKE2b-256 1b39000dfd03efea0fec687ee2b291d5690aad699659b08db5cdfe0180c32fc5

See more details on using hashes here.

Provenance

The following attestation bundles were made for dfgenerator-0.1.1.tar.gz:

Publisher: deploy.yml on cdahirel/dfgenerator

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

File details

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

File metadata

  • Download URL: dfgenerator-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 28.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dfgenerator-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d0fcc05379b381c55d57ddaa49359be8db6b11083a3f7f428a8223f3e3fa584e
MD5 42b8693b0ccff794465dd01c620f9d5e
BLAKE2b-256 f5972013af200cf4b521fa48c7027d59106e851e9b2a0417a8a87a0b51108b17

See more details on using hashes here.

Provenance

The following attestation bundles were made for dfgenerator-0.1.1-py3-none-any.whl:

Publisher: deploy.yml on cdahirel/dfgenerator

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