Skip to main content

Tools to make codecs for time-series serialization and deserialization.

Project description

recode

Make codecs for fixed size structured chunks serialization and deserialization of sequences, tabular data, and time-series.

To install: pip install recode

Examples

single channel numerical stream

>>> from recode import StructCodecSpecs
>>> specs = StructCodecSpecs(
...     chk_format='h',
... )
>>> print(specs)
StructCodecSpecs(chk_format='h', n_channels=1, chk_size_bytes=2)
>>>
>>> encoder = ChunkedEncoder(
...     frame_to_chk=specs.frame_to_chk
... )
>>> decoder = ChunkedDecoder(
...     chk_size_bytes=specs.chk_size_bytes,
...     chk_to_frame=specs.chk_to_frame,
...     n_channels=specs.n_channels
... )
>>>
>>> frames = [1, 2, 3]
>>> b = encoder(frames)
>>> assert b == b'\x01\x00\x02\x00\x03\x00'
>>> decoded_frames = list(decoder(b))
>>> assert decoded_frames == frames

Multi-channel numerical stream

>>> from recode import StructCodecSpecs
>>> specs = StructCodecSpecs(
...     chk_format='@h',
...     n_channels = 2
... )
>>> print(specs)
StructCodecSpecs(chk_format='@hh', n_channels=2, chk_size_bytes=4)
>>>
>>>
>>> encoder = ChunkedEncoder(
...     frame_to_chk=specs.frame_to_chk
... )
>>> decoder = ChunkedDecoder(
...     chk_size_bytes=specs.chk_size_bytes,
...     chk_to_frame=specs.chk_to_frame,
...     n_channels=specs.n_channels
... )
>>>
>>> frames = [(1, 2), (3, 4), (5, 6)]
>>>
>>> b = encoder(frames)
>>> assert b == b'\x01\x00\x02\x00\x03\x00\x04\x00\x05\x00\x06\x00'
>>> decoded_frames = list(decoder(b))
>>> assert decoded_frames == frames

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

recode-0.1.4.tar.gz (9.0 kB view hashes)

Uploaded Source

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