Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 4.4.0 instead.
Reason given by maintainers: Misconfigured Python version support. Newer version now available.

bitstring is a pure Python module designed to help make the creation and analysis of binary data as simple and natural as possible.

Bitstrings can be constructed from integers (big and little endian), hex, octal, binary, strings or files. They can be sliced, joined, reversed, inserted into, overwritten, etc. with simple functions or slice notation. They can also be read from, searched and replaced, and navigated in, similar to a file or stream.

bitstring is open source software, and has been released under the MIT licence.

bitstring version 4 onwards only supports Python 3.7 and later. Use bitstring version 3 if you’re using Python 2.7 or 3.6 or earlier.

Installation

Probably all you need to do is:

pip install bitstring

Documentation

The manual for the bitstring module is available here <https://bitstring.readthedocs.org>. It contains a walk-through of all the features and a complete reference section.

Simple Examples

Creation:

>>> a = BitArray(bin='00101')
>>> b = Bits(a_file_object)
>>> c = BitArray('0xff, 0b101, 0o65, uint:6=22')
>>> d = pack('intle:16, hex=a, 0b1', 100, a='0x34f')
>>> e = pack('<16h', *range(16))

Different interpretations, slicing and concatenation:

>>> a = BitArray('0x1af')
>>> a.hex, a.bin, a.uint
('1af', '000110101111', 431)
>>> a[10:3:-1].bin
'1110101'
>>> '0b100' + 3*a
BitArray('0x835e35e35, 0b111')

Reading data sequentially:

>>> b = BitStream('0x160120f')
>>> b.read(12).hex
'160'
>>> b.pos = 0
>>> b.read('uint:12')
352
>>> b.readlist('uint:12, bin:3')
[288, '111']

Searching, inserting and deleting:

>>> c = BitArray('0b00010010010010001111')   # c.hex == '0x1248f'
>>> c.find('0x48')
(8,)
>>> c.replace('0b001', '0xabc')
>>> c.insert('0b0000', pos=3)
>>> del c[12:16]

Unit Tests

The 500+ unit tests should all pass. To run them, from the test directory run:

python -m unittest discover

The bitstring module has been released as open source under the MIT License. Copyright (c) 2006 Scott Griffiths

For more information see the project’s homepage on GitHub: <https://github.com/scott-griffiths/bitstring>

Download files

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

Source Distribution

bitstring-4.0.0b1.tar.gz (199.6 kB view details)

Uploaded Source

Built Distribution

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

bitstring-4.0.0b1-py3-none-any.whl (40.5 kB view details)

Uploaded Python 3

File details

Details for the file bitstring-4.0.0b1.tar.gz.

File metadata

  • Download URL: bitstring-4.0.0b1.tar.gz
  • Upload date:
  • Size: 199.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for bitstring-4.0.0b1.tar.gz
Algorithm Hash digest
SHA256 428cc56e3d13a0426062a45492eb07c5101992bd2cf14f2a17776b090102d5c7
MD5 78a459a8414631130ba6164395ba5e8c
BLAKE2b-256 d3f30e9dfdd80083dcb4f46d2ecb43df01b5ab9b8c9a474bf2be61407ecfc3b0

See more details on using hashes here.

File details

Details for the file bitstring-4.0.0b1-py3-none-any.whl.

File metadata

  • Download URL: bitstring-4.0.0b1-py3-none-any.whl
  • Upload date:
  • Size: 40.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.5

File hashes

Hashes for bitstring-4.0.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 aa7f6bb89cfff1b398100680df3fa267c9425ac53b9b539dd69008d6504523f5
MD5 9e3a7fa0cc9f2dcc0977a04708d4d9ef
BLAKE2b-256 b2669167e54fc75a5c071e7478987281c21076f253c80ff2c5f65570a9e99874

See more details on using hashes here.

Release history Release notifications | RSS feed

4.4.0

2 files

4.3.1

2 files

4.3.0

2 files

4.2.3

2 files

4.2.2

2 files

4.2.1

2 files

4.2.0

2 files

4.1.4

2 files

4.1.3

2 files

4.1.2

2 files

4.1.1

2 files

4.1.0

2 files

4.0.2

2 files

4.0.1

2 files

4.0.0

2 files

This release

4.0.0b1 This release

2 files

3.1.9

3 files

3.1.8

3 files

3.1.7

1 file

3.1.6

3 files

3.1.5

1 file

3.1.4

1 file

3.1.3

3.1.2

1 file

3.1.1

1 file

3.1.0

1 file

3.0.2

1 file

3.0.1

1 file

3.0.0

1 file

2.2.0

1 file

2.1.1

1 file

2.1.0

1 file

2.0.3

1 file

2.0.2

1 file

1.3.0

1 file

1.2.0

1 file

1.1.3

1 file

1.1.2

1 file

1.1.1

1 file

1.1.0

1 file

1.0.0

1 file

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.3

1 file

0.4.2

1 file

0.4.0

2 files

0.3.2

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page