BitAware
Bitwise Toolbox
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bitaware-0.3.0.tar.gz | 4.7 kB | With provenance | Details for bitaware-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bitaware-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for bitaware-0.3.0-py3-none-any.whl |
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 logRelease 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 logSecurity for bitaware 0.3.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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for bitaware-0.3.0.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 Jul 8, 2026.
Transparency logA 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.