fastavro.utils¶
-
generate_one
(schema: Union[str, List[T], Dict[KT, VT]]) → Any¶ Returns a single instance of arbitrary data that conforms to the schema.
Parameters: schema – Schema that data should conform to 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[T], Dict[KT, VT]], 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 – Schema that data should conform to
- count – Number of objects to generate
Example:
from fastavro import writer from fastavro.utils import generate_many 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_many(schema, 5))
-
anonymize_schema
(schema: Union[str, List[T], Dict[KT, VT]]) → Union[str, List[T], Dict[KT, VT]]¶ Returns an anonymized schema
Parameters: schema – Schema to anonymize Example:
from fastavro.utils import anonymize_schema anonymized_schema = anonymize_schema(original_schema)