Skip to main content

Python bindings for the Rust implementation of read/write bit streams supporting several types of instantaneous codes

Project description

dsi-bitstream-py

GitHub CI license Supported Python versions Pypi total project downloads Pypi project

Python bindings of dsi-bitstream-rs

Install with:

pip install dsi_bitstream

Example:

from dsi_bitstream import BitReaderLittleEndian, BitWriterLittleEndian

writer = BitWriterLittleEndian("./bitstream.bin")

# all write methods return how many bits were written
writer.write_bits(10, n = 5) # write 10 as 5 bits 
writer.write_unary(100)
writer.write_gamma(10)
writer.write_delta(2)
writer.write_rice(3, k=4)
writer.write_golomb(4, k=10)
writer.write_zeta(10, k=3)
writer.write_exp_golomb(100, k=3)
writer.write_minimal_binary(10, max=100)
writer.flush()

reader = BitReaderLittleEndian("./bitstream.bin")
assert reader.read_bits(n = 5) == 10
assert reader.read_unary() == 100
assert reader.read_gamma() == 10
print(reader.bit_pos()) # bits from the start of the file (here 497)
assert reader.read_delta() == 2
assert reader.read_rice(k=4) == 3
assert reader.read_golomb(k=10) == 4
assert reader.read_zeta(k=3) == 10
assert reader.read_exp_golomb(k=3) == 100
assert reader.read_minimal_binary(max=100) == 10

# the reader can seek in the file, while the writer cannot.
reader.set_bit_pos(497)
assert reader.read_delta() == 2
assert reader.read_rice(k=4) == 3
assert reader.read_golomb(k=10) == 4
assert reader.read_zeta(k=3) == 10
assert reader.read_exp_golomb(k=3) == 100
assert reader.read_minimal_binary(max=100) == 10

Building

To publish on pypi for linux:

docker run --rm -v $PWD:/io ghcr.io/pyo3/maturin build --release

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

dsi_bitstream-0.1.0.tar.gz (22.0 kB view hashes)

Uploaded Source

Built Distributions

dsi_bitstream-0.1.0-cp37-abi3-win_amd64.whl (169.4 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

dsi_bitstream-0.1.0-cp37-abi3-win32.whl (169.9 kB view hashes)

Uploaded CPython 3.7+ Windows x86

dsi_bitstream-0.1.0-cp37-abi3-musllinux_1_1_x86_64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.1+ x86-64

dsi_bitstream-0.1.0-cp37-abi3-musllinux_1_1_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.1+ i686

dsi_bitstream-0.1.0-cp37-abi3-musllinux_1_1_aarch64.whl (1.2 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.1+ ARM64

dsi_bitstream-0.1.0-cp37-abi3-macosx_11_0_arm64.whl (275.3 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

dsi_bitstream-0.1.0-cp37-abi3-macosx_10_12_x86_64.whl (279.9 kB view hashes)

Uploaded CPython 3.7+ macOS 10.12+ x86-64

Supported by

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