A sleek Python library for binary data.
Project description
A sleek Python library for your binary data
[!NOTE] The project is currently in alpha. This documentation is incomplete.
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')
Mutibs('0xabde')
>>> m.replace([1], [0, 1, 0])
Mutibs('0b01000100010001001001001000100100100100')
Note that mutating methods like extend and replace also return the modified Mutibs instance.
This perhaps isn't the most Pythonic of interfaces, but it allows methods to be chained:
>>> m[:32].byte_swap().reverse().to_f()
2.1993814317305072e-18
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.
But why is it called tibs?
Because 'tibs' is (almost) 'bits' backwards, it's distinctive, and the name was available on PyPI. It's got nothing to do with Ethiopian stew.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tibs-0.5.0.tar.gz.
File metadata
- Download URL: tibs-0.5.0.tar.gz
- Upload date:
- Size: 3.2 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dad0ef7cadb122f9fe4710e408681faa06ab11811462c526e4fbe37e94fb8322
|
|
| MD5 |
b502a25540f5d63881d2c4b2b563eef3
|
|
| BLAKE2b-256 |
c1ee9bfe05df09e29d90ea02944552b0a49ae824e4f798a82b175c808fccda92
|
File details
Details for the file tibs-0.5.0-cp314-cp314t-win_amd64.whl.
File metadata
- Download URL: tibs-0.5.0-cp314-cp314t-win_amd64.whl
- Upload date:
- Size: 285.7 kB
- Tags: CPython 3.14t, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
319502e9be815c5fba6cb60bcb0d8f73f79ed3451102415e287bdf62b32b8965
|
|
| MD5 |
188c8affdc64eae4aeec3f169ebb51bb
|
|
| BLAKE2b-256 |
291541fb11910b10473c51cd017dfc067a8e1b6a478de5a69e4d3cb59a7a2501
|
File details
Details for the file tibs-0.5.0-cp314-cp314t-win32.whl.
File metadata
- Download URL: tibs-0.5.0-cp314-cp314t-win32.whl
- Upload date:
- Size: 270.0 kB
- Tags: CPython 3.14t, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b04915209550d09b12d7c0780d45ca294aaba44725543cb1086e37c04a10c3c2
|
|
| MD5 |
2b24bde7531bd30ec0e10009a59047b7
|
|
| BLAKE2b-256 |
b3bbb0bdfc4214672991a55547989d4c195b4575e967c92792a3117eb787009f
|
File details
Details for the file tibs-0.5.0-cp38-abi3-win_amd64.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-win_amd64.whl
- Upload date:
- Size: 295.7 kB
- Tags: CPython 3.8+, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbf1ef14474116ff60bea3dc19498f402c14dba434e06e8a6f1c0a5158c8471b
|
|
| MD5 |
c72f85158f96a8363b0e1a2193dbe76d
|
|
| BLAKE2b-256 |
cee3085c3aee42a2ab1b1fde1c0351d293a75590030f9b3aff25906abd7c497e
|
File details
Details for the file tibs-0.5.0-cp38-abi3-win32.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-win32.whl
- Upload date:
- Size: 279.4 kB
- Tags: CPython 3.8+, Windows x86
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1987dab429cf715e0f835515ce6c0c16ad6633eefd88d44ebe5bad9bea405cc
|
|
| MD5 |
738fe17b72a9070e70b867dcd7ef7dc4
|
|
| BLAKE2b-256 |
499e148f5cc2c1a11008e6518d2cddb395d7d9c4b8d146811d2b990a2a83fadc
|
File details
Details for the file tibs-0.5.0-cp38-abi3-musllinux_1_2_x86_64.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-musllinux_1_2_x86_64.whl
- Upload date:
- Size: 488.3 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35bdd071806059c6d0e43f37679112feca0fc351b283f9efbba973daf90c1b37
|
|
| MD5 |
fd9426acfe354cea093b092f26c3e4ee
|
|
| BLAKE2b-256 |
aa060067f6427492cddb870b7c2b3a7b8d7cfdf3f2fa27cec3a7d989f0d43643
|
File details
Details for the file tibs-0.5.0-cp38-abi3-musllinux_1_2_ppc64le.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-musllinux_1_2_ppc64le.whl
- Upload date:
- Size: 483.4 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2283598645082d6440c10087935041b992bb15544452042c6e2ab26c67eee579
|
|
| MD5 |
1354ef3d04e889836a0bb2a505c08c14
|
|
| BLAKE2b-256 |
9e789442714f7f25afd4674d5e54fd8127035cdb702e9585d8a6d7cf81f7e0bb
|
File details
Details for the file tibs-0.5.0-cp38-abi3-musllinux_1_2_aarch64.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-musllinux_1_2_aarch64.whl
- Upload date:
- Size: 463.2 kB
- Tags: CPython 3.8+, musllinux: musl 1.2+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
771cca4e065ee87bf260873ba857b89fe4ac0de1ece2f57517e9b45cb043da12
|
|
| MD5 |
69020debf6c3060766d9b1b60bbe4bc1
|
|
| BLAKE2b-256 |
e6344ce0cd2513bbe61a020364399872e1e1d753b9a549c353166bda56fe333e
|
File details
Details for the file tibs-0.5.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
- Upload date:
- Size: 406.7 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
87f8bc3fe677ba979b49928cfb6214c672d599ebe47458d48ea8c50b31465979
|
|
| MD5 |
6577309366d4aa65e4ece3fd6ba8e8fe
|
|
| BLAKE2b-256 |
6ab6d78f77f9f6cba2b898b8f92c7dca43ad7ac98d5af7df09823cb82d662cfb
|
File details
Details for the file tibs-0.5.0-cp38-abi3-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-manylinux2014_ppc64le.manylinux_2_17_ppc64le.whl
- Upload date:
- Size: 441.6 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ppc64le
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad3eef17344b5dd80cf14491d3d690b3c39c6c43d51361138f7a7e9b3fb358b3
|
|
| MD5 |
3d409677c41d689371c8abea04ed5ed4
|
|
| BLAKE2b-256 |
5f5e80bc5e54d26d7ed669a101d63b8b1f94bb9691ec41278dff3203b080f4f3
|
File details
Details for the file tibs-0.5.0-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
- Upload date:
- Size: 397.2 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfefa9e8fbc0dcb0bfaa8eb2050451ca34b86e36c6402803c6d28a84220b2ced
|
|
| MD5 |
51d0958627d9fa08838038ae90b2c135
|
|
| BLAKE2b-256 |
fd244bd93fa27c21578ddd9318404ccf3a5f49c24c47f5cec76230d483d29f6f
|
File details
Details for the file tibs-0.5.0-cp38-abi3-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-manylinux1_i686.manylinux2014_i686.manylinux_2_17_i686.manylinux_2_5_i686.whl
- Upload date:
- Size: 433.9 kB
- Tags: CPython 3.8+, manylinux: glibc 2.17+ i686, manylinux: glibc 2.5+ i686
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
91d7d03a6c103740ebe1075a6dcab70cfea943026c6d0e5ea01239bfa874e59c
|
|
| MD5 |
8ab1eacfe2d9aa4d3ee7202a880e2dd7
|
|
| BLAKE2b-256 |
951276c4b17a3ddcba0b2879db29649e7292e621065fecd4125c2844fc2eb523
|
File details
Details for the file tibs-0.5.0-cp38-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: tibs-0.5.0-cp38-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 366.8 kB
- Tags: CPython 3.8+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
144a2a9656a3688ecdc19486e32d38b81bcc497baf55b8b9bbedd896e842bf08
|
|
| MD5 |
6e3d5496ea9edf4afb32b77b69ea5277
|
|
| BLAKE2b-256 |
f2045832d35947dedf11550acbab261b1a513c4d59f7e02c50ce161a9831e367
|