Eventum Logo

Eventum

Eventtemplate

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

FunctionSignatureDescription
choice(items) → TReturn a random item from a sequence.
choices(items, n) → list[T]Return n random items with replacement.
weighted_choice(items, weights) → TReturn 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 | strShuffle elements. Returns a string if the input is a string.
chance(prob) → boolReturn 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

FunctionSignatureDescription
integer(a, b) → intRandom integer in [a, b] inclusive.
floating(a, b) → floatRandom float in [a, b].
gauss(mu, sigma) → floatRandom float from a Gaussian (normal) distribution.
lognormal(mu, sigma) → floatRandom float from a log-normal distribution (always positive, right-skewed).
exponential(lambd) → floatRandom float from an exponential distribution. lambd is the rate (1/mean).
pareto(alpha, xmin=1.0) → floatRandom float from a Pareto distribution (heavy-tailed, values ≥ xmin).
triangular(low, high, mode) → floatRandom float from a triangular distribution in [low, high] peaking at mode.
clamp(value, min, max) → floatClamp 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

FunctionSignatureDescription
letters_lowercase(size) → strRandom lowercase ASCII letters.
letters_uppercase(size) → strRandom uppercase ASCII letters.
letters(size) → strRandom mixed-case ASCII letters.
digits(size) → strRandom digit characters.
punctuation(size) → strRandom ASCII punctuation characters.
hex(size) → strRandom hex characters (0–9, a–f).
{%- set token = module.rand.string.hex(32) -%}
{%- set code = module.rand.string.letters_uppercase(6) -%}

rand.network

FunctionSignatureDescription
ip_v4() → strRandom IPv4 address (any range).
ip_v4_public() → strRandom public IPv4 (excludes private and reserved ranges).
ip_v4_private_a() → strRandom Class A private IPv4 (10.0.0.0/8).
ip_v4_private_b() → strRandom Class B private IPv4 (172.16.0.0/12).
ip_v4_private_c() → strRandom Class C private IPv4 (192.168.0.0/16).
mac() → strRandom 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

FunctionSignatureDescription
uuid4() → strRandom UUID v4.
md5() → strRandom 32-character hex string (MD5-length).
sha256() → strRandom 64-character hex string (SHA-256-length).
{%- set request_id = module.rand.crypto.uuid4() -%}
{%- set checksum = module.rand.crypto.sha256() -%}

rand.datetime

FunctionSignatureDescription
timestamp(start, end) → datetimeRandom 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 pathReturnsDescription
module.mimesis.locale['en']GenericFull Mimesis provider for a locale.
module.mimesis.enumsmoduleMimesis enums (Gender, FileType, TLDType, etc.).
module.mimesis.randommoduleMimesis 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.

On this page