PyByteBuffer is a Python library for manipulating byte buffers, drawing inspiration from Java's `java.nio.ByteBuffer`. It provides methods for writing and reading various data types (integers, strings, arrays, bytes) into a buffer with control over aspects like endianness and position. The current stable version is 1.0.5, released in late 2020, and it appears to be in a maintenance status, stable for its intended functionality.
Install & Compatibility
Where this runs
tested against v1.0.5 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
from PyByteBuffer import ByteBuffer
This quickstart demonstrates how to create a ByteBuffer, write different data types into it, reset its position, and then read the data back. It also highlights the behavior of `get()` versus `read()` methods concerning position advancement.
from PyByteBuffer import ByteBuffer
# Create a ByteBuffer with an initial capacity
bb = ByteBuffer(1024)
# Write various data types
bb.write(12345, 'int', 4) # Write an int (4 bytes)
bb.write('Hello PyByteBuffer', 'str') # Write a string
bb.write(b'\x01\x02\x03', 'bytes') # Write raw bytes
# Reset position to read from the beginning
bb.position(0)
# Read the data back
int_val = bb.read('int', 4)
str_val = bb.read('str', 18) # Read 18 characters for 'Hello PyByteBuffer'
bytes_val = bb.read('bytes', 3)
print(f'Read int: {int_val}')
print(f'Read string: {str_val}')
print(f'Read bytes: {bytes_val}')
# Example of getting without advancing position
bb.position(0)
first_byte = bb.get()
print(f'First byte (get, position unchanged): {first_byte}')
print(f'Position after get(): {bb.position()}')
first_byte_again = bb.get()
print(f'First byte again (get, position unchanged): {first_byte_again}')
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.