API Reference¶
Auto-generated from source docstrings.
avro_datagen¶
avro_datagen
¶
Schema-driven data generator for Avro schemas with arg.properties hints.
RecordResolver(schema, seed=None)
¶
Resolves a single Avro record schema into generated dicts.
Maintains pools (for pool hints) across multiple generate() calls so that
pooled values are reused across records.
Source code in src/avro_datagen/resolver.py
generate()
¶
Generate one record. Fields resolved top-to-bottom.
SchemaValidationError(errors)
¶
Bases: ValueError
Raised when a schema fails validation.
Contains a list of error messages, one per issue found. The first message is also used as the exception's main message.
Source code in src/avro_datagen/validator.py
generate(schema_path, count, seed=None)
¶
Generate count fake records from an Avro schema file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_path
|
str | Path
|
Path to a .avsc file. |
required |
count
|
int
|
Number of records to generate. 0 means infinite. |
required |
seed
|
int | None
|
Optional seed for reproducible output. |
None
|
Yields:
| Type | Description |
|---|---|
dict
|
dict — one record per iteration. |
Source code in src/avro_datagen/generator.py
load_schema(path)
¶
validate(schema)
¶
Validate an Avro schema and return a list of warnings.
Errors (structural problems) raise SchemaValidationError. Warnings (unknown hint keys, etc.) are returned as a list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema
|
dict | str | Path
|
Parsed schema dict or path to an .avsc file. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
List of warning strings (empty if the schema is clean). |
Raises:
| Type | Description |
|---|---|
SchemaValidationError
|
if the schema has structural errors. |
Source code in src/avro_datagen/validator.py
generator¶
avro_datagen.generator
¶
Core generator — loads an Avro schema and yields fake records.
generate(schema_path, count, seed=None)
¶
Generate count fake records from an Avro schema file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_path
|
str | Path
|
Path to a .avsc file. |
required |
count
|
int
|
Number of records to generate. 0 means infinite. |
required |
seed
|
int | None
|
Optional seed for reproducible output. |
None
|
Yields:
| Type | Description |
|---|---|
dict
|
dict — one record per iteration. |
Source code in src/avro_datagen/generator.py
resolver¶
avro_datagen.resolver
¶
Field resolver — maps Avro types + arg.properties to generated values.
This is the core engine. It walks an Avro schema top-to-bottom, resolving each
field's value based on its type, logical type, and arg.properties hints. Fields
are resolved in declaration order so that later fields can reference earlier ones
via ref and rules.
RecordResolver(schema, seed=None)
¶
Resolves a single Avro record schema into generated dicts.
Maintains pools (for pool hints) across multiple generate() calls so that
pooled values are reused across records.
Source code in src/avro_datagen/resolver.py
generate()
¶
Generate one record. Fields resolved top-to-bottom.
producer¶
avro_datagen.producer
¶
Kafka producer — generates records from an Avro schema and publishes to a topic.
build_producer_config(bootstrap_servers, security_protocol='', sasl_mechanism='', sasl_username='', sasl_password='', acks='all', linger_ms=5, batch_size=16384, compression_type='none')
¶
Build a confluent-kafka producer config dict from explicit params.
Source code in src/avro_datagen/producer.py
produce(schema_path, topic, producer_config, count=10, rate=None, seed=None, key_fn=None, on_delivery=None, on_progress=None)
¶
Generate records and publish them to a Kafka topic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schema_path
|
str | Path
|
Path to the .avsc schema file. |
required |
topic
|
str
|
Kafka topic to publish to. |
required |
producer_config
|
dict[str, str | int]
|
confluent-kafka Producer config dict. |
required |
count
|
int
|
Number of records (0 = infinite). |
10
|
rate
|
float | None
|
Records per second limit. None = unlimited. |
None
|
seed
|
int | None
|
Random seed for reproducibility. |
None
|
key_fn
|
Callable[[dict[str, Any]], str | None] | None
|
Callable to extract a message key from the record. |
None
|
on_delivery
|
Callable[[Any, Any], None] | None
|
Per-message delivery callback (err, msg). |
None
|
on_progress
|
Callable[[int, dict[str, Any]], None] | None
|
Called after each record with (index, record). |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, int | float]
|
dict with produced, errors, elapsed_s keys. |
Source code in src/avro_datagen/producer.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
cli¶
avro_datagen.cli
¶
CLI entry point — generate fake data to stdout as JSON lines.