Skip to main content

BitAware

Bitwise Toolbox

python ruff pytest markdown License: GPLv3

Usage

Define

from bitaware import BitFlag, BitAware

class PermissionTypes(BitFlag):
    READ = 1
    CREATE = 2
    EDIT = 4
    ADMIN = 8


class UserPermission(BitAware[PermissionTypes]):
    def __init__(self, value: int):
        super().__init__(value, PermissionTypes)

    pass

    # "User Roles" Named sets can be used interchangeably
    READER = PermissionTypes.READ
    CREATOR = PermissionTypes.CREATE | PermissionTypes.READ
    EDITOR = PermissionTypes.EDIT | PermissionTypes.READ

Simple Use

Standalone:

permission = UserPermission(PermissionTypes.ADMIN | PermissionTypes.READ)

print(permission.has(PermissionTypes.ADMIN))  # True
print(permission.has(PermissionTypes.CREATE))  # False

Pydantic

As Pydantic field:

class User(BaseModel):
    name: str
    permissions: UserPermission

Usage

user = User(name="test_user", permissions=UserPermission.READER)
admin = User(name="admin_user", permissions=PermissionTypes.READ | PermissionTypes.ADMIN)

print(user.model_dump_json(indent=2))

Above code will print:

{
  "name": "test_user",
  "permissions": 1
}

Misc

x = UserPermission(12)

print(str(x)) # EDIT|ADMIN [EDIT, ADMIN]
print(repr(x)) # UserPermission(PermissionTypes.EDIT | PermissionTypes.ADMIN)
print(list(x)) # [<PermissionTypes.EDIT: 4>, <PermissionTypes.ADMIN: 8>]

For predefined named flag set:

x = UserPermission(UserPermission.CREATOR)

print(str(x)) # CREATOR [READ, CREATE]
print(repr(x)) # UserPermission(PermissionTypes.READ | PermissionTypes.CREATE)
print(list(x)) # [<PermissionTypes.READ: 1>, <PermissionTypes.CREATE: 2>]

Predefined named flag sets:

print(UserPermission.properties()) # {<PermissionTypes.READ|CREATE: 3>: 'CREATOR', <PermissionTypes.READ|EDIT: 5>: 'EDITOR', <PermissionTypes.READ: 1>: 'READER'}

Test

uv run pytest

Security

If you discover any security-related issues, please email email instead of using the issue tracker.


Copyright (c) 2025 Wojciech Nowicki

Metadata

Release files for bitaware 0.3.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 bitaware 0.3.0
File Size Uploaded
bitaware-0.3.0.tar.gz 4.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bitaware 0.3.0
File Interpreter ABI Platform
bitaware-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 10.0 kB

Release files / bitaware-0.3.0.tar.gz

Download URL bitaware-0.3.0.tar.gz
Size 4.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bfd92030204350d3e148635cfff325611026e87a701fba535fcff5fb530fd39b
BLAKE2b-256 checksum
How to use checksums
a86052c2b7f67fdec8bd44fdf4559d726934bdcff0dbb53bbaa0f0835ea2b11a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 8, 2026.

Transparency log

Release files / bitaware-0.3.0-py3-none-any.whl

Download URL bitaware-0.3.0-py3-none-any.whl
Size 5.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e5c121b907e55f07b185db29b9d73166ac2b1b4d7b3ea1aceadad02ad7d920cc
BLAKE2b-256 checksum
How to use checksums
7217a57dcb89926a934fa55113709ac88bbf3d5df193b735eefac75e00f4ad5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jul 8, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.0.0

2 release files

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