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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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

Hashes for pycirce-0.1.0.tar.gz
Algorithm Hash digest
SHA256 71d4aedc037d2082bf8e2513d72f95edf1971c75f97dff2b2c5521aff79a1dea
MD5 04dd6e7dfa992b8487a48ad1e95577ba
BLAKE2b-256 9bf835a461a3bce1eed06b3c256869da012b2ec1d6af07dec7d38d90e8c72bd1

See more details on using hashes here.

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

Hashes for pycirce-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d54569693516d3d5a2f0dfd79b70f0e403255db030b669972bbf182fbc2e74c1
MD5 035d277d6f88b963485138fd1a6a761f
BLAKE2b-256 2b7d63af240c41004426cc0f03fb03266e59c10ec46383193b7aca7252c8bb78

See more details on using hashes here.

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