Skip to main content

Xenum: A simple alternative to Python 3 Enums.

Xenum offers a simple alternative to Python 3 enums that’s especially useful for (de)serialization. When you would like to model your enum values so that they survive jumps to and from JSON, databases, and other sources cleanly as strings, Xenum will allow you to do so extremely easily.

Installation

Installation is simple. With python3-pip, do the following:

$ sudo pip install -e .

Or, to install the latest version available on PyPI:

$ sudo pip install xenum

Usage

Just create a basic class with attributes and annotate it with the @xenum attribute. This will convert all of the class attributes into Xenum instances and allow you to easily convert them to strings via str(MyEnum.A) and from strings via MyEnum.by_name("MyEnum.A").

Example

from xenum import xenum, ctor

@xenum
class Actions:
  INSERT = ctor('insert')
  UPDATE = ctor('update')
  DELETE = ctor('delete')

  def __init__(self, name):
     self.name = name

assert Actions.INSERT == Actions.by_name('Actions.INSERT')
assert Actions.INSERT().name == 'insert'

Checkout test.py in the git repo for more usage examples.

Change Log

Version 1.4: September 5th, 2016

  • Add ‘xenum.sref()’ allowing enum values to be instances of the @xenum annotated class, whos *args is prepended with the Xenum instance itself for self-reference.

Version 1.3: September 4th, 2016

  • Add ‘xenum.ctor()’ allowing enum values to be instances of the @xenum annotated class.

  • Made Xenum instances callable, returning the enum’s internal value.

Version 1.2: September 4th, 2016

  • Add ‘values()’ method to @xenum annotated classes for fetching an ordered sequence of the Xenum entities created.

Version 1.1: August 31st, 2016

  • Made Xenum instances hashable, removed value() as a function.

Metadata

Release files for xenum 1.4

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

Source distribution (sdist)

Source distribution for xenum 1.4
File Size Uploaded Provenance Actions
xenum-1.4.tar.gz 4.3 kB Without provenance Details for xenum-1.4.tar.gz

Release files / xenum-1.4.tar.gz

Download URL xenum-1.4.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c0802956b74fa2d77af939faa517e8681bc18fcebadf94b8b3a1657d213288bb
BLAKE2b-256 checksum
How to use checksums
03bfef6b523c4d63f0f84c91b6ccfe467d6d184c1c1f7afa1bad83b3ac2b5e9a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for xenum 1.4

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