A library for converting avro schemas to python types.
Project description
avro-to-python-types
A library for converting avro schemas to python types.
Currently, it supports converting record
s to TypedDict
. If you would like to see more features added, please open up an issue.
Why would I want this?
This library is target to people writing code generation for python apps that are using avro.
Example usage
from avro_to_python_types import schema_to_typed_dict
with open(test_json_file) as f:
avro_schema = f.read()
output = schema_to_typed_dict(avro_schema)
print(output)
The avro schema will produce the following python
{
"namespace": "example.avro",
"type": "record",
"name": "User",
"fields": [
{ "name": "name", "type": "string" },
{ "name": "favorite_number", "type": ["int", "null"] },
{ "name": "favorite_color", "type": ["string", "null"] },
{
"name": "address",
"type": {
"type": "record",
"name": "AddressUSRecord",
"fields": [
{ "name": "streetaddress", "type": "string" },
{ "name": "city", "type": "string" }
]
}
},
{
"name": "other_thing",
"type": {
"type": "record",
"name": "OtherThing",
"fields": [
{ "name": "thing1", "type": "string" },
{ "name": "thing2", "type": ["int", "null"] }
]
}
}
]
}
from typing import TypedDict, Optional
class AddressUSRecord(TypedDict):
streetaddress: str
city: str
class OtherThing(TypedDict):
thing1: str
thing2: Optional[int]
class User(TypedDict):
name: str
favorite_number: Optional[int]
favorite_color: Optional[str]
address: AddressUSRecord
other_thing: OtherThing
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for avro-to-python-types-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1248e5834aff8f42c78752da5b8b125db0eb83f063a6fedd4479c452dae530b |
|
MD5 | 91d19153ed773570fc0fc237c0cd87aa |
|
BLAKE2b-256 | 122f050e4bc5fa033ee1884304a0d9a7aee966a56478640b91e79e7f07bf904b |
Close
Hashes for avro_to_python_types-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc6e817c3d6c0c8cd348ce3ba699ff581ae182ec099564f3891651832b93d56b |
|
MD5 | 1f9755de6bae2d68f91d0f4f5ac54882 |
|
BLAKE2b-256 | c4c0e82e3c864544fcd16d4a99d0f2ac4cef0e32112894e39e865ef12a347853 |