Registry / serialization / bytesparse

bytesparse

JSON →
library1.1.0pypypi✓ verified 35d ago

The `bytesparse` library provides utilities for managing sparse bytes within a virtual memory space. It offers an interface similar to Python's built-in `bytearray`, allowing for non-contiguous data allocation across a potentially infinite addressing space. Data chunks are stored internally using mutable `bytearray` objects. The library is currently at version 1.1.0 and exhibits an active release cadence, with several updates in the past year.

serialization
Install & Compatibility
Where this runs
tested against v1.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.022s · 18.4MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.020s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

A generic virtual memory class with an infinite address range.

from bytesparse import Memory

A subclass of Memory that behaves more like a bytearray.

from bytesparse import bytesparse

This quickstart demonstrates how to initialize `bytesparse` and `Memory` objects, perform basic read/write operations, and store data sparsely at arbitrary addresses. It shows how `bytesparse` can be initialized from bytes and how `poke` can be used for non-contiguous writes.

from bytesparse import bytesparse, Memory # Create a bytesparse object from existing bytes m = bytesparse(b'Hello, World!') print(f"Initial bytesparse: {m}") print(f"Length: {len(m)}") print(f"As bytes: {bytes(m)}") # Modify the content m[0:5] = b'Ciao ' print(f"After modification: {bytes(m)}") # Store data at a sparse, non-contiguous address m.poke(1000, b'remote data') print(f"After poking remote data: {m}") print(f"Virtual length increased: {len(m)}") # Accessing a generic Memory object mem = Memory() mem[0x100:0x105] = b'DATA_A' mem[0x200:0x205] = b'DATA_B' print(f"Memory object blocks: {mem.to_blocks()}") print(f"Memory at 0x100: {mem.peek(0x100, 5)}")
Debug
Known footguns
gotchaThe companion `cbytesparse` (Cython) package has a limited addressing space (uint_fast64_t, typically 32-bit or 64-bit) and does not support infinite or negative addresses, unlike the pure Python `bytesparse` implementation. Users switching between implementations should be aware of this difference.
gotchaWhile the Cython implementation (`cbytesparse`) aims for speedup, it is labeled as 'experimental' and the documentation suggests that even faster 'ad-hoc' implementations for specific hardware might exist. Do not assume `cbytesparse` provides optimal performance for all scenarios without benchmarking.
gotchaBoth `Memory` and `bytesparse` classes inherit from `collections.abc.MutableSequence` and `collections.abc.MutableMapping` to provide familiar interfaces. However, their internal sparse storage mechanism means that certain operations might have different performance characteristics or behaviors compared to direct Python `list` or `dict` equivalents, especially for highly fragmented data.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
18 hits · last 30 days
gptbot
4
ahrefsbot
4
amazonbot
4
bytedance
4
script
1
Resources