Skip to main content

Binary Data for Humans

Project description

Python PyPI version 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 seamlesly 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 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-2020 Sébastien Boisgérault

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

bitstream-2.6.0.tar.gz (161.5 kB view details)

Uploaded Source

File details

Details for the file bitstream-2.6.0.tar.gz.

File metadata

  • Download URL: bitstream-2.6.0.tar.gz
  • Upload date:
  • Size: 161.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.0.0.post20201207 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for bitstream-2.6.0.tar.gz
Algorithm Hash digest
SHA256 beb3b23b4d8a33d6c57d9e373952d804805d1e914cd54719b160686d3137cc4d
MD5 0a310fb19eded58850c40431f242a15a
BLAKE2b-256 9f825da301d8a1e8bf1a6c8e011cad3565fea43692bb527794a35f966e9eb1c0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page