{"id":28485986,"url":"https://github.com/brunodavi/envclass","last_synced_at":"2025-07-02T05:31:55.571Z","repository":{"id":200819730,"uuid":"703866948","full_name":"brunodavi/envclass","owner":"brunodavi","description":"Manage environment variables in a simple and elegant way","archived":false,"fork":false,"pushed_at":"2024-09-09T14:07:44.000Z","size":94,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-08T01:07:45.641Z","etag":null,"topics":["configuration","dotenv","env","environment-variables","hints","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/envclass","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/brunodavi.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}},"created_at":"2023-10-12T04:38:54.000Z","updated_at":"2024-09-09T14:07:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"fccaa852-17de-49c1-bdda-c8f4700215d7","html_url":"https://github.com/brunodavi/envclass","commit_stats":{"total_commits":47,"total_committers":3,"mean_commits":"15.666666666666666","dds":"0.21276595744680848","last_synced_commit":"bb648ce1e201ad53591ad98476b6564031f84669"},"previous_names":["brunodavi/envclass"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/brunodavi/envclass","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fenvclass","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fenvclass/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fenvclass/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fenvclass/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brunodavi","download_url":"https://codeload.github.com/brunodavi/envclass/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brunodavi%2Fenvclass/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263081442,"owners_count":23410884,"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","dotenv","env","environment-variables","hints","python"],"created_at":"2025-06-08T01:06:26.570Z","updated_at":"2025-07-02T05:31:55.563Z","avatar_url":"https://github.com/brunodavi.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EnvClass\n\n[![python_versions][BadgePyVersions]][PYPI]\n[![gnu][BadgeGNU]][PYPI]\n[![version][BadgeVersion]][PYPI]\n[![testing][BadgePipeline]][CI]\n\n\nManage environment variables in a simple and elegant way\n\n\n## Why does this exist\n\nTo manage environment variables in an easy\nway that works for any device (like a cell phone\nwith termux)\n\n\n\u003e If you intend to run in production, use [pydantic-settings](https://pypi.org/project/pydantic-settings)\n\n\n### Installation\n```sh\npip install envclass\n```\n\n### Quick Start\n\n`.env`\n```env\nHOST=0.0.0.0\nPORT=1234\n\nCONFIG_FILE=\n```\n\n```python\nfrom envclass import EnvClass\n\n\n# When declaring the class with _env_file it\n# reads the file and casts all attributes\nclass MyEnv(EnvClass):\n    _env_file = '.env'\n\n    TESTING: bool = False\n\n    HOST: str = 'localhost'\n    PORT: int\n\n    CONFIG_FILE: str\n\n\n# Return: '0.0.0.0'\nMyEnv.HOST\n\n# Return: False\nMyEnv.TESTING\n\n# Return: 1234\nMyEnv.PORT\n\n# Return: None\nMyEnv.CONFIG_FILE\n```\n\n### Supported Types\nCurrently, only primitive types have been tested, such as:\n\n- `str`\n- `int`\n- `bool`\n- `float`\n\n#### Booleans\n\nAttributes follow Python language conventions\nfor conversion, but `bool` attributes have specific\ninterpretations when reading environment variables:\n\n`bool` attributes can be:\n\n- `True`, `true`, or `1` for true.\n- `False`, `false`, or `0` for false.\n\n\n### Read Only Attributes\n\nWhen this configuration is defined,\nit is not possible to change the attributes\n\nExample:\n\n```python\nfrom envclass import EnvClass\n\n\nclass EnvLock(EnvClass)\n    KEY: str = None\n\n# Generates an AttributeError stating \n# that it is read-only\nEnvLock.KEY = 'Value'\n```\n\n### Lower Attrubutes\n\nLowercase attributes work the same way,\nI just thought leaving everything capitalized\nwould look better\n\nSince the name is closest to the environment variable read\n\nExample:\n\n`.env`\n```env\nLOWER_KEY='lower'\n```\n\n```python\nfrom envclass import EnvClass\n\nclass EnvLower(EnvClass):\n    _env_file = '.env'\n    lower_key = 'upper'\n\n# Return: 'lower'\nEnvLower.lower_key\n```\n\n### See your variables\n\nThe class is seen this way:\n\n`.env`\n```env\nENV_A=3\nENV_B=1\nENV_C=10\n```\n\n```python\nfrom envclass import EnvClass\n\nclass Env(EnvClass):\n    _env_file = '.env'\n    _prefix = 'ENV'\n\n    A: str\n    B: bool = False\n    C: int\n\nprint(Env)\n```\n\nOutput:\n\n```env\nENV_A='3'\nENV_B=True\nENV_C=10\n```\n\n\n### Special Attributes\n\n#### Env File\nBy default, this is set to `None`.\n\nIt is used to read the file like `.env`\n\n\nExample:\n\n```python\n# file: no_load_env.py\n\nfrom envclass import EnvClass\n\n\nclass NoEnv(EnvClass):\n    WAIT_TIME: int = 10\n\n\nprint(NoEnv.WAIT_TIME)\n```\n\nExecution on Linux:\n\n```sh\n$ WAIT_TIME=5 python no_load_env.py\n5\n```\n\n#### Strict Mode\nBy default, this is set to `True`.\n\nThis allows using `environ[key]` to signal when an\nenvironment variable is not defined, generating\nthe default `KeyError` error if the variable\ndoes not have a default value. If set to\n`False`, attributes that do not exist\nwill return `None`.\n\nExamples:\n\n```python\nfrom envclass import EnvClass\n\n# Disabled strict mode\nclass NotStrict(EnvClass):\n    _strict = False\n    NOT_EXISTS: str\n\n# Returns None\nNotStrict.NOT_EXISTS\n\n\n# Enabled strict mode\n# Generates a KeyError\nclass Strict(EnvClass):\n    _strict = True\n    NOT_EXISTS: str\n```\n\n#### Prefix\nBy default, there is `None`\n\nThis allows adding a string at the beginning\nof the environment variable name,\nmaking it easier to organize.\n\nExample:\n\n`.env`\n```env\nDB_USER=dev_user\nDB_KEY=dev_key_123\n```\n\n```python\nfrom envclass import EnvClass\n\nclass DataBase(EnvClass):\n    _env_file = '.env'\n    _prefix = 'DB'\n\n    NAME: str = 'Dev'\n    HOST: str = 'localhost'\n\n    USER: str\n    KEY: str\n\n# Return: 'Dev'\nDataBase.NAME\n\n# Return: dev_key_123\nDataBase.KEY\n```\n\n\n[PYPI]: https://pypi.python.org/pypi/envclass\n[CI]: https://github.com/brunodavi/envclass/actions/workflows/pipeline.yml\n\n[BadgeGNU]: https://img.shields.io/pypi/l/envclass.svg\n[BadgeVersion]: https://img.shields.io/pypi/v/envclass.svg\n[BadgePyVersions]: https://img.shields.io/pypi/pyversions/envclass.svg\n[BadgePipeline]: https://github.com/brunodavi/envclass/actions/workflows/pipeline.yml/badge.svg\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunodavi%2Fenvclass","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrunodavi%2Fenvclass","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrunodavi%2Fenvclass/lists"}