Skip to main content

Better binary serialization for python

Project description

pybinary

A simple binary serializer/deserializer in pure python.

Limitations

Variable-sized fields are not supported. No size check on assignment for the most of the types.

Installation

Install from pypi:

pip install pybinary

Or download the repository and build from the sources:

python3 ./setup.py build
python3 ./setup.py install

Examples

ELF64 header

Spec taken from https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html

class Elf64_Ehdr(BinarySerializable):
    e_ident = ArrayTypes.bytearray(16)
    e_type = Types.u16
    e_machine = Types.u16
    e_version = Types.u32
    e_entry = Types.u64
    e_phoff = Types.u64
    e_shoff = Types.u64
    e_flags = Types.u32
    e_ehsize = Types.u16
    e_phentsize = Types.u16
    e_phnum = Types.u16
    e_shentsize = Types.u16
    e_shnum = Types.u16
    e_shstrndx  = Types.u16


header = Elf64_Ehdr.deserialize(input_stream_or_bytes) # deserialize header
header.e_phnum += 1 # update any field
header.serialize() # serialize and get updated bytes
...

CPIO Newc ACII Format Archive

Spec taken from https://manpages.ubuntu.com/manpages/bionic/man5/cpio.5.html

Code here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybinary-0.9.5.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

pybinary-0.9.5-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file pybinary-0.9.5.tar.gz.

File metadata

  • Download URL: pybinary-0.9.5.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for pybinary-0.9.5.tar.gz
Algorithm Hash digest
SHA256 a37981ab22c927cf43d5ccf825988f9be105a324a2c0d5ca5c0a1684c73974cf
MD5 3c1c00644f5c6e03ca55831364d89cc4
BLAKE2b-256 db0aff0908e73fcec201ad80a0bbddc3e4bb0a273edb6717dc5feabe793a043c

See more details on using hashes here.

File details

Details for the file pybinary-0.9.5-py3-none-any.whl.

File metadata

  • Download URL: pybinary-0.9.5-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for pybinary-0.9.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1dd145ad59bfeb2243048cd3d438a9845ef3243c6e802ef9f84fdf68136fcb55
MD5 614dcfaf79d93cb815b226c2800c65fb
BLAKE2b-256 eab6eb2c91653d87017c4189d0f580c179b1fbd54207e94a8b32fd6c663b2ff4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page