Skip to main content

The simplest way to create bit-flags

Project description


Simplest way to create bit-flags.

$ pip install intflags


Create any number of intflags by using intflags.get(). You can create a union of any amount using the pipe (|) operator.

>>> import intflags

>>> a, b, c = intflags.get(3)
>>> bin(a | b | c)

>>> flags = a | b
>>> a in flags
>>> c in flags

Flags can be subtracted.

# ...
>>> new_flags = flags - b
>>> b in new_flags
>>> new_flags == a

You could use classes as a pseudo-namespace.

>>> class RegexFlags:
...     I, L, M, S, U, X = intflags.get(6)

Flags share an internal "namespace" ID to prevent accidental conflicts between sets. This allows multiple sets of flags to exist within the same class or module, without risk of accidentally creating a union between them.

>>> x = intflags.get(1)
>>> y = intflags.get(1)
>>> x | y
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Flags must share a namespace to create a union.


IntFlags is licensed under the ISC license. A copy of the license is included in the root of this repository and in the source of the module.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for intflags, version 2.0.0
Filename, size File type Python version Upload date Hashes
Filename, size intflags-2.0.0-py3-none-any.whl (4.4 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size intflags-2.0.0.tar.gz (3.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page