Skip to main content

A simple helper for generating DataFrames filled with fake data with the help of Faker.

Project description

DataFrame Faker

CI badge PyPI - Version PyPI - Python Version

What

A simple helper for generating PySpark DataFrames filled with fake data with the help of Faker.

Why

This tool is built to allow quickly generating fake data for development of data pipelines etc. in situations where you don't have example data in your development environment and you don't want to work in production when iterating on your code.

How

import datetime

from pyspark.sql import SparkSession

from dataframe_faker import (
    FloatConstraint,
    StringConstraint,
    StructConstraint,
    TimestampConstraint,
    generate_fake_dataframe,
)

spark = (
    SparkSession.builder.appName("dataframe-faker-example")
    .config("spark.sql.session.timeZone", "UTC")
    .master("local[4]")
    .getOrCreate()
)

schema_str = """
machine_id: int,
uuid: string,
json_message: struct<
    measurement: float,
    dt: timestamp
>
"""
df = generate_fake_dataframe(
    schema=schema_str,
    constraints={
        "uuid": StringConstraint(string_type="uuid4"),
        "json_message": StructConstraint(
            element_constraints={
                "measurement": FloatConstraint(min_value=25.0, max_value=100.0),
                "dt": TimestampConstraint(
                    min_value=datetime.datetime.fromisoformat(
                        "2025-01-01T00:00:00.000Z"
                    ),
                    max_value=datetime.datetime.fromisoformat(
                        "2025-01-31T23:59:59.999Z"
                    ),
                ),
            }
        ),
    },
    rows=5,
    spark=spark,
)

print(df)
# DataFrame[machine_id: int, uuid: string, json_message: struct<measurement:float,dt:timestamp>]

df.show(truncate=False)
# +----------+------------------------------------+---------------------------------------+
# |machine_id|uuid                                |json_message                           |
# +----------+------------------------------------+---------------------------------------+
# |36        |709e3210-896e-4337-9a8b-7fe2969d99a1|{53.12909, 2025-01-23 21:57:47.177554} |
# |98        |7c80c8e7-de0a-46fd-9bb4-61ce72c541e8|{52.056786, 2025-01-08 21:24:30.353171}|
# |31        |43585e16-8fd4-4e8f-b474-646b6a9678ff|{92.424286, 2025-01-02 21:55:08.503093}|
# |0         |2f00aee0-c7b4-4125-933a-55b87f55f156|{80.54238, 2025-01-10 06:57:59.352183} |
# |65        |531df313-e9b3-4f53-89cc-f95adcab94d4|{94.593094, 2025-01-07 03:56:48.097414}|
# +----------+------------------------------------+---------------------------------------+

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

dataframe_faker-0.1.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

dataframe_faker-0.1.1-py3-none-any.whl (6.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dataframe_faker-0.1.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.3

File hashes

Hashes for dataframe_faker-0.1.1.tar.gz
Algorithm Hash digest
SHA256 66662244fed81ebb16df22aa9e5a7a633bdf7489df1ec355e8239126038815e2
MD5 c23c01b536799c62142e3bf4a505f60f
BLAKE2b-256 88353c82fe6c366e76eece201343f0c8588155c159e48e8019cfef943ca4c3da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for dataframe_faker-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 47a577c4a6dcb5c98089ca40d6adb87daf0287a27632e33b5521e1f32efeed7f
MD5 bfe1269e83fc56e22fb15b68c7906eb2
BLAKE2b-256 afef53e5c8a6dc2eaa106ff8109c8d6fcea53df664858003e1c0d55101e85726

See more details on using hashes here.

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