Avro schema and data converters supporting storing arbitrary nested python data structures.
Project description
rec-avro:
Avro support for JSON and other nested data structures.
Rec-avro provides a generic Avro schema and converter functions that allow for storing nested python data structures in avro.
Tested in Python 3 only.
Installation:
$ pip3 install rec-avro
Usage:
With fastavro:
from fastavro import writer, reader, schema
from rec_avro import to_rec_avro_destructive, from_rec_avro_destructive, rec_avro_schema
def json_objects():
return [{'a': 'a'}, {'b':'b'}]
# For efficiency, to_rec_avro_destructive() destroys rec, and reuses it's
# data structures to construct avro_objects
avro_objects = (to_rec_avro_destructive(rec) for rec in json_objects())
# store records in avro
with open('json_in_avro.avro', 'wb') as f_out:
writer(f_out, schema.parse_schema(rec_avro_schema()), avro_objects)
#load records from avro
with open('json_in_avro.avro', 'rb') as f_in:
# For efficiency, from_rec_avro_destructive(rec) destroys rec, and
# reuses it's data structures to construct it's output
loaded_json = [from_rec_avro_destructive(rec) for rec in reader(f_in)]
assert loaded_json == json_objects()
Development:
# Running all tests:
$ python setup.py pytest
# Running tests manually
$ pip3 install fastavro pytest
$ python setup.py develop
$ pytest tests/test_rec_avro.py
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rec-avro-0.0.4.tar.gz
(3.0 kB
view details)
Built Distribution
File details
Details for the file rec-avro-0.0.4.tar.gz
.
File metadata
- Download URL: rec-avro-0.0.4.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e7217d56e46bb0fe9ef5a156e04400b4a3bbdf7612920c3f8f2670d840bd249 |
|
MD5 | fe5fafe88deaa2d521db473c02dc1109 |
|
BLAKE2b-256 | e4c16f85a5b6fce4f04bd5e1546e02ccb99c3699cc7d96e2826be044a5e395bb |
File details
Details for the file rec_avro-0.0.4-py3-none-any.whl
.
File metadata
- Download URL: rec_avro-0.0.4-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 543951512dabeaa83f354d34c34815e7f0decb961fb8c42a2961b6aa11eb2e12 |
|
MD5 | f479e5ab1dba7b3be6f0564b792110fd |
|
BLAKE2b-256 | 14feb9bb0a22fbd3fe4f4b1502a2a1f003e1f7f3511d8142ba9501dc0b46e939 |