Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A roughly 3x faster drop-in replacement of Python's enum
.
Python's enum
type is a useful building block for creating semantic types and constants in your programs.
The problem is, if you're doing millions and millions of enum lookups (even simple expressions like Color.ORANGE
) it's a little bit slow.
fastenum
is a stripped-down enum implementation that's up to 3.5x faster than the standard library implementation. At Quantlane we use it in production code as a drop-in replacement. Read more, including benchmarks, on our blog: A 3x faster enum type for Python.
fastenum
is available on PyPI and you can install it with:
pip install fastenum
or
poetry add fastenum
Simply use fastenum.Enum
instead of enum.Enum
:
import fastenum
class Color(fastenum.Enum):
RED = 0
BLUE = 1
GREEN = 2
assert isinstance(Color.RED, Color)
assert Color.RED is Color['RED']
assert Color.BLUE != 1
assert Color.GREEN.value == 2
def is_red(c: Color) -> bool:
return c is Color.RED
There is also a mypy plugin that you'll want to enable in mypy.ini
to help mypy understand fastenum
just like it understands enum
:
[mypy]
plugins = fastenum.mypy_plugin:plugin
There is no support for automatic values, unique value checks, aliases, custom __init__
implementations on members, IntEnum
, Flag
, or the functional API. If you require any of these features it's probably best to just use enum
.
fastenum
's mypy plugin may cause issues with your mypy cache (see above).
poetry install
poetry run pytest
Pull requests are welcome!
We will accept pull requests adding missing functionality provided they do not impact base fastenum
performance (it's best to verify that with benchmarks).
fastenum
was made byQuantlane <https://quantlane.com>
_, a systematic trading firm. We design, build and run our own stock trading platform.
FAQs
Faster drop-in replacement of Python's enum
We found that fastenum demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.