{"id":24534395,"url":"https://github.com/ispaneli/tchoice","last_synced_at":"2026-02-10T03:31:03.565Z","repository":{"id":273582531,"uuid":"920205053","full_name":"ispaneli/tchoice","owner":"ispaneli","description":"Lightweight implementation of Django-like `TextChoices` and `IntegerChoices`.","archived":false,"fork":false,"pushed_at":"2025-01-21T19:08:27.000Z","size":6,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-11-08T01:22:17.290Z","etag":null,"topics":["backend","dataclass","django","enum","fastapi","pydantic","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/tchoice/","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/ispaneli.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}},"created_at":"2025-01-21T18:40:00.000Z","updated_at":"2025-08-27T14:58:10.000Z","dependencies_parsed_at":"2025-06-27T03:47:44.450Z","dependency_job_id":null,"html_url":"https://github.com/ispaneli/tchoice","commit_stats":null,"previous_names":["ispaneli/tchoice"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ispaneli/tchoice","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ispaneli%2Ftchoice","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ispaneli%2Ftchoice/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ispaneli%2Ftchoice/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ispaneli%2Ftchoice/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ispaneli","download_url":"https://codeload.github.com/ispaneli/tchoice/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ispaneli%2Ftchoice/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29289902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-10T02:32:08.756Z","status":"ssl_error","status_checked_at":"2026-02-10T02:30:31.937Z","response_time":65,"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":["backend","dataclass","django","enum","fastapi","pydantic","python"],"created_at":"2025-01-22T11:17:07.731Z","updated_at":"2026-02-10T03:31:03.535Z","avatar_url":"https://github.com/ispaneli.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TChoice\n\nLightweight implementation of Django-like `TextChoices` and `IntegerChoices` \nfor Python applications.\n\n## Problem Statement\n\nWhen working with FastAPI or other frameworks, it's often useful to have \nenumerations with labels for better readability and usability in models, \nforms, and APIs. While Django provides `TextChoices` and `IntegerChoices` \nfor this purpose, they are tightly coupled to the Django framework. \n`tchoice` offers a standalone solution, allowing you to use similar \nfunctionality without requiring Django.\n\n## Installation\n\nInstall the package via pip:\n\n```bash\npip install tchoice\n```\n\n## How to Use\n\n### Defining Choices\nYou can define your choices using `TextChoices` or `IntegerChoices`:\n\n```python\nfrom tchoice import TextChoices, IntegerChoices\n\nclass ColorChoices(TextChoices):\n    RED = \"red\", \"Red Color\"\n    GREEN = \"green\", \"Green Color\"\n    BLUE = \"blue\", \"Blue Color\"\n\nclass SizeChoices(IntegerChoices):\n    SMALL = 1, \"Small Size\"\n    MEDIUM = 2, \"Medium Size\"\n    LARGE = 3, \"Large Size\"\n```\n\n### Accessing Labels and Values\n\n```python\nprint(ColorChoices.RED)          # Output: red\nprint(ColorChoices.RED.label)    # Output: Red Color\n\nprint(SizeChoices.SMALL)         # Output: 1\nprint(SizeChoices.SMALL.label)   # Output: Small Size\n```\n\n### Using Choices in Models\n\nFor FastAPI and Pydantic:\n\n```python\nfrom pydantic import BaseModel\nfrom tchoice import TextChoices\n\nclass ColorChoices(TextChoices):\n    RED = \"red\", \"Red Color\"\n    GREEN = \"green\", \"Green Color\"\n    BLUE = \"blue\", \"Blue Color\"\n\nclass Item(BaseModel):\n    name: str\n    color: ColorChoices\n\n# Example usage\nitem = Item(name=\"Example Item\", color=ColorChoices.RED)\nprint(item.color)           # Output: red\nprint(item.color.label)     # Output: Red Color\n```\n\n---\n\n## License\n\nThis project is licensed under the terms of the [MIT license](https://github.com/ispaneli/tchoice/blob/master/LICENSE).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fispaneli%2Ftchoice","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fispaneli%2Ftchoice","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fispaneli%2Ftchoice/lists"}