bitstring
Simple construction, analysis and modification of binary data.
What it is and what it does
bitstring is a Python library for working with binary data at the bit level. It lets you create bitstrings from hex, octal, binary, bytes, integers, floats, and files, then manipulate them through slicing, searching, replacing, and packing operations. The library provides idiomatic Python classes (Bits, BitArray, BitStream) and utility functions, making bit-level work feel natural rather than low-level.
The package is production-stable and has been actively maintained since 2006. It depends on bitarray and tibs (a newer Rust-based rewrite of the core, currently in beta). The library supports Python 3.8 through 3.14 and is widely used—it ranks in the top 5000 PyPI packages by download volume. It's particularly useful for tasks like binary protocol parsing, data serialization, and bit manipulation in embedded or network contexts.
Use it for:
- Parse binary network protocols or file formats by creating bitstrings from hex/binary and extracting fields via bit-level slicing.
- Pack and unpack structured binary data (e.g., multi-format fields) using the pack function with endianness control.
- Search for and replace bit patterns within binary data, useful for binary data transformation pipelines.
- Read and interpret binary streams sequentially, tracking position and reading typed chunks (uint, float, etc.).
- Create and manipulate arrays of fixed-length bitstrings for efficient storage of homogeneous binary records.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
bitstring provides Python classes and functions to create, manipulate, and interpret binary data at the bit level, with support for multiple input formats and bit-level operations like slicing, searching, and packing.
Yes. bitstring is production-stable, actively maintained, has no known vulnerabilities, and low install friction. It's the standard choice for bit-level binary manipulation in Python. Install it if you need to work with binary protocols, data formats, or bit-level operations; the API is well-documented and the library is widely trusted in the community.
Install
bitstring on PyPI
pip
pip install bitstringuv
uv add bitstringpoetry
poetry add bitstringInstalling bitstring
Before you install
Low install friction with a pure-Python wheel distribution. Actively maintained since 2006 with a recent release 157 days ago; the project has 446 repository stars and remains under active development.
License in practice
Released under the MIT license (permissive), which permits commercial and private use with minimal restrictions—suitable for most projects without licensing concerns.
Quickstart
pip install bitstring
from bitstring import BitArray, Bits, pack
a = BitArray(bin='00101')
b = Bits('0xff, 0b101, 0o65')
c = pack('intle16, hex=a', 100, a='0x34f')
print(a.hex, a.bin, a.uint)
Verify before relying
- Performance characteristics when handling very large binary datasets or streaming scenarios.
- Compatibility guarantees between bitstring and its new Rust-based sibling tibs package.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — bitarray, tibs |
| Maintenance | actively maintained — 157 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,910,491/month — #2,014 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: bitstring-4.4.0-py3-none-any.whl
Keywords: binary, bitarray, bitvector, bitfield
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
bitmapBitMap provides a compact bit array class for…
unclear · top 15,000 on PyPI
bitstructPacks and unpacks Python values into bit-level…
permissive · top 5,000 on PyPI
tibsTibs provides immutable and mutable bit-level…
permissive · top 5,000 on PyPI
bitarray-hardbyteProvides an efficient C-backed array type for…
permissive · top 15,000 on PyPI
bitarrayProvides an efficient C-backed array type for…
permissive · top 1,000 on PyPI
hachoirHachoir parses and displays binary files as a…
copyleft · top 15,000 on PyPI
cbitstructA C-accelerated implementation of the bitstruct…
copyleft · top 15,000 on PyPI
intelhexRead, write, and manipulate Intel HEX files, a…
permissive · top 5,000 on PyPI
PyByteBufferPyByteBuffer provides Java ByteBuffer-style…
copyleft · top 5,000 on PyPI
fixedintProvides fixed-width integer classes that…
permissive · top 5,000 on PyPI