https://github.com/clarketm/bitflag
A simple bit flag class for Python 🐍
https://github.com/clarketm/bitflag
bitflag bitflags python
Last synced: 10 months ago
JSON representation
A simple bit flag class for Python 🐍
- Host: GitHub
- URL: https://github.com/clarketm/bitflag
- Owner: clarketm
- License: mit
- Created: 2018-07-23T23:48:37.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-01-13T07:11:27.000Z (about 7 years ago)
- Last Synced: 2025-03-28T00:44:00.343Z (11 months ago)
- Topics: bitflag, bitflags, python
- Language: Python
- Homepage: https://pypi.org/project/bitflag/
- Size: 52.7 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [BitFlag](https://pypi.org/project/bitflag/)
[](https://pypi.org/project/bitflag/)
[](https://pepy.tech/project/bitflag)
A simple bit flag class for Python 🐍.
## Installation
```bash
$ pip install bitflag
```
## Usage
```python
# 1. import the "BitFlag" class.
from bitflag import BitFlag
# 2. initialize a BitFlag instance with any number of string, flag arguments.
bf = BitFlag("flagA", "flagB", "flagC")
# 3. run operations on those bit flags!
# set – Set one or more bit flags.
bf.set("flagB", "flagC")
# unset – Unset one or more bit flags.
bf.unset("flagB")
# has – Check if one or more bit flags have been set.
bf.has("flagC")
# toggle – Toggle one or more bit flags.
bf.toggle("flagA", "flagB", "flagC")
# reset – Reset (unset) all bit flags.
bf.reset()
# flip – Flip all bit flags.
bf.flip()
# keys - iterate over flag keys.
for k in bf.keys():
print(k)
# values - iterate over flag values.
for v in bf.values():
print(v)
# items - iterate over flag keys and values.
for k,v in bf.items():
print(k, v)
# str - informal string representation.
str(bf)
# repr - formal string representation.
repr(bf)
# int - integer representation.
int(bf)
```
## License
MIT © [**Travis Clarke**](https://blog.travismclarke.com/)