{"id":25534824,"url":"https://github.com/diegojromerolopez/constantia","last_synced_at":"2026-02-09T10:02:27.626Z","repository":{"id":273615558,"uuid":"919719767","full_name":"diegojromerolopez/constantia","owner":"diegojromerolopez","description":"Enforce constants in your code at import or run time","archived":false,"fork":false,"pushed_at":"2025-01-26T22:30:47.000Z","size":24,"stargazers_count":0,"open_issues_count":3,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-20T12:05:13.321Z","etag":null,"topics":["const","python"],"latest_commit_sha":null,"homepage":"","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/diegojromerolopez.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-20T22:06:19.000Z","updated_at":"2025-01-26T22:17:05.000Z","dependencies_parsed_at":"2025-01-22T00:36:22.394Z","dependency_job_id":null,"html_url":"https://github.com/diegojromerolopez/constantia","commit_stats":null,"previous_names":["diegojromerolopez/constantia"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegojromerolopez%2Fconstantia","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegojromerolopez%2Fconstantia/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegojromerolopez%2Fconstantia/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/diegojromerolopez%2Fconstantia/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/diegojromerolopez","download_url":"https://codeload.github.com/diegojromerolopez/constantia/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248409349,"owners_count":21098768,"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":["const","python"],"created_at":"2025-02-20T03:29:04.178Z","updated_at":"2025-11-11T20:21:15.972Z","avatar_url":"https://github.com/diegojromerolopez.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# constantia\n\n![test](https://github.com/diegojromerolopez/constantia/actions/workflows/test.yml/badge.svg)\n[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/diegojromerolopez/constantia/graphs/commit-activity)\n[![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)](https://www.python.org/)\n[![PyPI pyversions](https://img.shields.io/pypi/pyversions/constantia.svg)](https://pypi.python.org/pypi/constantia/)\n[![PyPI version constantia](https://badge.fury.io/py/constantia.svg)](https://pypi.python.org/pypi/constantia/)\n[![PyPI status](https://img.shields.io/pypi/status/constantia.svg)](https://pypi.python.org/pypi/constantia/)\n[![PyPI download month](https://img.shields.io/pypi/dm/constantia.svg)](https://pypi.python.org/pypi/constantia/)\n[![Maintainability](https://api.codeclimate.com/v1/badges/2866bb9c56abf9223384/maintainability)](https://codeclimate.com/github/diegojromerolopez/constantia/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/2866bb9c56abf9223384/test_coverage)](https://codeclimate.com/github/diegojromerolopez/constantia/test_coverage)\n\nEnforce constants in your code at import or at run time.\n\n## Usage\nUse the `consts` decorator and pass as parameters a list of\nvariables you want to treat as constants.\n\nThe variables in the constant list cannot be re-assigned nor they\ncan be assigned a mutable object. They can only be assigned:\n- strings\n- integers\n- floats\n- tuples\n\nThis is done to avoid indirect modifications.\n\nChoose if you want to do the checks at runtime or when importing\nthe function by setting the check_at argument.\n\n## Examples\n\n### Function\n\n#### Checking the constants at import time\n\n```python\nfrom constantia import consts\n\n@consts(['x', 'y', 'z'], check_at='import')\ndef func():\n    x = [1, 2, 3] # this will crash at import time as the constant does not have an immutable value\n    y = 20\n    y = 30  # this will raise an exception at import time as the constant is reassigned\n```\n\n#### Checking the constants at run time\n\n```python\nfrom constantia import consts\n\n@consts(['x', 'y', 'z'], check_at='runtime')\ndef func():\n    x = [1, 2, 3] # this will rais an exception when trying to run the function\n    y = 20\n    y = 30  # this will rais an exception when trying to run the function\n```\n\n### Class constants\n\n#### Ensuring every uppercase attribute is a constant\n\n```python\nfrom constantia import consts\n\n@consts('uppercase', check_at='import')\nclass Example:\n    X = 9999\n    Y = 'other constant'\n    X = 888  # this will raise an exception\n```\n\n#### Ensuring a constant is not re-assignable\n\n```python\nfrom constantia import consts\n\n@consts(['X'], check_at='import')\nclass Example:\n    X = 9999\n    X = 888  # this will raise an exception\n\n    @classmethod\n    def change_x1(cls):\n        cls.X = 8888  # this will raise an exception\n\n    @staticmethod\n    def change_x2():\n        Example.X = 8888  # this will raise an exception\n```\n\n#### Sensible defaults: constants are uppercase and check the constants at import time\n\n```python\nfrom constantia import consts\n\n@consts\nclass Example:\n    X = 9999\n    Y = 'other constant'\n    X = 888  # this will raise an exception\n```\n\n## Dependencies\nThis package has no dependencies.\n\n## License\n[MIT](LICENSE) license, but if you need any other contact me.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegojromerolopez%2Fconstantia","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdiegojromerolopez%2Fconstantia","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdiegojromerolopez%2Fconstantia/lists"}