Skip to main content

fastenum

Based on python/cpython#17669 and python/cpython#16483

Patch for stdlib enum that makes it fast.

How fast?

  • ~10x faster name/value access
  • ~6x faster access to enum members
  • ~2x faster values positive check
  • ~3x faster values negative check
  • ~3x faster iteration
  • ~100x faster new Flags and IntFlags creation for Python 3.8 and below

Wow this is fast! How do I use it?

First, install it from PyPi using pip

pip install f-enum

or using poetry

poetry add f-enum

Then enable the patch just by calling fastenum.enable() once at the start of your programm:

import fastenum

fastenum.enable()

You don't need to re-apply patch across different modules: once it's enabled, it'll work everywhere.

What's changed?

fastenum is designed to give effortless boost for all enums from stdlib. That means that none of optimizations should break existing code, thus requiring no changes other than installing and activating the library.

Here are summary of internal changes:

  • Optimized Enum.__new__
  • Remove EnumMeta.__getattr__
  • Store Enum.name and .value in members __dict__ for faster access
  • Replace Enum._member_names_ with ._unique_member_map_ for faster lookups and iteration (old arg still remains)
  • Replace _EmumMeta._member_names and ._last_values with .members mapping (old args still remain)
  • Add support for direct setting and getting class attrs on DynamicClassAttribute without need to use slow __getattr__
  • Various minor improvements

Metadata

Release files for f-enum 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for f-enum 0.2.0
File Size Uploaded Provenance
f-enum-0.2.0.tar.gz 10.0 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for f-enum 0.2.0
File Interpreter ABI Platform
f_enum-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.6 kB

Release files / f-enum-0.2.0.tar.gz

Download URL f-enum-0.2.0.tar.gz
Size 10.0 kB
Tags Source
SHA-256 checksum
How to use checksums
3df8fdfad2dc7079a0ed6b0ec2b369b9f2dda358ef08c037a6a3e3c17e9a49e7
BLAKE2b-256 checksum
How to use checksums
73af8b421877bd10736d631a8795b6b90c56f6710b41f528e89bf1150b728a96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.1 Darwin/21.5.0

Release files / f_enum-0.2.0-py3-none-any.whl

Download URL f_enum-0.2.0-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88eb831d75534c132eaea621f9e969d23a02d37130ebb5dec16a50f434aa20ea
BLAKE2b-256 checksum
How to use checksums
37b2173d953c5ddf217c82a9dcf90d04447bdeadf1d4ef476918b1c784df84fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.10.1 Darwin/21.5.0

Security for f-enum 0.2.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.

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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page