{"id":16463588,"url":"https://github.com/simon-ritchie/pconst","last_synced_at":"2025-03-21T06:31:51.716Z","repository":{"id":57451307,"uuid":"154911808","full_name":"simon-ritchie/pconst","owner":"simon-ritchie","description":"\"pconst\" library provide you const-like function on Python.","archived":false,"fork":false,"pushed_at":"2024-01-22T13:58:08.000Z","size":55,"stargazers_count":17,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T00:26:41.389Z","etag":null,"topics":[],"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/simon-ritchie.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}},"created_at":"2018-10-27T01:29:03.000Z","updated_at":"2024-02-01T09:23:12.000Z","dependencies_parsed_at":"2024-01-22T15:59:33.926Z","dependency_job_id":null,"html_url":"https://github.com/simon-ritchie/pconst","commit_stats":{"total_commits":36,"total_committers":1,"mean_commits":36.0,"dds":0.0,"last_synced_commit":"64aba537793c23bec2576770a5ed09be49bf33c8"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon-ritchie%2Fpconst","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon-ritchie%2Fpconst/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon-ritchie%2Fpconst/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simon-ritchie%2Fpconst/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simon-ritchie","download_url":"https://codeload.github.com/simon-ritchie/pconst/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244117631,"owners_count":20400742,"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":[],"created_at":"2024-10-11T11:14:53.853Z","updated_at":"2025-03-21T06:31:51.437Z","avatar_url":"https://github.com/simon-ritchie.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pconst\n\n\"pconst\" library provide you const-like function on Python.\n\n# Install\n\nInstall via pip is available.\n\n```\n$ pip install pconst\n```\n\n# How to use\n\nYou can set constants to const module's attribute.\n\n```py\nfrom pconst import const\nconst.APPLE_PRICE = 100\nconst.APPLE_NAME = 'apple'\nprint(const.APPLE_PRICE)\n```\n\n```\n100\n```\n\nIf try to update constant value, ConstantError will be raised.\n\n```py\nconst.APPLE_PRICE = 200\n```\n\n```\nConstant value of \"APPLE_PRICE\" is not editable.\n```\n\ndel operator is also disallowed.\n\n```py\ndel const.APPLE_NAME\n```\n\n```\nConstantError: Constant values are not deletable.\n```\n\nYou can also set dict and list value to const module, and they will be not editable (if dict or list values contains dict or list, then will be applied recursively.).\n\n```py\nconst.APPLE_DATA = {\n    'prince': 100,\n    'name': 'apple',\n    'sales_list': [12300, 25000, 8200]}\nprint('price:', const.APPLE_DATA['price'])\nprint('name:', const.APPLE_DATA['name'])\nprint('sales_list:', const.APPLE_DATA['sales_list'])\n```\n\n```\nprice: 100\nname: apple\nsales_list: [12300, 25000, 8200]\n```\n\n```py\nconst.APPLE_DATA['price'] = 200\n```\n\n```\nConstantError: Update dict value is not allowed.\n```\n\n```py\nconst.APPLE_DATA['sales_list'][1] = 9800\n```\n\n```\nConstantError: Constant list value is not allowed.\n```\n\nThe dict or list class method that will not change the values is be able to access (e.g., len(), keys()).\n\n```py\nprint(len(const.APPLE_DATA['sales_list']))\n```\n\n```\n3\n```\n\n```py\nprint(const.APPLE_DATA.keys())\n```\n\n```\ndict_keys(['price', 'name', 'sales_list'])\n```\n\nConversely, if the method that will change the dict or list values, it will raise error.\n\n```py\nconst.APPLE_DATA.update({'season': 'winter'})\n```\n\n```\nConstantError: To update dict values is not allowed.\n```\n\nIf you want to allow the setting of the same constant value, calling the `accept_same_value` method will prevent errors. This setting can be convenient in situations where you are running Jupyter cells multiple times.\n\n```py\nconst.accept_same_value()\nconst.APPLE_PRICE = 100\n\n# Setting the same value like this will not raise an error.\nconst.APPLE_PRICE = 100\n```\n\n# For test\n\nTest will be run by nose library (https://nose.readthedocs.io/en/latest/).\n\n```\n# pip install nose\n```\n\nProbably this pip command requires \"Run as Administrator\".\n\nThen move to pconst directory, and run following command:\n\n```\n$ nosetests -s\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon-ritchie%2Fpconst","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimon-ritchie%2Fpconst","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimon-ritchie%2Fpconst/lists"}