Skip to main content

version pytest license monthly-downloads Code style: black

Bit Vectors For Humans™

This simple bit vector implementation aims to make addressing single bits a little less fiddly. It can be used by itself to work with bit fields in an integer word, but it really starts to shine when you use the supplied BitField descriptor with a subclass of BitVector:

> from bitvector import BitVector, BitField
>
> class IOTDeviceCommand(BitVector):
>     def __init__(self):
>         super().__init__(size=32)
>
>     power = BitField(0, 1) # offset and size
>     spin  = BitField(1, 1)
>     speed = BitField(2, 4)
>     sense = BitField(6, 2)
>     red   = BitField(8, 8)
>     blue  = BitField(16, 8)
>     green = BitField(24, 8)
>
> widget_cmd = IOTDeviceCommand()
> widget_cmd.power = 1
> widget_cmd.sense = 2
> widget_cmd.speed = 5
> widget_cmd.red = 0xaa
> widget_cmd.blue = 0xbb
> widget_cmd.green = 0xcc
> widget_cmd
IOTDeviceCommand(value=0xccbbaa95, size=32)
> widget_cmd.bytes
b'\xcc\xbb\xaa\x95'

Installation

$ python3 -m pip install bitvector-for-humans
$ pydoc bitvector
...

Or directly from github:

$ pip install git+https://github.com/JnyJny/bitvector.git

Motivations

  1. Address sub-byte bits in a less error prone way.
  2. Minimize subdependencies (zero is minimized right?).
  3. Learn something about descriptors: ✅.

Caveats

The tests need expanding and I got lazy when writing the multi-bit setting / getting code and it could undoubtedly be improved. Pull requests gladly accepted.

Other Ways to Implement a Bit Vector

  1. Python builtin ctypes.Structure allows sub-byte bit fields
  2. Python builtin struct provides extensive support for byte manipulations
  3. Python3 IntEnums can be used to build bit field masks
  4. The plain int will serve admirably with bitwise operators
  5. Provide cffi bindings to existing bit-twiddling libraries
  6. Use Numpy bool arrays as the "backing store"
  7. Other good ideas I overlooked, forgot about or just plain don't know.

Metadata

Release files for bitvector-for-humans 0.14.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bitvector-for-humans 0.14.4
File Size Uploaded Provenance Actions
bitvector_for_humans-0.14.4.tar.gz 40.2 kB With provenance Details for bitvector_for_humans-0.14.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bitvector-for-humans 0.14.4
File Interpreter ABI Platform Actions
bitvector_for_humans-0.14.4-py3-none-any.whl Python 3 none any Details for bitvector_for_humans-0.14.4-py3-none-any.whl

Total release size: 50.7 kB

Release files / bitvector_for_humans-0.14.4.tar.gz

Download URL bitvector_for_humans-0.14.4.tar.gz
Size 40.2 kB
Tags Source
SHA-256 checksum
How to use checksums
df33ad1011c272faa11c1aa4d6bd6bee26b91438c1b59b72b762b43b4697b950
BLAKE2b-256 checksum
How to use checksums
30e7dcadb4fbb22eee67b601ded3ecf7c25a5407023897d5007cfa350bae3809
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 21, 2025.

Transparency log

Release files / bitvector_for_humans-0.14.4-py3-none-any.whl

Download URL bitvector_for_humans-0.14.4-py3-none-any.whl
Size 10.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60c0eba8e5566082013006cc735eac5695fd8d89a114d39a692d108d073d7c2f
BLAKE2b-256 checksum
How to use checksums
8cfb35c95328c4abd3b7f15c44fa109088504c835d98771842ba179179d4dc7c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 21, 2025.

Transparency log

Security for bitvector-for-humans 0.14.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bitvector_for_humans-0.14.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 21, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page