alt-flags
altflags allows you to easily map, parse and manipulate binary flags
Why?
- The built in Python Flags and IntFlags didn't fit my needs
- Simple usage to handle binary flag mapping, parsing and manipulation
- Needs to run super efficiently and quick (same thing?)
- This is my first public package, it's small and easy to maintain
Quick Start
1. Install with pip from PyPi
python -m pip install altflags
2. Create altflags, Flags class
from altflags import Flags, flag
class Permissions(Flags):
create_message = flag(0)
delete_message = flag(1)
edit_message = flag(2)
user_permissions = Permissions()
3. Edit your flags
# Set create_message and edit_message flags to true
user_permissions.create_message = True
user_permissions.edit_message = True
# print flags as binary
print("{:0b}".format(user_permissions.flags))
# >>> 101
# all flags are False (0) from initialization
# print flags as integer
print({:0n}.format(user_permissions.flags))
# >>> 5
4. Compare flags
user2_permissions = Permission()
user2_permissions.create_message = True
user2_permissions.edit_message = True
print(user_permissions == user2_permissions)
# >>> True
user2_permissions.create_message = False
print(user_permissions == user2_permissions)
# >>> False
5. Extend altflags with class methods that return pre-formatted flag objects
class Permissions(Flags):
create_message = flag(0)
delete_message = flag(1)
edit_message = flag(2)
@classmethod
def all(cls):
new_cls = cls()
new_cls.create_message = True
new_cls.delete_message = True
new_cls.edit_message = True
return new_cls
user_permissions = Permissions.all()
print({:0b}.format(user_permissions))
# >>> 111
print({:0n}.format(user_permissions))
# >>> 7
Notes
flags(n: int)n argument specifies the bit position of your flag (Warning: These can be overwritten).
Metadata
Release files for altflags 0.0.3
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 |
|---|---|---|---|---|
| altflags-0.0.3.tar.gz | 3.7 kB | Without provenance | Details for altflags-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| altflags-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for altflags-0.0.3-py3-none-any.whl |
Total release size: 7.5 kB
Release files / altflags-0.0.3.tar.gz
| Download URL | altflags-0.0.3.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3832943ec68faa6c270f07acbb7150e0d0d02164a568ae1a1f9af3eef6f0b521
|
|
BLAKE2b-256 checksum How to use checksums |
91e2e4e4ec7fadcb53e235a9aeec8b0b85915e82feb0107ec089e91ef28fd077
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.2
|
Release files / altflags-0.0.3-py3-none-any.whl
| Download URL | altflags-0.0.3-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ad6c8d7a29bc96372c971de4a6629440dd5cccdedc14e6c49f5f35ab7ad7e84e
|
|
BLAKE2b-256 checksum How to use checksums |
149ccd3c3e8ebbfa591511dc32e811737ec58caee1c1ed74cd95c22b3b6bf8ab
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.8.2
|
Security for altflags 0.0.3
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.