Skip to main content

Helpers for generating demo data

Project description

data-generator-utils

Utility functions for generating synthetic retail sales data and creating valid table names for use in databases and analytics tools.

Installation

pip install data-generator-utils

Requirements

  • Python 3.9+
  • numpy
  • pandas (for the holiday calendar utilities)

These are installed automatically when you install the package.

Usage

1. Generate synthetic sales data

The generate_sales_data function returns a list of dictionaries, each representing a row of simulated sales data.

from data_generator import generate_sales_data

records = generate_sales_data(
n_rows=10_000, # number of rows to generate
base_demand=1000, # upper bound for demand
day_range=100, # how many days back from now to sample
seed=123456789 # RNG seed for reproducibility
)

Output schema

Each record has the following fields:

  • row_id: Random UUID string.
  • date: Calendar date (Python date) within the last day_range days.
  • average_temperature: Random float between 0 and 35 (degrees, arbitrary units).
  • rainfall: Random float from an exponential distribution with mean ≈ 5.
  • weekend: Boolean flag indicating whether date falls on Saturday or Sunday.
  • holiday: Boolean flag indicating whether date is a US federal holiday (via USFederalHolidayCalendar).
  • price_per_kg: Random float between 0.5 and 3.0.
  • demand: Random float between 1 and base_demand.
  • month: Integer month extracted from date.
  • total_spend: demand * price_per_kg, rounded to 2 decimal places.

2. Generate valid table names

The to_valid_table_name function converts an arbitrary string into a safe, normalized table name.

from data_generator import to_valid_table_name

raw = "2024 Sales Report (US-West)"
safe = to_valid_table_name(raw)

print(safe) # e.g. "t_2024_sales_report_us_west"

Rules applied

  • Converts the input to lowercase.
  • Replaces any character not in a–z, 0–9, or _ with _.
  • Collapses multiple underscores into a single underscore.
  • Ensures the name is non-empty; falls back to "t" if needed.
  • Ensures the name does not start with a digit; prefixes with "t_" if it does.
  • Truncates to max_length characters (default 128).
  • Strips leading/trailing underscores; if stripping empties the name, falls back to "t" again.

Development

  • Format code with your preferred formatter (e.g., black).
  • Run tests (if added) before publishing a new version.
  • When updating behavior of public functions, bump the package version accordingly.

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

data_generator_utils-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

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

data_generator_utils-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: data_generator_utils-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for data_generator_utils-0.1.0.tar.gz
Algorithm Hash digest
SHA256 71812a3b6134f526845249bed977961d9ca1439bd9d07bb88623c273f8bed195
MD5 97152b548cadb2bdd71f39743887a8e1
BLAKE2b-256 2e61065fcf19a42346f479deccca2342957a1fdf6369de58823f28911dba11eb

See more details on using hashes here.

File details

Details for the file data_generator_utils-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for data_generator_utils-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e80f7faf1a3a3190c116265de8c67c7def13222f59f184175dccb35139980ac6
MD5 f5f6c0237cb895a193e7f70093b2e244
BLAKE2b-256 ca9d2e4ca3fa3a600e0777b0059ed2fa8767ce84231bc1073777f235c8660fc0

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