Skip to main content
labeled-enums
=============

A Django-friendly iterable Enum type with labels.

Example
-------

.. code-block:: python

>>> from django.utils.translation import gettext_lazy as _
>>> from lenum import LabeledEnum
>>> class STATE_CHOICES(LabeledEnum):
... NEW = 0
... IN_PROGRESS = 1
... REVIEW = 2, _('In Review')
...
>>>
>>> STATE_CHOICES.NEW
0
>>> STATE_CHOICES.IN_PROGRESS
1
>>> STATE_CHOICES[2]
'In Review'
>>> list(STATE_CHOICES)
[(0, 'New'), (1, 'In Progress'), (2, 'In Review')]

>>> STATE_CHOICES.for_label('In Progress')
1
```

>>> STATE_CHOICES.names
('NEW', 'IN_PROGRESS', 'REVIEW')

Usage in Django:

.. code-block:: python

class STATUS(LabeledEnum):
CLOSED = 0
NEW = 1
PENDING = 2, 'Process Pending'
FAILED = -1, 'Processing Failed'

class MyModel(models.Model):
# django migrations can have trouble resolving imports if we define the
# class within the class, so we bind this here for convenience.
STATUS = STATUS

status = models.IntegerField(choices=STATUS, default=STATUS.NEW)

Want translations?

.. code-block:: python
from django.utils.translation import gettext_lazy as _

class STATUS(LabeledEnum, label_wrapper=_):
CLOSED = 0
NEW = 1
PENDING = 2, 'Process Pending'
FAILED = -1, 'Processing Failed'

All label values (including auto-generated ones) will have `label_wrapper`
applied first.

Installation
------------

.. code-block::

pip install labeled-enum

Metadata

Release files for labeled-enum 1.3.1

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

Source distribution (sdist)

Source distribution for labeled-enum 1.3.1
File Size Uploaded Provenance Actions
labeled-enum-1.3.1.tar.gz 2.3 kB Without provenance Details for labeled-enum-1.3.1.tar.gz

Release files / labeled-enum-1.3.1.tar.gz

Download URL labeled-enum-1.3.1.tar.gz
Size 2.3 kB
Tags Source
SHA-256 checksum
How to use checksums
b422c8b165886a28dd129c62c1e16f732cb685d2d10bd8651595f2a28e0af370
BLAKE2b-256 checksum
How to use checksums
cf3ac6bdbc923b1060ab27410cdf3045ee477623145fa382a650dad5529f9bc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3rc1

Security for labeled-enum 1.3.1

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.

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