Skip to main content
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)}})

  • 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

Metadata

Release files for fakr 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fakr 0.1.1
File Size Uploaded
fakr-0.1.1.tar.gz 78.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fakr 0.1.1
File Interpreter ABI Platform
fakr-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 157.1 kB

Release files / fakr-0.1.1.tar.gz

Download URL fakr-0.1.1.tar.gz
Size 78.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7ed7b2acb1961673c9433cf8b3558348a424cec86e7b5f45ff11d2cdafa3ebf9
BLAKE2b-256 checksum
How to use checksums
6a1d244c8813fd3e2fd17a94560e89a882977f29ea95d3d7c8e32f15f5d1fd71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / fakr-0.1.1-py3-none-any.whl

Download URL fakr-0.1.1-py3-none-any.whl
Size 78.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a24fe9da1263db515ba41d6a08f2f842bdb2ac1872f57201beed48ed4974bc85
BLAKE2b-256 checksum
How to use checksums
08d8b7a88d05b8bac73d4c2de881cc87b421a9f228fe582acd9163aeed6d5757
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

1 release file

0.0.5

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page