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.0.tar.gz (19.6 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.0-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dfgenerator-0.1.0.tar.gz
  • Upload date:
  • Size: 19.6 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.0.tar.gz
Algorithm Hash digest
SHA256 bf80b3a6bff4ed2289e0b36ab0483a5a55b343ca10062ff1d2ebcca9fda8660d
MD5 f3e78a8a0b076d0e2368a7e9ba9ddc4b
BLAKE2b-256 af4aa3423e513c4482e9a4b17cc85d54fbc3aeac0635f6cafefb107fab9d83e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for dfgenerator-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: dfgenerator-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 28.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa6fa74dfa9cea6da01cebf704b0936ff726bab501c675c798e5cde9ddadc20a
MD5 73122e8a6a22103dec3caff5b022af85
BLAKE2b-256 dba2887cee3525c9c4ea1ab804b2b285eb484d30bfd5823ed1e610d83dc71bff

See more details on using hashes here.

Provenance

The following attestation bundles were made for dfgenerator-0.1.0-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