Registry / serialization / bitarray

bitarray

JSON →
library3.10.1pypypi✓ verified 25d ago

Efficient boolean arrays implemented as a C extension for Python. Provides bit-level operations, packed representations, and performance comparable to NumPy for bit manipulation. Current version 2.3.8. Released under PSF license.

pip install bitarray
INSTALL
IMPORT
SIG · BITARRAY
B
bitarray
serializationpythonv3.10.1
Install
2.1s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.10.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.1s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Bitarray
from bitarray import bitarray
from bitarray import Bitarray
Class name is lowercase 'bitarray'.
bitarray
from bitarray import bitarray
import bitarray
While 'import bitarray' works, you need to use 'bitarray.bitarray()'. Direct import of the class is common.

Create bitarrays, perform bitwise operations, and convert to bytes.

from bitarray import bitarray # Create a bitarray of 8 zero bits a = bitarray(8) print('Length:', len(a)) # 8 # Set bits from a binary string a = bitarray('11001010') print(a) # bitarray('11001010') # Bitwise operations b = bitarray('11110000') c = a & b print(c) # bitarray('11000000') # Convert to bytes packed = a.tobytes() print('Bytes:', packed)
Debug
Known issues
breakingbitarray objects are not hashable. Attempting to use them as dictionary keys or in sets will raise TypeError.
fix
Convert to bytes or tuple for hashing, e.g., key = a.tobytes()
affects: all
deprecatedThe 'bitarray.endian()' method is deprecated in favor of the 'endian' property in version 2.0+.
fix
Use 'bitarray.endian' (property) instead of 'bitarray.endian()' (method).
affects: >=2.0,<3.0
gotchaWhen creating a bitarray from an integer, the integer is treated as the length (number of bits), not as the initial bits. bitarray(8) creates 8 zero bits, not a bitarray with one bit set at position 3.
fix
Use bitarray('111') for specific bits or bitarray(8) for an all-zero array of given length.
affects: all
gotchaThe 'count()' method with 'value' parameter default is 1. bitarray('110').count() returns 2 (counts 1s). Use count(0) to count zeros.
fix
Explicitly pass value=0 for zero count: mybitarray.count(0).
affects: all
Errors
Common errors & fixes
TypeError: 'bitarray' object is not callable
Trying to call a bitarray object as a function, e.g., a() instead of a[index].
fix
Use indexing to access bits: bit = a[0]
ValueError: bitarray must not contain whitespace
Constructing bitarray from a string that contains spaces or other invalid characters.
fix
Remove whitespace: bitarray('11001010') not bitarray('1100 1010')
ImportError: cannot import name 'bitarray' from 'bitarray'
Incorrect import attempt or missing installation/conflict with another package named bitarray.
fix
Use 'from bitarray import bitarray'. If you already installed, check for version conflicts: 'pip install --upgrade bitarray'
Upgrade
Version history
3.10.1latest on PyPI · released Aug 7, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources