pycirce, a set of combinators for encoding and decoding data
Project description
pycirce
Some primitive combinators for structurally decoding Python dataclass's,
namedtuple's, or other types.
Usage
pycirce.decode_list
The decode_list combinator accepts a decoder as its first argument and returns a decoder:
>>> decode_intlist = decode_list(int)
>>> decode_intlist(["1", "2", "3"])
[1, 2, 3]
pycirce.decode_object
The decode_object combinator accepts a constructor as its first argument,
as well as a kwarg of parameter names to decoders for that particular name.
>>> @dataclass
... class Person:
... name: str
... age: int
...
>>> decode_person = decode_object(Person)()
>>> decode_person({"name": "John Smith", "age": "45"})
Person(name='John Smith', age=45)
If members don't require downstream decoders, the second argument list kwargs can be empty:
>>> @dataclass
... class Person:
... name: str
... age: str
...
>>> decode_person = decode_object(Person)()
>>> decode_person({"name": "John Smith", "age": "45"})
Person(name='John Smith', age="45")
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pycirce-0.1.0.tar.gz.
File metadata
- Download URL: pycirce-0.1.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71d4aedc037d2082bf8e2513d72f95edf1971c75f97dff2b2c5521aff79a1dea
|
|
| MD5 |
04dd6e7dfa992b8487a48ad1e95577ba
|
|
| BLAKE2b-256 |
9bf835a461a3bce1eed06b3c256869da012b2ec1d6af07dec7d38d90e8c72bd1
|
File details
Details for the file pycirce-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pycirce-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d54569693516d3d5a2f0dfd79b70f0e403255db030b669972bbf182fbc2e74c1
|
|
| MD5 |
035d277d6f88b963485138fd1a6a761f
|
|
| BLAKE2b-256 |
2b7d63af240c41004426cc0f03fb03266e59c10ec46383193b7aca7252c8bb78
|