Skip to main content

big-bitfield (Python)

Python equivalent of the JavaScript big-bitfield library for storing permission-style bitfields in a fixed-size byte array and exchanging them as base64 strings.

Compatibility

This implementation matches the JavaScript library's storage format:

  • default size is 8 bytes
  • bit 0 is the high bit (0x80) of the first byte
  • .base64 uses standard base64 encoding of the raw byte array
  • out-of-range get() returns False
  • out-of-range set() is a no-op

That means a base64 string produced in JavaScript can be read in Python and vice versa.

Install

pip install big-bitfield

Usage

from big_bitfield import BitField

bf = BitField()
bf.set(0)
bf.set(9)

assert bf.get(0) is True
assert bf.get(1) is False
assert bf.has_all(0, 9) is True
assert bf.has_any(1, 9) is True

encoded = bf.base64
same = BitField(encoded)
assert same.get(0) is True
assert same.get(9) is True

API

BitField(data=8)

  • data may be:
    • an int meaning the number of bytes to allocate
    • a base64 str
    • base64 bytes / bytearray

Methods

  • get(bit) -> bool
  • set(bit, value=True) -> None
  • set_all(bits, value=True) -> None
  • has_all(*bits) -> bool
  • has_any(*bits) -> bool

Properties

  • array -> bytes
  • base64 -> str

JavaScript parity example

JavaScript:

const BitField = require('big-bitfield');
const bf = new BitField();
bf.set(0);
bf.set(9);
console.log(bf.base64);

Python:

from big_bitfield import BitField

bf = BitField("gEAAAAAAAAA=")
print(bf.get(0))  # True
print(bf.get(9))  # True

Metadata

Release files for big-bitfield 1.0.0

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

Source distribution (sdist)

Source distribution for big-bitfield 1.0.0
File Size Uploaded Provenance Actions
big_bitfield-1.0.0.tar.gz 5.8 kB Without provenance Details for big_bitfield-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for big-bitfield 1.0.0
File Interpreter ABI Platform Actions
big_bitfield-1.0.0-py3-none-any.whl Python 3 none any Details for big_bitfield-1.0.0-py3-none-any.whl

Total release size: 11.7 kB

Release files / big_bitfield-1.0.0.tar.gz

Download URL big_bitfield-1.0.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
168aa3e06de27e6190f5a0c80f48feff1fc65161c7abdccedb0a883380da2715
BLAKE2b-256 checksum
How to use checksums
9c69ebc489b7c5406726fe4453cd7be767fdd7a5c94e25dcc7a008f2a9828975
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.11

Release files / big_bitfield-1.0.0-py3-none-any.whl

Download URL big_bitfield-1.0.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36b50b44393c2a14fd08afda6364f8113b9a0d97dd9ad1a393058a26b0a2314a
BLAKE2b-256 checksum
How to use checksums
7c3875d87e9797055d0f16f1c3ce754bd0fe50308cfbdbf75359fe31bf640253
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.11

Security for big-bitfield 1.0.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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