Skip to main content

pycirce, a set of combinators for encoding and decoding data

Project description

pycirce

Run on Repl.it pypi: 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


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)

Uploaded Source

Built Distribution

pycirce-0.1.0-py3-none-any.whl (3.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page