https://github.com/boisgera/bitstream
Binary Data for Humans
https://github.com/boisgera/bitstream
binary-data bitstream python
Last synced: 14 days ago
JSON representation
Binary Data for Humans
- Host: GitHub
- URL: https://github.com/boisgera/bitstream
- Owner: boisgera
- License: mit
- Created: 2013-05-02T11:19:52.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2023-09-24T17:20:38.000Z (over 1 year ago)
- Last Synced: 2025-05-03T06:02:35.596Z (18 days ago)
- Topics: binary-data, bitstream, python
- Language: Cython
- Homepage: https://boisgera.github.io/bitstream
- Size: 915 KB
- Stars: 94
- Watchers: 6
- Forks: 14
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- Contributing: docs/contributing/index.html
- License: LICENSE.txt
Awesome Lists containing this project
README

[](https://pypi.python.org/pypi/bitstream)
[](https://pepy.tech/project/bitstream)
[](http://boisgera.github.io/bitstream)
[](http://joss.theoj.org/papers/dd351bf2ed414a623557bb51d75b2536)
[](https://travis-ci.org/boisgera/bitstream)
[](https://ci.appveyor.com/project/boisgera/bitstream)# Bitstream
A Python library to manage binary data as [bitstreams](https://en.wikipedia.org/wiki/Bitstream).
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](http://boisgera.github.io/bitstream)
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
[pip]: https://packaging.python.org/tutorials/installing-packages/#install-pip-setuptools-and-wheel
For more details, refer to [the documentation](http://boisgera.github.io/bitstream/installation/).
Examples
--------------------------------------------------------------------------------First, the mandatory "Hello World!" example:
>>> from bitstream import BitStream
>>> BitStream(b"Hello World!")
010010000110010101101100011011000110111100100000010101110110111101110010011011000110010000100001The 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() #
>>> 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) #
b'AB'Refer to the documentation [Overview](http://boisgera.github.io/bitstream/)
section for more elementary examples.Contributing
--------------------------------------------------------------------------------Refer to [Contributing](http://boisgera.github.io/bitstream/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](http://boisgera.github.io/bitstream/),
please open an issue in the
[GitHub issue tracker](https://github.com/boisgera/bitstream/issues).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](https://github.com/boisgera).In both cases, you will need to sign into GitHub
(and [join GitHub](https://github.com/join) if you
don't already have an account).License
--------------------------------------------------------------------------------Bitstream is open source software released under the [MIT license](https://github.com/boisgera/bitstream/blob/master/LICENSE.txt).
Copyright (c) 2012-2023 Sébastien Boisgérault