Skip to main content

DataChunk is an useful library for proessing messages in a stream where messages are sent in a stream as shown below: <msg-size><msg-bytes><msg-size><msg-bytes><msg-size>…. msg-size is a 4 byte integer (little-endian) whenever a complete message is read, DataChunk calls the handle_msg method of the handler.

A message may come in fragments. Sometimes many messages may come in a single data packet. All we need to do is to call process_chunk method of DataChunk and DataChunk object will take care of re-assembling the messages as and when needed.

Basic example

from __future__ import print_function
from struct import pack
import random
from datachunkpy.datachunk import DataChunk, MessageHandler

# A message handler class
class MyMsgHandler(MessageHandler):
    def __init__(self):
        self.msg_processed = 0
        self.bytes_processed = 0

    def handle_msg(self, data):
        print('I am handling', data)
        self.msg_processed += 1
        self.bytes_processed += len(data)


datach = DataChunk(MyMsgHandler())

i = 0
random.seed()
mydata = b''
total_bytes = 0
while i < 10000:
    i += 1
    j = random.randint(1,50)
    mydata += pack('i', j)
    mydata += b'a' * j
    total_bytes += j
datach.process_chunk(mydata)

Metadata

Release files for datachunkpy 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for datachunkpy 1.0.0
File Size Uploaded Provenance
datachunkpy-1.0.0.tar.gz 3.1 kB Without provenance Details

Release files / datachunkpy-1.0.0.tar.gz

Download URL datachunkpy-1.0.0.tar.gz
Size 3.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d1bbf648ab0309fef6697e3ac88a0b15902585196fa3f7623ea08a731a9a2673
BLAKE2b-256 checksum
How to use checksums
2b84690f69310fd526dc4a6c8756926762d21ebf16c510c17c779b83c5b37454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for datachunkpy 1.0.0

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page