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.6.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pybinary-0.9.6.tar.gz
Algorithm Hash digest
SHA256 b932be9afa7bdf91b62e2af21c058252a9fccab63d955ccbae4c6d69dfc01e92
MD5 32a880df0189f346cefd02a7bf315644
BLAKE2b-256 9c650153fb674a9246bee395ea5c0e579e4f1f6edf18becef9e4eb8a8030d51a

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pybinary-0.9.6-py3-none-any.whl
Algorithm Hash digest
SHA256 096393651dacbe8adbab32592522ccec98d07428a2e0676951760e1d0d7b7f6e
MD5 a691c33096a6f3b7530959f93714ff9f
BLAKE2b-256 735c831810546d8797c38c780121dfdc13c70b65be3f6eee37acc663ce69a9b9

See more details on using hashes here.

Supported by

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