{"id":15403187,"url":"https://github.com/woodruffw/ordered_enum","last_synced_at":"2025-04-06T15:12:44.234Z","repository":{"id":52427420,"uuid":"241256014","full_name":"woodruffw/ordered_enum","owner":"woodruffw","description":"Totally ordered enums for Python.","archived":false,"fork":false,"pushed_at":"2025-01-27T15:46:04.000Z","size":75,"stargazers_count":30,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-06T07:18:43.269Z","etag":null,"topics":["enum","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/ordered-enum/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/woodruffw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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},"funding":{"github":"woodruffw","thanks_dev":"u/gh/woodruffw"}},"created_at":"2020-02-18T02:38:38.000Z","updated_at":"2025-01-27T15:46:06.000Z","dependencies_parsed_at":"2023-12-18T17:13:11.473Z","dependency_job_id":"d32132dd-ad21-4a65-b6b5-699cc5dfc69c","html_url":"https://github.com/woodruffw/ordered_enum","commit_stats":{"total_commits":61,"total_committers":5,"mean_commits":12.2,"dds":0.5081967213114754,"last_synced_commit":"c494ce551525b0cd60bdfa7e0c9e07ecc0e68758"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woodruffw%2Fordered_enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woodruffw%2Fordered_enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woodruffw%2Fordered_enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woodruffw%2Fordered_enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/woodruffw","download_url":"https://codeload.github.com/woodruffw/ordered_enum/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247500469,"owners_count":20948880,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["enum","python"],"created_at":"2024-10-01T16:06:41.339Z","updated_at":"2025-04-06T15:12:44.215Z","avatar_url":"https://github.com/woodruffw.png","language":"Python","readme":"ordered_enum\n============\n\n[![CI](https://github.com/woodruffw/ordered_enum/actions/workflows/ci.yml/badge.svg)](https://github.com/woodruffw/ordered_enum/actions/workflows/ci.yml)\n[![Downloads](https://pepy.tech/badge/ordered-enum)](https://pepy.tech/project/ordered-enum)\n\n**ordered_enum** is a small library for adding (total) orderings to `enum.Enum`s.\n\nIt provides two ordering behaviors:\n\n* `ordered_enum.OrderedEnum`: total ordering by definition\n* `ordered_enum.ValueOrderedEnum`: \"total\" ordering by member values\n\n## Installation\n\n**ordered_enum** requires Python 3.7 or newer.\n\n```bash\npip3 install ordered_enum\n```\n\n## Usage\n\nTo use **ordered_enum**, just use `OrderedEnum` or `ValueOrderedEnum` as your parent class:\n\n```python\nfrom ordered_enum import OrderedEnum\n\n\nclass State(OrderedEnum):\n    Disabled = 4\n    Loaded = 3\n    Waiting = 2\n    Running = 1\n    Dead = 0\n\n\nassert(State.Disabled \u003c State.Loaded)\nassert(sorted([State.Dead, State.Waiting]) == [State.Waiting, State.Dead])\n```\n\n`OrderedEnum` doesn't require `@enum.unique` (or unique values at all); it uses the order of\ndefinition to impose an ordering between members.\n\nIf you'd like to impose an ordering based on member values, you can use `ValueOrderedEnum` instead:\n\n```python\nimport enum\nfrom ordered_enum import ValueOrderedEnum\n\n\n@enum.unique\nclass State(ValueOrderedEnum):\n    Disabled = 4\n    Loaded = 3\n    Waiting = 2\n    Running = 1\n    Dead = 0\n\n\nassert(State.Disabled \u003e State.Loaded)\nassert(sorted([State.Waiting, State.Dead]) == [State.Dead, State.Waiting])\n```\n\n`ValueOrderedEnum` **does** require unique values, which can be enforced via `@enum.unique`.\nFailing to make a `ValueOrderedEnum`'s values unique will result in a silently broken ordering.\n\n## Caveats\n\nAs mentioned above, `ordered_enum.OrderedEnum` provides an ordering of enum values based on their order\nof definition in the class. This means that:\n\n1. Enum values doesn't have to be unique for **ordered_enum** to work\n2. Enum values can be heterogeneously typed\n2. Moving enum values around changes their ordering\n\nTherefore, you should either not depend on a specific ordering **or** ensure that your\norder of definition is the order you'd like.\n","funding_links":["https://github.com/sponsors/woodruffw","https://thanks.dev/u/gh/woodruffw"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoodruffw%2Fordered_enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwoodruffw%2Fordered_enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoodruffw%2Fordered_enum/lists"}