{"id":20977298,"url":"https://github.com/2degrees/python-enumeration","last_synced_at":"2026-04-21T21:01:24.404Z","repository":{"id":139812549,"uuid":"68111441","full_name":"2degrees/python-enumeration","owner":"2degrees","description":"Enum implementation for Python 2 and 3","archived":false,"fork":false,"pushed_at":"2016-10-28T11:03:22.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-12-31T11:28:06.250Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2degrees.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-13T13:35:43.000Z","updated_at":"2016-10-24T12:47:21.000Z","dependencies_parsed_at":null,"dependency_job_id":"ef534757-7d67-4ccb-af72-a958d613f881","html_url":"https://github.com/2degrees/python-enumeration","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/2degrees/python-enumeration","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fpython-enumeration","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fpython-enumeration/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fpython-enumeration/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fpython-enumeration/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2degrees","download_url":"https://codeload.github.com/2degrees/python-enumeration/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2degrees%2Fpython-enumeration/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32110137,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-21T11:25:29.218Z","status":"ssl_error","status_checked_at":"2026-04-21T11:25:28.499Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-19T04:58:13.540Z","updated_at":"2026-04-21T21:01:24.376Z","avatar_url":"https://github.com/2degrees.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# python-enumeration\n\n[![Build Status](https://travis-ci.org/2degrees/python-enumeration.svg?branch=master)](https://travis-ci.org/2degrees/python-enumeration) \n[![Coverage Status](https://coveralls.io/repos/github/2degrees/python-enumeration/badge.svg?branch=master)](https://coveralls.io/github/2degrees/python-enumeration?branch=master)\n\nAn enumeration data type for Python.\n\n## Getting started\n\npython-enumeration can be installed from PyPi via:\n\n```bash\npip install python-enumeration\n\n```\n\nYou can then import the library and define an enumeration:\n\n```python\nfrom enumeration import Enum\n\nMY_ENUM = Enum(\n    ('value', 'IDENTIFIER'),\n    ...\n)\n```\n\n\n## Usage\n\npython-enumeration allows you to define enumerated data so that you have\na consistent interface to the underlying data, e.g.\n\n```python\n\u003e\u003e\u003e from enumeration import Enum\n\u003e\u003e\u003e AGES_OF_MAN = Enum(\n...     ('baby', 'BABY'),\n...     ('toddler', 'TODDLER'),\n...     ('child', 'CHILD'),\n...     ('teenager', 'TEENAGER'),\n...     ('adult', 'ADULT'),\n...     ('elderly', 'ELDERLY'),\n... )\n\u003e\u003e\u003e AGES_OF_MAN.BABY\n\u003cEnumItem: value='baby', index=0\u003e\n\u003e\u003e\u003e str(AGES_OF_MAN.BABY)\n'baby'\n\u003e\u003e\u003e AGES_OF_MAN.BABY.item_value\n'baby'\n```\n\n### Comparison\n\npython-enumeration supports comparison operations on its items so the\norder in which the enum defines its items is importation:\n\n```python\n\u003e\u003e\u003e AGES_OF_MAN.BABY \u003c AGES_OF_MAN.TODDLER\nTrue\n\u003e\u003e\u003e AGES_OF_MAN.TODDLER \u003e AGES_OF_MAN.CHILD\nFalse\n\u003e\u003e\u003e AGES_OF_MAN.ADULT \u003c= AGES_OF_MAN.ADULT\nTrue\n```\n\nIt's also possible to list all the values which are less than or\ngreater than an item:\n\n```python\n\u003e\u003e\u003e AGES_OF_MAN.CHILD.previous_values\n('baby', 'toddler')\n\u003e\u003e\u003e AGES_OF_MAN.CHILD.previous_values_with_self\n('baby', 'toddler', 'child')\n\u003e\u003e\u003e AGES_OF_MAN.CHILD.subsequent_values\n('teenager', 'adult', 'elderly')\n\u003e\u003e\u003e AGES_OF_MAN.CHILD.subsequent_values_with_self\n('child', 'teenager', 'adult', 'elderly')\n```\n\n### Setting human-readable labels\n\nIf you want to display a label for your enumeration in some UI, you can\ndefine a set of UI labels for the enumeration:\n\n```python\n\u003e\u003e\u003e AGES_OF_MAN.set_ui_labels({\n...     AGES_OF_MAN.BABY: \"Baby\",\n...     AGES_OF_MAN.TODDLER: \"Toddler\",\n...     AGES_OF_MAN.CHILD: \"Child\",\n...     AGES_OF_MAN.TEENAGER: \"Teenager\",\n...     AGES_OF_MAN.ADULT: \"Adult\",\n...     AGES_OF_MAN.ELDERLY: \"Elderly\",\n... })\n\u003e\u003e\u003e AGES_OF_MAN.BABY.get_ui_label()\n'Baby'\n\u003e\u003e\u003e AGES_OF_MAN.get_ui_labels()\n((\u003cEnumItem: value='baby', index=0\u003e, 'Baby'), (\u003cEnumItem: value='toddler', index=1\u003e, 'Toddler'), (\u003cEnumItem: value='child', index=2\u003e, 'Child'), (\u003cEnumItem: value='teenager', index=3\u003e, 'Teenager'), (\u003cEnumItem: value='adult', index=4\u003e, 'Adult'), (\u003cEnumItem: value='elderly', index=5\u003e, 'Elderly'))\n```\n\nFor further examples of how you can use the enumeration, see the test\nsuite.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2degrees%2Fpython-enumeration","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2degrees%2Fpython-enumeration","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2degrees%2Fpython-enumeration/lists"}