fastavro.utils

generate_one(schema: Union[str, List, Dict]) Any

Returns a single instance of arbitrary data that conforms to the schema.

Parameters

schema (dict, list, string) – Schema

Example:

from fastavro import schemaless_writer
from fastavro.utils import generate_one

schema = {
    'doc': 'A weather reading.',
    'name': 'Weather',
    'namespace': 'test',
    'type': 'record',
    'fields': [
        {'name': 'station', 'type': 'string'},
        {'name': 'time', 'type': 'long'},
        {'name': 'temp', 'type': 'int'},
    ],
}

with open('weather.avro', 'wb') as out:
    schemaless_writer(out, schema, generate_one(schema))
generate_many(schema: Union[str, List, Dict], count: int) Iterator[Any]

A generator that yields arbitrary data that conforms to the schema. It will yield a number of data structures equal to what is given in the count

Parameters
  • schema (dict, list, string) – Schema

  • count (int) – Number of objects to generate

Example:

from fastavro import writer
from fastavro.utils import generate_data

schema = {
    'doc': 'A weather reading.',
    'name': 'Weather',
    'namespace': 'test',
    'type': 'record',
    'fields': [
        {'name': 'station', 'type': 'string'},
        {'name': 'time', 'type': 'long'},
        {'name': 'temp', 'type': 'int'},
    ],
}

with open('weather.avro', 'wb') as out:
    writer(out, schema, generate_data(schema, 5))
anonymize_schema(schema: Union[str, List, Dict]) Union[str, List, Dict]

Returns an anonymized schema

Parameters

schema (dict, list, string) – Schema

Example:

from fastavro.utils import anonymize_schema

anonymized_schema = anonymize_schema(original_schema)