Registry / serialization / pybytebuffer

pybytebuffer

JSON →
library1.0.5pypypi✓ verified 25d ago

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.

pip install PyByteBuffer
INSTALL
IMPORT
SIG · PYBYTEBUFFER
P
pybytebuffer
serializationpythonv1.0.5
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 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.

ByteBuffer
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}')
Debug
Known issues
gotchaOperations like `get()` (for reading a single byte/value) do not advance the buffer's internal `position`, mimicking Java's `ByteBuffer`. This differs from typical Python stream-like objects where `read()` usually advances the cursor. Use `read()` methods or explicitly manage `position()` for sequential reading.
fix
Explicitly call `buffer.position(new_pos)` or use `buffer.read(...)` methods which advance the position automatically.
affects: All versions
gotchaWhen writing or reading integers, endianness matters. If not specified during a `write` operation, the system's default endianness is used. Reading with an incorrect endianness can lead to corrupted data. Be explicit, especially when dealing with network protocols or cross-platform data.
fix
Always explicitly specify endianness (e.g., `bb.write(value, 'int', 4, endian='big')`) if data exchange requires it, or if consistency across different systems is important.
affects: All versions
gotchaThe library documentation notes that performance considerations 'are all around the conversion between int->bytes bytes<-int'. Frequent or unoptimized conversions, especially in performance-critical loops, could lead to bottlenecks.
fix
Profile code that heavily uses `int` to `bytes` or `bytes` to `int` conversions. Consider batching operations or alternative approaches if performance becomes an issue.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pybytebuffer'
The `PyByteBuffer` library is imported with incorrect capitalization, or it has not been installed. The correct package name for installation and the primary module name start with a capital 'P'.
fix
Ensure the library is installed using `pip install PyByteBuffer` and import it using `from PyByteBuffer import ByteBuffer`.
IndexError: bytebuffer index out of range
This error occurs when an attempt is made to read or write beyond the allocated capacity or the current limit of the `ByteBuffer`, or when the requested read/write size exceeds the available remaining bytes.
fix
Before reading or writing, check `buffer.remaining()` to ensure sufficient bytes are available, or use `buffer.capacity()` and `buffer.limit()` to understand the buffer's boundaries. Adjust `buffer.position()` as needed.
ValueError: 'unsupported_type' is not a supported type
The `write()` or `read()` method was called with a `type` argument (e.g., 'int', 'str', 'bytes') that is misspelled or not recognized by the `PyByteBuffer` library.
fix
Verify the correct type strings accepted by the `write()` and `read()` methods, such as 'int', 'str', 'bytes', 'array', etc., as specified in the library's documentation.
Upgrade
Version history
1.0.5latest on PyPI · released Dec 28, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Amazon
1
Resources
pybytebuffer — pip install pybytebuffer · libregistry