Skip to main content

Random data generator for the command line

Project description

https://beerpay.io/l-x/fakr/badge.svg?style=beer https://badges.gitter.im/random-data-fakrs/Lobby.svg https://travis-ci.org/l-x/fakr.svg?branch=master https://codecov.io/gh/l-x/fakr/branch/master/graph/badge.svg

Random data, fakrs!

fakr reads a Jinja2 Template from stdin, renders it using a vocabulary and writes the result to stdout. It’s as simple as that…

Installation

$ pip install fakr

Basic Usage

$ fakr --help

Examples

Generate a simple csv file with 100k rows

$ echo "{{row}},{{row%100}},{{firstname}},{{lastname}},{{email}}" \
  | fakr --count 100000``

Use a file for complex template

$ cat examples/templates/vcard.tpl \
  | fakr --count 1000

Make a http request using curl:

$ echo "company={{company|urlencode}}&city={{city|urlencode}}"  \
  | fakr -c1 \
  | curl httpbin.org/post -d @-

Write data to a redis server:

$ echo 'firstname \"{{firstname}}\" lastname \"{{lastname}}\" email \"{{email}}\"' \
  | fakr \
  | xargs -i redis-cli HMSET {}``

Templates

The templates you use for data generation are plain Jinja2 Templates. See their reference for detailed information.

There are a few custom filters, functions and variables for use with fakr:

Custom filters:

  • ascii: Converts the value to ascii (using Unidecode) (i. e. {{lastname|ascii}})

  • shuffle: Shuffles the value randomly (i. e. {{lastname|shuffle}})

  • chance: Gives the value a chance from 0.0 to 1.0 to be returned (i. e. {{firstname|chance(0.9)}} - firstname will be 90% returned, 10% empty)

  • rjust: Right-justifies the value to the given with (i. e. {{company|rjust(40)}})

  • ljust: Left-justifies the value to the given with (i. e. {{company|ljust(40)}})

  • center: Centers the value in width (i. e. {{company|center(40)}})

Custom functions:

  • translate

  • uuid4: Returns a new UUIDv4 on every call (i. e. {{uuid4()}})

  • unixtime: Returns a the current unixtime as float in seconds, (i. e. {{unixtime()}})

Fixed (vocabulary independent) variables:

  • row: The row (starting from 0) of the current dataset

  • id: The id or sequence number of the current dataset

  • guid: The representation of the id in a uuid-like fashion

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

fakr-0.0.8.tar.gz (80.3 kB view details)

Uploaded Source

Built Distribution

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

fakr-0.0.8-py3-none-any.whl (82.5 kB view details)

Uploaded Python 3

File details

Details for the file fakr-0.0.8.tar.gz.

File metadata

  • Download URL: fakr-0.0.8.tar.gz
  • Upload date:
  • Size: 80.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fakr-0.0.8.tar.gz
Algorithm Hash digest
SHA256 d07d426ba86a1342797c202556b954a1ebe8ac0e349a7903fd6c6198334b8d9b
MD5 5dda096e1b995389c202986c209752ba
BLAKE2b-256 610055cad719f89842e157e8ac2f8d5f3f060c6a4fe9d97e5fa3b292c79c28a2

See more details on using hashes here.

File details

Details for the file fakr-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: fakr-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 82.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fakr-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8b098b53e738d805ca0e27e0f4ada5a5cfeba164b84013d353d1af5afb67a5ff
MD5 b455338da100fceeaf10a19eb78171d9
BLAKE2b-256 d17445ae8aafb716e46c3d442ffb44f5900ddc7c644902ae65262e1187f2ce62

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