Skip to main content

sansio_tools

Useful tools for building Sans IO-based libraries.

BytesQueue

Example code:

from sansio_tools.queue import BytesQueue

q = BytesQueue()

q.append(b"012345")

print(bytes(q.peekleft(2)))  # b"01"

print(bytes(q.popleft(3)))  # b"012"

# put the bytes back into the queue!
q.appendleft(b"012")

print(bytes(q.popleft(4)))  # b"0123"

BinaryParser

Example code:

from struct import Struct
from sansio_tools.parser import BinaryParser


# int8, uint32, uint64
my_struct = Struct("!bIQ")

def parser_generator(p: BinaryParser):
    b = yield from p.read_bytes(6)
    results.append(b)
    b = yield from p.read_bytes(6)
    results.append(b)

    lst = yield from p.read_struct(my_struct)
    results.append(lst)

    n = yield from p.read_int(2, "little", False)
    results.append(n)

    n = yield from p.read_variable_length_int_7bit(
        maximum_length=10,
        byteorder="big",
        continuation_bit_value=True,
        require_canonical=True,
    )
    results.append(n)

results = []
p = BinaryParser(parser_generator)
p.feed(b"hell")
p.feed(b"o world!\xff")

# receive partial results as they become available!
assert results == [b"hello ", b"world!"]
assert not p.generator_exited
results.clear()

p.feed(b"\xff\x00\x00\x00\xff\x00\x00\x00\x00\x00\x00\x00\x12\x34")
p.feed(b"\x81\x80\x80")

assert results == [(-1, 0xff << 24, 0xff << 56), 0x3412]
assert not p.generator_exited
results.clear()

p.feed(b"\x80\x05")
p.feed(None)  # signal eof

assert results == [(1 << (7 * 4)) + 5]
assert p.generator_exited

Metadata

Release files for sansio-tools 1.0.2

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

Source distribution (sdist)

Source distribution for sansio-tools 1.0.2
File Size Uploaded Provenance Actions
sansio_tools-1.0.2.tar.gz 16.6 kB Without provenance Details for sansio_tools-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sansio-tools 1.0.2
File Interpreter ABI Platform Actions
sansio_tools-1.0.2-py3-none-any.whl Python 3 none any Details for sansio_tools-1.0.2-py3-none-any.whl

Total release size: 25.2 kB

Release files / sansio_tools-1.0.2.tar.gz

Download URL sansio_tools-1.0.2.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
55de0243cef66513751f7e1c9d49314a0ea78d45aac62fd1e7263806f44dfe84
BLAKE2b-256 checksum
How to use checksums
cc5616d2c6f471f2aef2ddffb37cedaac453ad164247b5b6ff98cce832b65253
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / sansio_tools-1.0.2-py3-none-any.whl

Download URL sansio_tools-1.0.2-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f8f12c406b91a59d1ce63fabcbaede5ac628001ce995726efdcd0dc1c6ab9417
BLAKE2b-256 checksum
How to use checksums
224960d9a1e2759a92063fa06a79f55197ba26fcb0a409f08991e3e786e83b8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Security for sansio-tools 1.0.2

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.

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