Skip to main content

Integer enum choices helper (value/label mapping)

Project description

int-enum-choices

Helper turning an IntEnum into (value, label) choices with reverse lookups — handy for Django-style choice fields backed by integer enums.

Installation

pip install entirius-py-int-enum-choices

Usage

from enum import IntEnum
from int_enum_choices import IntEnumChoices


class Color(IntEnum):
    RED = 1
    GREEN = 2


class ColorChoices(IntEnumChoices):
    enumClass = Color
    labels = {Color.RED: "Red", Color.GREEN: "Green"}


ColorChoices.choices()          # [(1, "Red"), (2, "Green")]
ColorChoices.label(1)           # "Red"
ColorChoices.idFromText("red")  # Color.RED
ColorChoices.keys()             # [1, 2]

Development

make install     # sync dependencies (uv)
make check       # lint + format check (ruff)
make test        # test suite (pytest)

Development and agent instructions: AGENTS.md.

License

Mozilla Public License 2.0 — see LICENSE.

Project details


Download files

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

Source Distribution

entirius_py_int_enum_choices-2.0.0.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

entirius_py_int_enum_choices-2.0.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file entirius_py_int_enum_choices-2.0.0.tar.gz.

File metadata

  • Download URL: entirius_py_int_enum_choices-2.0.0.tar.gz
  • Upload date:
  • Size: 21.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for entirius_py_int_enum_choices-2.0.0.tar.gz
Algorithm Hash digest
SHA256 14b02733651f800f58acc34950502832a8f9ef0474b0cb9596eeb2f1b42af490
MD5 c76e55652449ab249a673c26ae248cf0
BLAKE2b-256 1ab28596d7839d0e4fe67588235cc5b6e00e89f52fe32f10a19541c5c2dd8420

See more details on using hashes here.

File details

Details for the file entirius_py_int_enum_choices-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: entirius_py_int_enum_choices-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for entirius_py_int_enum_choices-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e53e800e8d988aa2ee3ec079a26c3b01bf9d6d34b6d21192fd59f183f38c9f20
MD5 baf7fb12a74d3638417e1879b650c93b
BLAKE2b-256 caa698664b41cf9cf255bab644e8adba6f6bb7be82d3d1523d84024a9d4a2ebf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page