{"id":24362416,"url":"https://github.com/machu-gwu/constant2-project","last_synced_at":"2026-05-26T05:01:53.160Z","repository":{"id":82575123,"uuid":"91770988","full_name":"MacHu-GWU/constant2-project","owner":"MacHu-GWU","description":"provide extensive way of managing your constant variable.","archived":false,"fork":false,"pushed_at":"2020-12-03T21:37:10.000Z","size":317,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-21T11:47:56.509Z","etag":null,"topics":["configuration","constants","data","developer-tools","python"],"latest_commit_sha":null,"homepage":null,"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/MacHu-GWU.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2017-05-19T06:02:24.000Z","updated_at":"2020-12-03T21:37:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"d1d8102b-d150-47a0-b640-4c54923dafe7","html_url":"https://github.com/MacHu-GWU/constant2-project","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacHu-GWU%2Fconstant2-project","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacHu-GWU%2Fconstant2-project/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacHu-GWU%2Fconstant2-project/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MacHu-GWU%2Fconstant2-project/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MacHu-GWU","download_url":"https://codeload.github.com/MacHu-GWU/constant2-project/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243188241,"owners_count":20250457,"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":["configuration","constants","data","developer-tools","python"],"created_at":"2025-01-18T22:52:05.330Z","updated_at":"2025-12-26T05:33:13.065Z","avatar_url":"https://github.com/MacHu-GWU.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\n.. image:: https://github.com/MacHu-GWU/constant2-project/workflows/CI/badge.svg\n    :target: https://github.com/MacHu-GWU/constant2-project/actions?query=workflow:CI\n\n.. image:: https://codecov.io/gh/MacHu-GWU/constant2-project/branch/master/graph/badge.svg\n    :target: https://codecov.io/gh/MacHu-GWU/constant2-project\n\n.. image:: https://img.shields.io/pypi/v/constant2.svg\n    :target: https://pypi.python.org/pypi/constant2\n\n.. image:: https://img.shields.io/pypi/l/constant2.svg\n    :target: https://pypi.python.org/pypi/constant2\n\n.. image:: https://img.shields.io/pypi/pyversions/constant2.svg\n    :target: https://pypi.python.org/pypi/constant2\n\n.. image:: https://img.shields.io/badge/STAR_Me_on_GitHub!--None.svg?style=social\n    :target: https://github.com/MacHu-GWU/constant2-project\n\n------\n\n\n.. image:: https://img.shields.io/badge/Link-Document-blue.svg\n    :target: http://constant2.my-docs.com/index.html\n\n.. image:: https://img.shields.io/badge/Link-API-blue.svg\n    :target: http://constant2.my-docs.com/py-modindex.html\n\n.. image:: https://img.shields.io/badge/Link-Source_Code-blue.svg\n    :target: http://constant2.my-docs.com/py-modindex.html\n\n.. image:: https://img.shields.io/badge/Link-Install-blue.svg\n    :target: `install`_\n\n.. image:: https://img.shields.io/badge/Link-GitHub-blue.svg\n    :target: https://github.com/MacHu-GWU/constant2-project\n\n.. image:: https://img.shields.io/badge/Link-Submit_Issue-blue.svg\n    :target: https://github.com/MacHu-GWU/constant2-project/issues\n\n.. image:: https://img.shields.io/badge/Link-Request_Feature-blue.svg\n    :target: https://github.com/MacHu-GWU/constant2-project/issues\n\n.. image:: https://img.shields.io/badge/Link-Download-blue.svg\n    :target: https://pypi.org/pypi/constant2#files\n\n\nWelcome to ``constant2`` Documentation\n==============================================================================\n\nIf you have lots of constant2 value widely used across your development. A better way is to define ``Constantant Variable`` rather than using the raw value. This can improve the readability and accessibility.\n\n``constant2`` is a library provide extensive way of managing your constant2 variable.\n\n**Another powerful feature** is, ``constant2`` allows developer defines normalized entity relationship and is data in ``class`` style, which giving awesome accessibility to every single row, and every single column, free developer from memorizing things.\n\n\nUsage\n------------------------------------------------------------------------------\n\n**Version Changed 0.0.9: All nested class now has to inherit from** ``Constant`` **or its subclass**:\n\n.. code-block:: python\n\n    # WRONG!\n    class ItemType(Constant):\n        class Weapon:\n            id = 1\n\n    # CORRECT\n    class ItemType(Constant):\n        class Weapon(Constant):\n            id = 1\n\n    # or\n    class Item(Constant):\n        pass\n\n    class ItemType(Constant):\n        class Weapon(Item):\n            id = 1\n\nUsage:\n\n.. code-block:: python\n\n    from constant2 import Constant\n\n    class Food(Constant):\n\n        class Fruit(Constant):\n            id = 1\n            name = \"fruit\"\n\n            class Apple(Constant):\n                id = 1\n                name = \"apple\"\n\n                class RedApple(Constant):\n                    id = 1\n                    name = \"red apple\"\n\n                class GreenApple(Constant):\n                    id = 2\n                    name = \"green apple\"\n\n            class Banana(Constant):\n                id = 2\n                name = \"banana\"\n\n                class YellowBanana(Constant):\n                    id = 1\n                    name = \"yellow banana\"\n\n                class GreenBanana(Constant):\n                    id = 2\n                    name = \"green banana\"\n\n        class Meat(Constant):\n            id = 2\n            name = \"meat\"\n\n            class Pork(Constant):\n                id = 1\n                name = \"pork\"\n\n            class Beef(Constant):\n                id = 2\n                name = \"beef\"\n\n    food = Food()\n\nYou can visit it's data or child class data in these way:\n\n.. code-block:: python\n\n    # Use class\n    \u003e\u003e\u003e Fruit.Items() # .Items() return it's data\n    [('id', 1), ('name', 'fruit')]\n\n    \u003e\u003e\u003e Fruit.Keys() # .Keys() return keys\n    ['id', 'name']\n\n    \u003e\u003e\u003e Fruit.Values() # .Values() return values\n    [1, 'fruit']\n\n    \u003e\u003e\u003e Fruit.ToDict() # return data in a dict\n    {'id': 1, 'name': 'fruit'}\n\n    # use instance\n    \u003e\u003e\u003e food.items() # .Items() return it's data\n    [('id', 1), ('name', 'fruit')]\n\n    \u003e\u003e\u003e food.keys() # .keys() return keys\n    ['id', 'name']\n\n    \u003e\u003e\u003e food.values() # .values() return values\n    [1, 'fruit']\n\n    \u003e\u003e\u003e food.to_dict() # return data in a dict\n    {'id': 1, 'name': 'fruit'}\n\n    # iterate on all nested class\n    \u003e\u003e\u003e Fruit.Subclasses(sort_by='id')\n    [class Apple, class Banana]\n\n    # get first nested class that kls.id == 1\n    # useful when you need reverse lookup\n    \u003e\u003e\u003e Fruit.GetFirst('id', 1)\n    class Apple\n\n    # get all child class that kls.id == 1\n    \u003e\u003e\u003e Fruit.GetAll('id', 1)\n    [class Apple, ]\n\nAnd it provides built-in I/O methods allow you to dump these data in to a dictionary.\n\n.. code-block:: python\n\n    \u003e\u003e\u003e data = Food.dump()\n    \u003e\u003e\u003e data\n    {\n        \"Food\": {\n            \"Fruit\": {\n                \"Apple\": {\n                    \"GreenApple\": {\n                        \"__classname__\": \"GreenApple\",\n                        \"id\": 2,\n                        \"name\": \"green apple\"\n                    },\n                    \"RedApple\": {\n                        \"__classname__\": \"RedApple\",\n                        \"id\": 1,\n                        \"name\": \"red apple\"\n                    },\n                    \"__classname__\": \"Apple\",\n                    \"id\": 1,\n                    \"name\": \"apple\"\n                },\n                \"Banana\": {\n                    \"GreenBanana\": {\n                        \"__classname__\": \"GreenBanana\",\n                        \"id\": 2,\n                        \"name\": \"green banana\"\n                    },\n                    \"YellowBanana\": {\n                        \"__classname__\": \"YellowBanana\",\n                        \"id\": 1,\n                        \"name\": \"yellow banana\"\n                    },\n                    \"__classname__\": \"Banana\",\n                    \"id\": 2,\n                    \"name\": \"banana\"\n                },\n                \"__classname__\": \"Fruit\",\n                \"id\": 1,\n                \"name\": \"fruit\"\n            },\n            \"Meat\": {\n                \"Beef\": {\n                    \"__classname__\": \"Beef\",\n                    \"id\": 2,\n                    \"name\": \"beef\"\n                },\n                \"Pork\": {\n                    \"__classname__\": \"Pork\",\n                    \"id\": 1,\n                    \"name\": \"pork\"\n                },\n                \"__classname__\": \"Meat\",\n                \"id\": 2,\n                \"name\": \"meat\"\n            },\n            \"__classname__\": \"Food\"\n        }\n    }\n\n    \u003e\u003e\u003e Food = Constant.load(data)\n\n\n.. _install:\n\nInstall\n------------------------------------------------------------------------------\n\n``constant2`` is released on PyPI, so all you need is:\n\n.. code-block:: console\n\n    $ pip install constant2\n\nTo upgrade to latest version:\n\n.. code-block:: console\n\n    $ pip install --upgrade constant2","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachu-gwu%2Fconstant2-project","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmachu-gwu%2Fconstant2-project","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmachu-gwu%2Fconstant2-project/lists"}