py-coders
A simple set of symmetric strongly-typed encoder/decoder classes for serializing to and from byte-like objects. The intended use case for these is to allow for composable encoding of raw byte arrays, operations that may be common to systems working with low level key-value stores (memcached/Redis/LMDB/etc) or passing binary messages in message queues (e.g. Protocol Buffers as messages in RabbitMQ).
Usage
Coders are meant to have a simple interface:
Coder.encocde(obj)to serialize objects to a bytes-like object.Coder.decode(buf)to deserialize objects from a byte-like object.
Supported Base Coders
IdentityCoder- passes bytes through unchanged.StringCoder- string objects, supportsascii,utf8,utf16, etc. encodings.IntCoder,UInt16Coder,UInt32Coder,UInt64Coder- general or unsigned 16/32/64 bit integers. (Big-endian)JSONCoder- JSON serializable python objectPickleCoder- Any picklable Python object.ProtobufCoder- Google Protobuf objects. Requiresprotobufto be installed.
Chaining Coders
Coders can be chained sequentially to create sequences of encoding/decoding. For example, to make a Coder that can encode and decode encrypted compressed JSON blobs, the following code can be used:
compressed_json_coder = ChainCoder([
JSONCoder(),
ZlibCoder(level=5),
EncryptedCoder(AES.new(...))
])
This chaining is pretty common in creating composite Coders so all Coders have a
then function that can be used in a fluent API.
compressed_json_coder = JSONCoder().then(ZlibCoder(level=5)) \
.then(EncryptedCoder(AES.new(...)))
Three special use cases, prefixing, compression, and encryption have further shortcuts to reduce repitition.:
prefixed_int_coder = IntCoder().prefixed(prefix=b'users:')
compressed_json_coder = JSONCoder().compressed(level=5).encrypted(AES.new(...))
Note: what is shown here as an example may not be entirely seucre. It's meant as an example of what can be done with the API, not what should be done. Compressing then encrypting data may weaken security depending on the context in which it's used.
Sequence / Stream Processing
Coders support encoding/decoding arbitrary streams of data via Coder.encode_all
and Coder.decode_all. These operations use generator expressions, so they can
operate on arbitrarily long, possilby infinite streams of data.
json_coder = JSONCoder().compressed(level=5)
# Works with normal iterables
json_blobs = json_coder.encode_all([{"name": "object_1"}, {"name": "object_2"}])
# Can run over infinite streams of inputs.
for messages in json_coder.decode_all(input_stream()):
// Handle messages
Async iterators are also supported via the Coder.encode_all_async and
Coder.decode_all_async alternatives.
json_coder = JSONCoder().compressed(level=5)
# Can run over infinite streams of inputs.
async for messages in json_coder.decode_all(async_input_stream()):
// Handle messages
Error handling can be done without terminating the stream by providing a
on_error parameter.
json_coder = JSONCoder().compressed(level=5)
def json_on_error(msg, exc, exc_type, traceback):
// handle decoding errors here
# Can run over infinite streams of inputs.
async for messages in json_coder.decode_all(async_input_stream(),
on_error=json_on_error):
// Handle messages
Metadata
Release files for py-coders 1.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| py-coders-1.1.5.tar.gz | 6.2 kB | Without provenance | Details for py-coders-1.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| py_coders-1.1.5-py3-none-any.whl | Python 3 | none | any | Details for py_coders-1.1.5-py3-none-any.whl |
Total release size: 13.7 kB
Release files / py-coders-1.1.5.tar.gz
| Download URL | py-coders-1.1.5.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c3411195be43b7743ac990dabe07354154c962003f8c27b7df7c5e8fa617b238
|
|
BLAKE2b-256 checksum How to use checksums |
8a20a6d89a92c086b94604273b4a3ae541d38c208f1937a47e6505a534801ae2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Release files / py_coders-1.1.5-py3-none-any.whl
| Download URL | py_coders-1.1.5-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c5039369db66b4debea397a52835608e3f530c44a7a08674bda6e34938c6d916
|
|
BLAKE2b-256 checksum How to use checksums |
e79545fca645800132138385fc19bc8d88223d5a50246e0a29ab16b894936f0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4
|
Security for py-coders 1.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.