Modules
Data-generation libraries available in Jinja2 templates — rand, faker, mimesis, and any Python module.
The module object provides access to three built-in data-generation libraries and acts as a gateway to any Python package installed in the environment. Access a module by name: module.<name>.
module.rand
Built-in random utilities organized into namespaces. This is the most commonly used module for generating synthetic data.
Top-level functions
| Function | Signature | Description |
|---|---|---|
choice | (items) → T | Return a random item from a sequence. |
choices | (items, n) → list[T] | Return n random items with replacement. |
weighted_choice | (items, weights) → T | Return a random item with weighted probability. Also accepts a dict: ({item: weight, ...}). |
weighted_choices | (items, weights, n) → list[T] | Return n items with weighted probability. Also accepts a dict: ({item: weight, ...}, n). |
shuffle | (items) → list | str | Shuffle elements. Returns a string if the input is a string. |
chance | (prob) → bool | Return True with the given probability (0.0–1.0). |
{%- set method = module.rand.choice(["GET", "POST", "PUT", "DELETE"]) -%}
{# Dict form — keys are items, values are weights #}
{%- set status = module.rand.weighted_choice({200: 80, 301: 5, 404: 10, 500: 5}) -%}
{# Two-sequence form — also supported #}
{%- set status = module.rand.weighted_choice([200, 301, 404, 500], [80, 5, 10, 5]) -%}
{% if module.rand.chance(0.05) %}RARE EVENT{% endif %}rand.number
| Function | Signature | Description |
|---|---|---|
integer | (a, b) → int | Random integer in [a, b] inclusive. |
floating | (a, b) → float | Random float in [a, b]. |
gauss | (mu, sigma) → float | Random float from a Gaussian (normal) distribution. |
lognormal | (mu, sigma) → float | Random float from a log-normal distribution (always positive, right-skewed). |
exponential | (lambd) → float | Random float from an exponential distribution. lambd is the rate (1/mean). |
pareto | (alpha, xmin=1.0) → float | Random float from a Pareto distribution (heavy-tailed, values ≥ xmin). |
triangular | (low, high, mode) → float | Random float from a triangular distribution in [low, high] peaking at mode. |
clamp | (value, min, max) → float | Clamp value to the range [min, max]. |
{%- set port = module.rand.number.integer(1024, 65535) -%}
{%- set latency = module.rand.number.floating(0.1, 2.5) -%}
{%- set score = module.rand.number.gauss(50, 10) -%}
{# Statistical distributions #}
{%- set duration = module.rand.number.lognormal(3.0, 1.0) -%}
{%- set wait_time = module.rand.number.exponential(0.5) -%}
{%- set file_size = module.rand.number.pareto(1.5, xmin=100.0) -%}
{%- set temperature = module.rand.number.triangular(15.0, 35.0, 22.0) -%}
{# Combine a distribution with clamp to bound the result #}
{%- set bytes_sent = module.rand.number.clamp(module.rand.number.gauss(5000, 2000), 0, 15000) -%}rand.string
| Function | Signature | Description |
|---|---|---|
letters_lowercase | (size) → str | Random lowercase ASCII letters. |
letters_uppercase | (size) → str | Random uppercase ASCII letters. |
letters | (size) → str | Random mixed-case ASCII letters. |
digits | (size) → str | Random digit characters. |
punctuation | (size) → str | Random ASCII punctuation characters. |
hex | (size) → str | Random hex characters (0–9, a–f). |
{%- set token = module.rand.string.hex(32) -%}
{%- set code = module.rand.string.letters_uppercase(6) -%}rand.network
| Function | Signature | Description |
|---|---|---|
ip_v4 | () → str | Random IPv4 address (any range). |
ip_v4_public | () → str | Random public IPv4 (excludes private and reserved ranges). |
ip_v4_private_a | () → str | Random Class A private IPv4 (10.0.0.0/8). |
ip_v4_private_b | () → str | Random Class B private IPv4 (172.16.0.0/12). |
ip_v4_private_c | () → str | Random Class C private IPv4 (192.168.0.0/16). |
mac | () → str | Random MAC address (colon-separated, e.g. a4:3b:00:ff:12:9e). |
{%- set src_ip = module.rand.network.ip_v4_public() -%}
{%- set dst_ip = module.rand.network.ip_v4_private_c() -%}
{%- set mac_addr = module.rand.network.mac() -%}rand.crypto
| Function | Signature | Description |
|---|---|---|
uuid4 | () → str | Random UUID v4. |
md5 | () → str | Random 32-character hex string (MD5-length). |
sha256 | () → str | Random 64-character hex string (SHA-256-length). |
{%- set request_id = module.rand.crypto.uuid4() -%}
{%- set checksum = module.rand.crypto.sha256() -%}rand.datetime
| Function | Signature | Description |
|---|---|---|
timestamp | (start, end) → datetime | Random timestamp in range [start, end]. Both arguments are datetime objects. |
Combined example
{%- set src_ip = module.rand.network.ip_v4_public() -%}
{%- set method = module.rand.weighted_choice(["GET", "POST", "PUT"], [70, 20, 10]) -%}
{%- set status = module.rand.weighted_choice([200, 301, 404, 500], [80, 5, 10, 5]) -%}
{%- set request_id = module.rand.crypto.uuid4() -%}
{%- set bytes_sent = module.rand.number.integer(200, 15000) -%}
{{ timestamp.isoformat() }} {{ src_ip }} {{ method }} /api/resource {{ status }} {{ bytes_sent }} {{ request_id }}module.faker
The Faker library for generating realistic fake data. Access a Faker instance by locale:
{{ module.faker.locale['en_US'].name() }} {# "John Smith" #}
{{ module.faker.locale['en_US'].email() }} {# "john.smith@example.com" #}
{{ module.faker.locale['en_US'].ipv4() }} {# "192.168.1.100" #}
{{ module.faker.locale['en_US'].user_agent() }} {# "Mozilla/5.0 ..." #}
{{ module.faker.locale['de_DE'].city() }} {# "Berlin" #}
{{ module.faker.locale['ja_JP'].name() }} {# "山田 太郎" #}Locale instances are created once and cached. Faker supports hundreds of providers — names, addresses, phone numbers, credit cards, companies, dates, user agents, and more.
In Jinja2, both dot notation (module.faker.locale.en_US) and bracket notation (module.faker.locale['en_US']) work. Bracket notation is recommended for locale codes with special characters.
module.mimesis
The Mimesis library for high-performance data generation. It provides three access paths:
| Access path | Returns | Description |
|---|---|---|
module.mimesis.locale['en'] | Generic | Full Mimesis provider for a locale. |
module.mimesis.enums | module | Mimesis enums (Gender, FileType, TLDType, etc.). |
module.mimesis.random | module | Mimesis random utilities. |
{{ module.mimesis.locale['en'].person.full_name() }} {# "John Doe" #}
{{ module.mimesis.locale['en'].internet.ip_v4() }} {# "10.0.1.42" #}
{{ module.mimesis.locale['en'].address.city() }} {# "San Francisco" #}
{{ module.mimesis.locale['ru'].person.full_name() }} {# "Иванов Иван" #}Any Python module
If the name isn't one of the three built-ins (rand, faker, mimesis), the module object imports it from the Python standard library or any package installed in the environment:
{# Standard library #}
{{ module.json.dumps({"event": "test"}) }}
{{ module.math.ceil(3.14) }}
{{ module.hashlib.sha256(b"data").hexdigest() }}
{{ module.base64.b64encode(b"hello").decode() }}
{{ module.datetime.timedelta(seconds=30) }}Modules are imported once and cached for subsequent access. If a module is not found, a KeyError is raised.