cbitstruct
Faster C implementation of bitstruct
What it is and what it does
cbitstruct is a C-based reimplementation of the bitstruct library, designed to parse and serialize binary data (bit fields, packed structs, protocol messages) much faster than the pure-Python version. It provides the same API—pack, unpack, pack_into, unpack_from, and compiled format objects—so you can often swap it in as a drop-in replacement by changing the import statement.
The tradeoff is that cbitstruct has real limitations: fields are capped at 64 bits (except padding), it only runs on CPython, error messages are less helpful, and it may not work on big-endian systems. The description notes that exceptions differ from bitstruct and some limitations are unlikely to be lifted. It's best suited for performance-critical code paths where you're already familiar with bitstruct and need the speed boost.
Use it for:
- Parsing binary network protocols or packet formats where speed matters and fields fit within 64 bits.
- Serializing structured data into compact binary form for storage or transmission in latency-sensitive applications.
- Unpacking embedded device telemetry or sensor data streams with high throughput requirements.
- Building compiled format objects for repeated pack/unpack cycles in tight loops.
- Migrating performance-critical bitstruct code to C acceleration without rewriting the logic.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A C-accelerated implementation of the bitstruct library that packs and unpacks binary data into Python objects with significantly higher performance than the pure-Python original.
Yes, if you are already using bitstruct and have identified bit packing/unpacking as a bottleneck in a CPython application on x86_64 Linux. The performance gains are substantial, and the API compatibility makes migration straightforward. No, if you need portability to other architectures, big-endian systems, or non-CPython implementations, or if you require clear error messages and full bitstruct feature parity. The copyleft license (MPL-2.0) also requires careful review if you plan to distribute derived works.
Install
cbitstruct on PyPI
pip
pip install cbitstructuv
uv add cbitstructpoetry
poetry add cbitstructInstalling cbitstruct
Before you install
Medium install friction due to compiled C extension wheels; prebuilt binaries are available for Python 3.8–3.14 on x86_64 Linux, but the package is aging (last release 186 days ago) with modest maintenance activity.
License in practice
Licensed under MPL-2.0 (copyleft); derivative works and modifications must be distributed under the same license, which may restrict commercial or proprietary use without disclosure.
Quickstart
pip install cbitstruct
import cbitstruct
# Pack integers into bits
packed = cbitstruct.pack('u8', 1)
# Unpack bits back to integers
unpacked = cbitstruct.unpack('u8', packed)
Requires CPython 3.8 or later; C extension wheels are available only for x86_64 Linux (manylinux2014 and later); other platforms or architectures require compilation from source.
Verify before relying
- Whether the performance gains reported in the test suite (ranging from 8× to 139× faster) hold for real-world workloads outside the benchmark.
- Whether the 64-bit field limit and potential big-endian architecture issues affect your use case.
- Current maintenance trajectory and whether limitations listed as 'Maybe' or 'Probably not' are likely to be addressed.
Package facts
| License | MPL-2.0 (copyleft) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | medium — platform-specific wheel |
| Runtime dependencies | none |
| Maintenance | aging — 186 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 223,422/month — #9,245 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cbitstruct-1.2.0-cp310-cp310-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; cbitstruct-1.2.0-cp311-cp311-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; cbitstruct-1.2.0-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; cbitstruct-1.2.0-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; cbitstruct-1.2.0-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; cbitstruct-1.2.0-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl; cbitstruct-1.2.0-cp39-cp39-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Keywords: bit, pack, unpack, struct, bitfield, bit parsing, bit unpack, bit pack, C
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
bitstructPacks and unpacks Python values into bit-level…
permissive · top 5,000 on PyPI
plum-pyTransforms byte sequences into Python objects…
permissive · top 15,000 on PyPI
bitstringbitstring provides Python classes and functions…
permissive · top 5,000 on PyPI
pycstructConverts binary data to and from Python…
permissive · top 15,000 on PyPI
dissect.cstructParse binary data using C-like structure…
permissive · top 15,000 on PyPI
tibsTibs provides immutable and mutable bit-level…
permissive · top 5,000 on PyPI
msgpackmsgpack serializes and deserializes Python…
permissive · top 1,000 on PyPI
bitarrayProvides an efficient C-backed array type for…
permissive · top 1,000 on PyPI
fdtParses, manipulates, and converts between…
permissive · top 15,000 on PyPI
PyByteBufferPyByteBuffer provides Java ByteBuffer-style…
copyleft · top 5,000 on PyPI