Skip to main content

tblfaker is a Python library to generate fake tabular data.

Project description

Summary

tblfaker is a Python library to generate fake tabular data.

PyPI package version Supported Python versions Linux/macOS CI status Windows CI status Test coverage

Usage

Basic Usage

Generate tabular data at random

Sample Code:
from tblfaker import TableFaker

faker = TableFaker()

print("[1]")
for row in faker.generate(["name", "address"], rows=4).as_tuple():
    print(row)

print("\n[2]")
for row in faker.generate(["name", "address"], rows=4).as_tuple():
    print(row)
Output:
[1]
Row(name='Jonathan Hendrix', address='368 Melanie Inlet Suite 890\nLake Stephanie, MT 17441')
Row(name='Kristina Simmons', address='3867 Perry Alley Suite 957\nLindafurt, FL 12507')
Row(name='Rebecca Velasquez', address='107 Karla Forges Apt. 925\nEast Jonathan, NC 85462')
Row(name='Jordan Morris', address='6341 Jessica Walks\nReynoldsshire, MD 05131')

[2]
Row(name='Caitlin Bush', address='87380 Barbara Haven Suite 042\nHutchinsonburgh, IA 39544')
Row(name='Jennifer King', address='39729 Gray Inlet Apt. 693\nPort Peter, AL 80733')
Row(name='Stephanie Smith', address='256 Emily Street\nCooperhaven, MS 70299')
Row(name='Nicholas Miller', address='59845 Daniel Ford Suite 729\nDamontown, UT 19811

Reproduce same tabular data

Fake tabular data can reproduce by passing the same seed value to TableFaker constructor.

Sample Code:
from tblfaker import TableFaker

seed = 1

print("[1]")
faker = TableFaker(seed=seed)
for row in faker.generate(["name", "address"], rows=4).as_tuple():
    print(row)

print("\n[2]")
faker = TableFaker(seed=seed)
for row in faker.generate(["name", "address"], rows=4).as_tuple():
    print(row)
Output:
[1]
Row(name='Ryan Gallagher', address='6317 Mary Light\nSmithview, HI 13900')
Row(name='Amanda Johnson', address='3608 Samuel Mews Apt. 337\nHousebury, WA 13608')
Row(name='Willie Heath', address='868 Santiago Grove\nNicolehaven, NJ 05026')
Row(name='Dr. Jared Ortega', address='517 Rodriguez Divide Suite 570\nWest Melinda, NH 85325')

[2]
Row(name='Ryan Gallagher', address='6317 Mary Light\nSmithview, HI 13900')
Row(name='Amanda Johnson', address='3608 Samuel Mews Apt. 337\nHousebury, WA 13608')
Row(name='Willie Heath', address='868 Santiago Grove\nNicolehaven, NJ 05026')
Row(name='Dr. Jared Ortega', address='517 Rodriguez Divide Suite 570\nWest Melinda, NH 85325')

Set locale for fake data

Sample Code:
from tblfaker import TableFaker

faker = TableFaker(locale="ja_JP")

for row in faker.generate(["name", "address"], rows=4).as_tuple():
    print(row)
Output:
Row(name='工藤 健一', address='宮崎県武蔵村山市六番町19丁目15番11号')
Row(name='井上 聡太郎', address='愛媛県長生郡白子町豊町33丁目7番20号 戸島コート620')
Row(name='大垣 美加子', address='京都府山武郡芝山町三ノ輪34丁目15番8号 クレスト所野560')
Row(name='宇野 くみ子', address='宮城県八街市西浅草20丁目24番6号')

Generate data in other data formats

Generate data in dict

Sample Code:
from tblfaker import TableFaker
import json

faker = TableFaker(seed=1)

print(json.dumps(faker.generate(["name", "address"], rows=2, table_name="dict").as_dict(), indent=4))
Output:
{
    "dict": [
        {
            "name": "Ryan Gallagher",
            "address": "6317 Mary Light\nSmithview, HI 13900"
        },
        {
            "name": "Amanda Johnson",
            "address": "3608 Samuel Mews Apt. 337\nHousebury, WA 13608"
        }
    ]
}

Generate data in pandas.DataFrame

Sample Code:
from tblfaker import TableFaker

faker = TableFaker(seed=seed)

print(faker.generate(["name", "address"], rows=4).as_dataframe())
Output:
               name                                            address
0    Ryan Gallagher               6317 Mary Light\nSmithview, HI 13900
1    Amanda Johnson     3608 Samuel Mews Apt. 337\nHousebury, WA 13608
2      Willie Heath          868 Santiago Grove\nNicolehaven, NJ 05026
3  Dr. Jared Ortega  517 Rodriguez Divide Suite 570\nWest Melinda, ...

Installation

pip install tblfaker

Dependencies

Python 2.7+ or 3.4+

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

tblfaker-0.0.3.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

tblfaker-0.0.3-py2.py3-none-any.whl (6.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file tblfaker-0.0.3.tar.gz.

File metadata

  • Download URL: tblfaker-0.0.3.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for tblfaker-0.0.3.tar.gz
Algorithm Hash digest
SHA256 c780ec4daee86524422bac713e4429d10d39cb911b026f9df59e1793c0362449
MD5 9b2347f4ac6357c4e03d9f472f344416
BLAKE2b-256 57963364b8a659951e347b4075e1014c7315ce03b1e74963db9037fb23116948

See more details on using hashes here.

File details

Details for the file tblfaker-0.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: tblfaker-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for tblfaker-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8567721939e0a52b1d5c590717edc5db66847ddea217ec9c69d6fd1a4fe5662c
MD5 b9e15ab31690a1b7ee56178da6d31787
BLAKE2b-256 c9ab07746d541588ad5b693982e0b9051a42d082159156e06282d87cec8e349a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page