Skip to main content

A data mocker for python scripts and jupyter notebooks

Project description

Pydatamocker

Create rich mock data for testing, learning and proofs of concepts!

About

Pydatamocker can generate tabular data of various data types and distributions using random generation and sampling. It is also possible to create a lookups from one table to another. Sampling is very fast even when generating 1'000'000s of records with ~10 fields. The tables are presented in the form of pandas DataFrames.

The API for writing the tables to files is easy to use. Just specify the file path and the formatting is inferred from the file extension, be it csv, tsv, json or a simple text file.

Datasets

Some datasets are included with the package. They can be sampled for fields. Datasets included are:

  • ~ 20'000 names of various origins
  • ~ 20'000 surnames of various origins

Get started

Production

Install the prod version by running

python3 -m pip install pydatamocker

Testing

Install the latest testing version by running

python3 -m pip install --index-url https://test.pypi.org/simple/ pydatamocker

Code example

You can generate mock tables with

# Create data table
acc = MockTable('Accounts')
# Create an integer field with binomial(10, 0.4) distribution
acc.add_field('YearsOfExperience', 'integer', distr='binomial', n=10, p=0.4)
# Field with real randomized first names
acc.add_field('FirstName', 'first_name')
# Field with real randomized surnames
acc.add_field('LastName', 'last_name')
# Date field
acc.add_field('DateHired', 'date', distr='uniform', start='2016-10-25', end='2020-02-10')
# Integer field
acc.add_field('Id', 'integer', distr='range', start=100000, end=90000000)

# Create sample
acc.sample(100_000)

# Create another table
audit = MockTable('Audits')
# Add a lookup
audit.add_lookup(acc, ['Id'])
# Add an enum field
audit.add_field('Subject', 'enum', values=['PPI Access', 'Administrative Reconfiguration', 'Phone contact'], weights=[5, 1, 2])
audit.add_field('ContactedAt', 'datetime', distr='range', start='2016-10-25', end='2019-03-15')

audit.sample(1_000_000)

# Get pandas dataframe
acc_df = acc.get_dataframe()
audit_df = audit.get_dataframe()

# Dump into csv (other formats also supported)
acc.dump('accounts.csv')
audit.dump('audits.csv')

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

pydatamocker-1.0.0.tar.gz (156.6 kB view details)

Uploaded Source

Built Distribution

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

pydatamocker-1.0.0-py3-none-any.whl (159.5 kB view details)

Uploaded Python 3

File details

Details for the file pydatamocker-1.0.0.tar.gz.

File metadata

  • Download URL: pydatamocker-1.0.0.tar.gz
  • Upload date:
  • Size: 156.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for pydatamocker-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d6e7af2d2aab966364cdae02bff7859de22205d844e248c959ae80d726b6348d
MD5 9ef9873f9bb77310ab5a8793ff787aa9
BLAKE2b-256 de592be598c61d02cfacd20fc8d3001bee4af82338c8da2752fd02882a640f0f

See more details on using hashes here.

File details

Details for the file pydatamocker-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pydatamocker-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 159.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.5

File hashes

Hashes for pydatamocker-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3d2ccf72f00a3eb9827411732aef45f963747d5fb7d2fa855c838944b06e2ded
MD5 e95394a319f29017fb1be7dafb397def
BLAKE2b-256 defef0510297177ad2b72e482b11df1017ee1fbd74646b338d4d9084fec37b22

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