Skip to main content

Random data generator for the command line

Project description

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…


$ pip install fakr

Basic Usage

$ fakr --help


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 -d @-

Write data to a redis server:

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


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)}})

  • hash: Calculates the hash with a given hashing algo (i. e. {{email|hash(‘md5’)}})

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.1.1.tar.gz (78.6 kB view hashes)

Uploaded source

Built Distribution

fakr-0.1.1-py3-none-any.whl (78.5 kB view hashes)

Uploaded py3

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