Skip to main content

Byter

Python reader/writer for binary objects

Installation

pip install -U byter

Usage Example

with open("/path/to/binary/file", "rb") as data:
    has_data = read_bool(data)
    year = read_short(data)
    month = read_short(data)
    width = read_float(data)
    height = read_float(data)
    text = read_string(data, 70)
    array = read_array(data, 3, 'unsigned_short')

print("has_data:", has_data)
print("year:", year)
print("month:", month)
print("width:", width)
print("height:", height)
print("text:": text)
print("array:", array)

>> has_data: True
   year: 2019
   month: 9
   width: 1280.0
   height: 1024.0
   text: "Hello World!"
   array: [13, 4, 16]

Types allowed to read/write

C Type Python type Size in bytes
char string of length 1 1
signed char integer 1
unsigned char integer 1
bool boolean 1
short integer 2
unsigned short integer 2
int integer 4
unsigned int integer 4
long integer 4
unsigned long integer 4
long long integer 8
unsigned long long integer 8
float float 4
double float 8
char[] string

Methodes allowed

For each C type from the table in the previous section, there is a read_ and a write_ function that performs a reading/writing of a specified number of bytes from the binary object. For example,

a = read_unsigned_long(data)

will read 4 consequent bytes from the binary source data.

However, to read an array of chars (string) the method is

s = read_string(data, s_len)

It is also possible to read an array of bytes using the following method:

arr = read_array(data, size, 'unsigned_short')

This will read a sequence of length size of unsigned ints, size * 2 bytes in total (short type is of 2 bytes).

Metadata

Release files for byter 0.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 byter 0.0.2
File Size Uploaded
byter-0.0.2.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for byter 0.0.2
File Interpreter ABI Platform
byter-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 13.5 kB

Release files / byter-0.0.2.tar.gz

Download URL byter-0.0.2.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
4331d01f175ba399110f1efcfd4f09bf341c768b5ae9128de88ccb5506ff5a44
BLAKE2b-256 checksum
How to use checksums
5d76ec9a6acc63f7c37a98966bb13fc566e56ce933fd15020569951c944f03d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.7

Release files / byter-0.0.2-py3-none-any.whl

Download URL byter-0.0.2-py3-none-any.whl
Size 9.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7e351bedfc60d4c2072b6680adc759fc3c4be088d5072f513cd4f75c39741fcd
BLAKE2b-256 checksum
How to use checksums
946f1402d7d432a1d0d3ca77e2bbdc00ba625442ce7f08516b1448fa527aa4ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.7

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

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