Name | env-get JSON |
Version |
1.1.0
JSON |
| download |
home_page | None |
Summary | Manage and get process.env |
upload_time | 2025-01-08 04:55:13 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3 |
license | Copyright (c) 2013 kaelzhang <>, contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
env-get
env
process.env
environment variable
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[](https://github.com/kaelzhang/python-env-get/actions/workflows/python.yml)
[](https://codecov.io/gh/kaelzhang/python-env-get)
[](https://pypi.org/project/env-get/)
[](https://github.com/kaelzhang/python-env-get)
<!-- [](https://anaconda.org/conda-forge/env-get) -->
# env-get
Manage and retrieve env variables in Python.
## Install
```sh
$ pip install env-get
```
## Usage
```py
from env_get import env
port = env('SERVER_PORT', env.integer, 80)
```
## env(key, converter, defaults) -> Any
```py
def Converter(v: Any, key: str, is_default: bool) -> Any:
```
- **key** `str`: The environment variable key.
- **converter** `Optional[Converter | List[Converter]]` A converter function or a list of converter functions.
- **v** the current value of the variable
- **key** the key of the environment variable
- **is_default** `True` means the environment variable is not set, even not set as `FOO=`
- **defaults** `Opitonal[Any]` The optional default value if the environment variable is not found.
Returns `Any` the retrieved env variable.
### Built-in Converter Functions
- **`env.boolean`**: Converts the value to a boolean. Treats `'true'`, `'1'`, `'Y'`, `'y'`, `'yes'`, and `True` as `True`.
- **`env.integer`**: Converts the value to an integer. Returns `0` if conversion fails.
- **`env.required`**: Ensures that the environment variable is set. Raises a `EnvRequiredError` if not.
## Examples
### Boolean Conversion
```py
debug_mode = env('DEBUG_MODE', env.boolean, False)
```
### Integer Conversion
```py
port = env('PORT', env.integer, 8080)
```
### Required Variable
```py
from env_get import env, EnvRequiredError
try:
api_key = env('API_KEY', env.required)
except RangeError as e:
print(e) # Output: env "API_KEY" is required
```
### Handling Multiple Converters
You can apply multiple converters by passing a list of converter functions.
```py
value = env('SOME_VAR', [env.required, env.integer], 10)
```
## License
[MIT](LICENSE)
Raw data
{
"_id": null,
"home_page": null,
"name": "env-get",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3",
"maintainer_email": null,
"keywords": "env-get, env, process.env, environment variable",
"author": null,
"author_email": "Kael Zhang <i+pypi@kael.me>",
"download_url": "https://files.pythonhosted.org/packages/a7/73/68ca410cb688e29c823d105545222dd3c74c3b243506a3b3c6e760779397/env_get-1.1.0.tar.gz",
"platform": null,
"description": "[](https://github.com/kaelzhang/python-env-get/actions/workflows/python.yml)\n[](https://codecov.io/gh/kaelzhang/python-env-get)\n[](https://pypi.org/project/env-get/)\n[](https://github.com/kaelzhang/python-env-get)\n\n<!-- [](https://anaconda.org/conda-forge/env-get) -->\n\n# env-get\n\nManage and retrieve env variables in Python.\n\n## Install\n\n```sh\n$ pip install env-get\n```\n\n## Usage\n\n```py\nfrom env_get import env\n\nport = env('SERVER_PORT', env.integer, 80)\n```\n\n## env(key, converter, defaults) -> Any\n\n```py\ndef Converter(v: Any, key: str, is_default: bool) -> Any:\n```\n\n- **key** `str`: The environment variable key.\n- **converter** `Optional[Converter | List[Converter]]` A converter function or a list of converter functions.\n - **v** the current value of the variable\n - **key** the key of the environment variable\n - **is_default** `True` means the environment variable is not set, even not set as `FOO=`\n- **defaults** `Opitonal[Any]` The optional default value if the environment variable is not found.\n\nReturns `Any` the retrieved env variable.\n\n### Built-in Converter Functions\n\n- **`env.boolean`**: Converts the value to a boolean. Treats `'true'`, `'1'`, `'Y'`, `'y'`, `'yes'`, and `True` as `True`.\n- **`env.integer`**: Converts the value to an integer. Returns `0` if conversion fails.\n- **`env.required`**: Ensures that the environment variable is set. Raises a `EnvRequiredError` if not.\n\n## Examples\n\n### Boolean Conversion\n\n```py\ndebug_mode = env('DEBUG_MODE', env.boolean, False)\n```\n\n### Integer Conversion\n\n```py\nport = env('PORT', env.integer, 8080)\n```\n\n### Required Variable\n\n```py\nfrom env_get import env, EnvRequiredError\n\ntry:\n api_key = env('API_KEY', env.required)\nexcept RangeError as e:\n print(e) # Output: env \"API_KEY\" is required\n```\n\n### Handling Multiple Converters\n\nYou can apply multiple converters by passing a list of converter functions.\n\n```py\nvalue = env('SOME_VAR', [env.required, env.integer], 10)\n```\n\n## License\n\n[MIT](LICENSE)\n",
"bugtrack_url": null,
"license": "Copyright (c) 2013 kaelzhang <>, contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Manage and get process.env",
"version": "1.1.0",
"project_urls": {
"Homepage": "https://github.com/kaelzhang/python-env-get"
},
"split_keywords": [
"env-get",
" env",
" process.env",
" environment variable"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "0de026c5dc9efb7bfe4d8d2e1d42f4a292c06352dd2f7417e143c116b65c3ca6",
"md5": "a79af46eb5cd02ba01462b0c49c344c6",
"sha256": "aec5a953065e985564f260139c8d935b63a81a386a628d6a6d958beb439be1d4"
},
"downloads": -1,
"filename": "env_get-1.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a79af46eb5cd02ba01462b0c49c344c6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3",
"size": 5233,
"upload_time": "2025-01-08T04:55:11",
"upload_time_iso_8601": "2025-01-08T04:55:11.403950Z",
"url": "https://files.pythonhosted.org/packages/0d/e0/26c5dc9efb7bfe4d8d2e1d42f4a292c06352dd2f7417e143c116b65c3ca6/env_get-1.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "a77368ca410cb688e29c823d105545222dd3c74c3b243506a3b3c6e760779397",
"md5": "e356d02014852778d7dc3fa5ea4d6ef6",
"sha256": "7cfcb2a659b3c34ad8cc52194b31b1cbe10ebb27b801d7a6ac3cf0f4d72713fb"
},
"downloads": -1,
"filename": "env_get-1.1.0.tar.gz",
"has_sig": false,
"md5_digest": "e356d02014852778d7dc3fa5ea4d6ef6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3",
"size": 5696,
"upload_time": "2025-01-08T04:55:13",
"upload_time_iso_8601": "2025-01-08T04:55:13.391376Z",
"url": "https://files.pythonhosted.org/packages/a7/73/68ca410cb688e29c823d105545222dd3c74c3b243506a3b3c6e760779397/env_get-1.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-08 04:55:13",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "kaelzhang",
"github_project": "python-env-get",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "env-get"
}