tibs 0.6.0


pip install tibs

  Latest version

Released: Apr 03, 2026


Meta
Author: Scott Griffiths
Requires Python: >=3.8

Classifiers

Development Status
  • 4 - Beta

Intended Audience
  • Developers

Operating System
  • OS Independent

Programming Language
  • Python :: 3.8
  • Python :: 3.9
  • Python :: 3.10
  • Python :: 3.11
  • Python :: 3.12
  • Python :: 3.13
  • Python :: 3.14
  • Rust
  • Python :: Implementation :: CPython

License
  • OSI Approved :: MIT License

Topic
  • Software Development :: Libraries :: Python Modules

Typing
  • Typed

tibs

A sleek Python library for your binary data

PyPI - Version CI badge Docs PyPI - License     PyPI - Downloads


tibs is a simple but powerful Python library for creating, interpreting and manipulating binary data. It is 100% written in Rust to give it excellent performance, and is from the same author as the bitstring library.

Documentation

The full documentation is available on Read the Docs.

Getting started

To install use

pip install tibs

There are pre-built wheels for most configurations - if there are issues then please let me know. Tibs works with Python 3.8 and later.

One way to get to know the library is to start a Python interactive session, import the two main classes, and experiment with some of the example code in the rest of this document.

>>> from tibs import Tibs, Mutibs

A quick tour

There are two classes:

  • Tibs: An immutable sequence of bits.
  • Mutibs: A mutable sequence of bits (pronounced 'mew-tibs').

They are created by class methods starting with from_, for example

>>> a = Tibs.from_bin('0110')
>>> b = Tibs.from_hex('abc')
>>> c = Tibs.from_string('0xfee, 0b11001')
>>> d = Tibs.from_bytes(b'some_byte_data')
>>> e = Tibs.from_random(1000)  # 1000 random bits
>>> f = Tibs.from_u(76, 25)  # Unsigned int stored in 25 bits
>>> g = Tibs.from_f(-0.125, 16)  # A float stored in 16 bits
>>> h = Tibs.from_bools([1, 0, 0])
>>> i = Tibs.from_joined([a, b, c, d, e, f, g, h])

Once created they are just binary data, stored efficiently, and they don't retain any information about how they were created.

The Tibs constructor can also be used to create new instances, and it will delegate to from_string, from_bytes or from_bools. This is often more convenient:

>>> a = Tibs('0b0110')
>>> b = Tibs('0xabc')
>>> c = Tibs('0xfee, 0b11001')
>>> d = Tibs(b'some_byte_data')
>>> h = Tibs([1, 0, 0])

Anything that works in the constructor can also be used in other places where a Tibs is needed. For example, instead of writing

x = b & Tibs.from_hex('0xff0')
if x.starts_with(Tibs.from_bin('0b11')):
    x += Tibs.from_bools([0, 1, 1])

you can write just

x = b & '0xff0'
if x.starts_with('0b11'):
    x += [0, 1, 1]

Note that the binary and hex strings need the 0b and 0x prefixes when not called via from_bin and from_hex.

To get the data out of the Tibs there are similar methods starting with to_

>>> a.to_bin()
'0110'
>>> b.to_hex()
'abc'
>>> d.to_bytes()
b'some_byte_data'
>>> f.to_u()
76
>>> g.to_f()
-0.125

There isn't a to_bools method, but creating a list from the Tibs instance will have the same effect. You can also use Tibs instances as iterators of bits.

Instances of Tibs are immutable. Once created they can't change in value, much like the Python bytes and str types. This allows them to be hashed, stored in sets, used as dictionary keys etc., and also allows various optimizations to be used to make them more efficient. They should be used by default if values don't need to be changed.

This does mean that the standard pieces of advice for working with things like Python strings does apply, and why something like this line:

i = Tibs()
for t in [a, b, c, d, e, f, g, h]:
    i += t  # NOT RECOMMENDED!

is an anti-pattern to avoid as it will create a new instance every time it appends. Use from_joined instead.

For the times when you do need a mutable container use Mutibs. This can do everything that Tibs can do, except that it's not hashable, so can't be used as a dictionary key, in sets etc. It also has several extra methods that will mutate the value in-place.

>>> m = Mutibs()
>>> m.extend('0xabde')
>>> m
Mutibs('0xabde')
>>> m.replace([1], [0, 1, 0])
>>> m
Mutibs('0b01000100010001001001001000100100100100')

You can do everything you'd expect with these classes - slicing, boolean operations, shifting, rotating, finding, replacing, setting, reversing etc.

For more information see the full documentation.

Wheel compatibility matrix

Platform CPython >=3.8 (abi3) CPython (additional flags: t) 3.14
macosx_10_12_x86_64
macosx_11_0_arm64
manylinux1_i686
manylinux2014_aarch64
manylinux2014_armv7l
manylinux2014_ppc64le
manylinux2014_s390x
manylinux2014_x86_64
manylinux_2_17_aarch64
manylinux_2_17_armv7l
manylinux_2_17_ppc64le
manylinux_2_17_s390x
manylinux_2_17_x86_64
manylinux_2_5_i686
musllinux_1_2_aarch64
musllinux_1_2_armv7l
musllinux_1_2_i686
musllinux_1_2_x86_64
win32
win_amd64
win_arm64

Files in release

tibs-0.6.0-cp314-cp314t-macosx_10_12_x86_64.whl (415.4KiB)
tibs-0.6.0-cp314-cp314t-macosx_11_0_arm64.whl (388.9KiB)
tibs-0.6.0-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (424.0KiB)
tibs-0.6.0-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (440.5KiB)
tibs-0.6.0-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (461.1KiB)
tibs-0.6.0-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl (468.5KiB)
tibs-0.6.0-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (434.1KiB)
tibs-0.6.0-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl (464.6KiB)
tibs-0.6.0-cp314-cp314t-musllinux_1_2_aarch64.whl (596.2KiB)
tibs-0.6.0-cp314-cp314t-musllinux_1_2_armv7l.whl (709.7KiB)
tibs-0.6.0-cp314-cp314t-musllinux_1_2_i686.whl (672.8KiB)
tibs-0.6.0-cp314-cp314t-musllinux_1_2_x86_64.whl (641.4KiB)
tibs-0.6.0-cp314-cp314t-win32.whl (297.7KiB)
tibs-0.6.0-cp314-cp314t-win_amd64.whl (313.6KiB)
tibs-0.6.0-cp314-cp314t-win_arm64.whl (289.2KiB)
tibs-0.6.0-cp38-abi3-macosx_10_12_x86_64.whl (426.3KiB)
tibs-0.6.0-cp38-abi3-macosx_11_0_arm64.whl (396.1KiB)
tibs-0.6.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (429.6KiB)
tibs-0.6.0-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (442.5KiB)
tibs-0.6.0-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (466.2KiB)
tibs-0.6.0-cp38-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (474.3KiB)
tibs-0.6.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (437.6KiB)
tibs-0.6.0-cp38-abi3-manylinux_2_5_i686.manylinux1_i686.whl (467.4KiB)
tibs-0.6.0-cp38-abi3-musllinux_1_2_aarch64.whl (601.9KiB)
tibs-0.6.0-cp38-abi3-musllinux_1_2_armv7l.whl (711.9KiB)
tibs-0.6.0-cp38-abi3-musllinux_1_2_i686.whl (676.4KiB)
tibs-0.6.0-cp38-abi3-musllinux_1_2_x86_64.whl (644.8KiB)
tibs-0.6.0-cp38-abi3-win32.whl (307.4KiB)
tibs-0.6.0-cp38-abi3-win_amd64.whl (324.1KiB)
tibs-0.6.0-cp38-abi3-win_arm64.whl (298.5KiB)
tibs-0.6.0.tar.gz (84.1KiB)
Extras:
Dependencies: