Skip to main content

Python PyPI version Downloads Mkdocs status Travis Build Status Appveyor Build status

Bitstream

A Python library to manage binary data as bitstreams.

Overview

Bitstream three main features:

  • It is easy to use since the bitstream abstraction is simple.

  • It works seamlessly at the bit and byte level.

  • It supports Python, NumPy and user-defined types.

See the documentation Overview section for more details.

Quickstart

Make sure that Python 2.7 or Python 3.6 to 3.9 are installed and that pip, NumPy and a C compiler are available, then install bitstream with

$ pip install bitstream

For more details, refer to the documentation.

Examples

First, the mandatory “Hello World!” example:

>>> from bitstream import BitStream
>>> BitStream(b"Hello World!")
010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001

The basic API is made of three methods only:

  • stream = BitStream() to create an empty stream.

  • stream.write(data, type) to write data data of type type.

  • data = stream.read(type, n) to read n items of type type.

For example:

>>> stream = BitStream()        # <empty>
>>> stream.write(True, bool)    # 1
>>> stream.write(False, bool)   # 10
>>> from numpy import int8
>>> stream.write(-128, int8)    # 1010000000
>>> stream.write(b"AB", bytes)  # 10100000000100000101000010
>>> stream.read(bool, 2)        # 100000000100000101000010
[True, False]
>>> stream.read(int8, 1)        # 0100000101000010
array([-128], dtype=int8)
>>> stream.read(bytes, 2)       # <empty>
b'AB'

Refer to the documentation Overview section for more elementary examples.

Contributing

Refer to Contributing in the documentation.

Support

If you need some support with bitstream and you haven’t found a solution to your problem in the documentation, please open an issue in the GitHub issue tracker.

If you don’t feel like you problem belongs there, you can send me an e-mail instead; please include “bitstream” in the subject. You will find my e-mail address in my GitHub profile.

In both cases, you will need to sign into GitHub (and join GitHub if you don’t already have an account).

License

Bitstream is open source software released under the MIT license.

Copyright (c) 2012-2021 Sébastien Boisgérault

Release files for bitstream 3.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bitstream 3.0.1
File Size Uploaded
bitstream-3.0.1.tar.gz 210.3 kB Details

Release files / bitstream-3.0.1.tar.gz

Download URL bitstream-3.0.1.tar.gz
Size 210.3 kB
Tags Source
SHA-256 checksum
How to use checksums
dfd7aa4f87ce339f080b1462c2d2401c6cac5f190cb97d84353070d6c55cab1d
BLAKE2b-256 checksum
How to use checksums
85bc60cc42dbc7d2ab0ff6caefd1a28c322f8c769261c48f1e67fd727c01e5fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.4

Release history Release notifications | RSS feed

This release

3.0.1 This release

1 release file

3.0

1 release file

2.6.0.2

1 release file

2.6.0.1

1 release file

2.6.0

1 release file

2.5.4

1 release file

2.5.3

1 release file

2.5.2

1 release file

2.5.1

1 release file

2.5.0

1 release file

2.4.0

1 release file

2.2.0

1 release file

2.0.3

1 release file

2.0.2

1 release file

2.0.1

1 release file

2.0.0

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.0.0.dev

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