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
pycirce-0.1.0.tar.gz
(3.7 kB
view hashes)