Skip to main content

Simple decoder and encoder for CBOR (fork of flynn)

Project description

Flunn is also a Python library providing CBOR [RFC7049] encoding and decoding with a traditional buffered and a streaming interface. (flunn is a fork of flynn)

Usage

The Flunn API is really simple and inspired by existing Python serialisation modules like json and pickle. The flunn module has four methods called dumps, dump, loads and load, where dumps will return the serialised input as bytes string, while dump will write the serialised input to a file descriptor. The same applies to loads and load.

>>> flunn.dumps([1, [2, 3]])
b'\x82\x01\x82\x02\x03'
>>> flunn.loads(b'\x82\x01\x82\x02\x03')
[1, [2, 3]]

Furthermore, Flunn supports generators and other iterables as input for streaming support:

>>> flunn.dumps(range(5))
b'\x9f\x00\x01\x02\x03\x04\xff'
>>> flunn.loads(b'\x9f\x00\x01\x02\x03\x04\xff')
[0, 1, 2, 3, 4]

Or to generate a map using an iterable:

>>> flunn.dumps(flunn.mapping(((a, a) for a in range(5))))
b'\xbf\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\xff'
>>> flunn.loads(b'\xbf\x00\x00\x01\x01\x02\x02\x03\x03\x04\x04\xff')
{0: 0, 1: 1, 2: 2, 3: 3, 4: 4}

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

flunn-1.0.0b4.tar.gz (5.3 kB view details)

Uploaded Source

File details

Details for the file flunn-1.0.0b4.tar.gz.

File metadata

  • Download URL: flunn-1.0.0b4.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for flunn-1.0.0b4.tar.gz
Algorithm Hash digest
SHA256 6358e72d925f081622acbad27fd2bfadb713eabc55e06ef435325e99aa078059
MD5 c5f6c817517916db37ef2a744a673667
BLAKE2b-256 b6b76662b2ed94ee10fdfde7294323dfadbc336d98c9b4fe170c37359a693a99

See more details on using hashes here.

Supported by

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