{"id":34090910,"url":"https://github.com/jmlepisto/envresolver","last_synced_at":"2026-03-09T16:03:07.740Z","repository":{"id":57426656,"uuid":"426356200","full_name":"jmlepisto/envresolver","owner":"jmlepisto","description":"Pythonic and lightweight resolving of environment variables","archived":false,"fork":false,"pushed_at":"2022-01-21T21:53:07.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-01-14T12:22:53.447Z","etag":null,"topics":["environment-variables","library","parsing","python","shell"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jmlepisto.png","metadata":{"files":{"readme":"README.md","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}},"created_at":"2021-11-09T19:15:51.000Z","updated_at":"2022-01-03T13:27:59.000Z","dependencies_parsed_at":"2022-09-19T06:00:49.634Z","dependency_job_id":null,"html_url":"https://github.com/jmlepisto/envresolver","commit_stats":null,"previous_names":["jjstoo/envresolver"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jmlepisto/envresolver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmlepisto%2Fenvresolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmlepisto%2Fenvresolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmlepisto%2Fenvresolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmlepisto%2Fenvresolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmlepisto","download_url":"https://codeload.github.com/jmlepisto/envresolver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmlepisto%2Fenvresolver/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30301524,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-09T14:33:48.460Z","status":"ssl_error","status_checked_at":"2026-03-09T14:33:48.027Z","response_time":61,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["environment-variables","library","parsing","python","shell"],"created_at":"2025-12-14T14:28:52.026Z","updated_at":"2026-03-09T16:03:07.729Z","avatar_url":"https://github.com/jmlepisto.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Envresolver\nEnvresolver is a Python library for parsing [environment variables](https://en.wikipedia.org/wiki/Environment_variable) \nto common Python datatypes. Environment variables are only accessible as pure text (string) typed variables and thus need\nsome manipulation to transform into any other types. `EnvResolver` class provides a nifty way of parsing the current \nenvironment according to given specifications.\n\nInstall with pip:\n`pip install envresolver`\n\n#### Supported types (at the moment)\n- `str`\n- `bool`\n- `int`\n- `float`\n- `list` holding any of the supported types\n- `Json`\n- `XML`\n- `datetime`\n\n#### Why Envresolver?\nEnvresolver is a lightweight alternative to other environment parsers and customizable by-design. \nAdding support for new types is ultra-simplified and does not need any source modifications of the library itself.\n\n\n## Usage\n\nAll variables to-be-resolved must be specified with a supported type when using `EnvResolver`. `EnvResolver` then inspects\nall the specified variables and tries to parse an environment variable with the same name to the given type format. For example,\nto parse simple string values:\n\n```python\nfrom envresolver import EnvResolver\n\nr = EnvResolver()\nr.add_variable(\"var\")\nr.resolve()\n```\n\nIf an environment variable `var` was present in the current environment, it can be accessed after resolving by a special \nnamespace member `ns` or by an explicit method `getr`.\n\n```python\nr.ns.var\n# Or\nr.getr(\"var\")\n```\n\nAdditionally, variables can also be fetched from the current environment without pre-calculated resolving.\nThis is suitable for simple variables and values that can change constantly:\n\n```python\nfrom envresolver import EnvResolver\n\nr = EnvResolver()\nr.get(\"var\")\n```\n\n\nUser can also supply default values to all requests:\n\n```python\nr.add_variable(\"var2\", default=\"default_value\")\n# Or\nr.get(\"var2\", default=\"default_value\")\n```\n\n### Environment Variables with Type Conversions\n\nAs stated before, `EnvResolver` also supports automated type conversions for environment variables. Variable types can\nbe specified as shown:\n\n```python\nr.add_variable(\"var\", t=int, default=-1)\n# Or\nr.get(\"var\", t=int, default=-1)\n```\n\nLet's imagine the current environment would hold the variable `var` with a value of `\"5\"`. By running `EnvResolver.resolve`, \nit would be automatically parsed. However, if the environment variable `var` would hold an incompatible value, `\"_\"` as an example,\nthe parsing would fail and `r.var` would hold the default value, if one was given:\n\n```python\nfrom envresolver import EnvResolver\n\n# export var=5\nr = EnvResolver()\nr.add_variable(\"var\", t=int, default=-1)\nr.resolve()\nr.ns.var  # 5\n\n# export var=_\nr = EnvResolver()\nr.add_variable(\"var\", t=int, default=-1)\nr.resolve()\nr.ns.var  # -1\n```\n\n### Advanced Types\n\n`EnvResolver` currently supports also some more advanced types of variables, such as lists, Json and XML. Lists have full support\nof type hinting and will try to convert all elements accordingly:\n\n```python\nfrom typing import List\nfrom envresolver import EnvResolver\n\n# export my_list=\"1,2,3,4\"\nr = EnvResolver()\nr.add_variable(\"my_list\", t=List[int])\nr.resolve()\nr.ns.my_list  # [1, 2, 3, 4]\n```\n\nJson and XML are supported via custom type notations stored in `envresolver.Types`. Json and XML will be parsed using Pythons built-in\n`json` and `xml` modules. Json parsing will output native python lists/dicts and XML results will be of type `xml.etree.ElementTree.Element`.\nHere is an example on Json parsing:\n\n```python\nfrom envresolver import EnvResolver, Types\n\n# export json='{\"key\": \"val\"}'\nr = EnvResolver()\nr.add_variable(\"json\", t=Types.Json)\nr.resolve()\nr.ns.json  # {\"key\": \"val\"}\n```\n\nDate objects are supported via Pythons built-in `datetime` module. User can specify in which format the date strings are expected, with the default being\n`%Y-%m-%d %H:%M:%S`. Here is an example:\n\n```python\nimport datetime\nfrom envresolver import EnvResolver\n\n# export mydate=\"2021-01-01 12:34:56\"\nr = EnvResolver()\nr.add_variable(\"mydate\", datetime.datetime)\nr.resolve()\nr.ns.mydate # datetime.datetime -object with the correct time\n```\n\nParsing certain advaced types, such as `datetime` objects or lists, relies on additional information\nregarding the data format. List parsing needs to know the list separator character and datetime conversions\nrely on certain date formats. These can be configured either at `EnvResolver` initialization or afterwards using\nthe methods `set_list_separator` and `set_datetime_format`.\n\n### Custom Types\n\nUsers can supply `EnvResolver` with custom parsers as well as override existing ones. Below is an example of using a custom parser\nfor reading data into a user-defined class:\n\n```python\nfrom envresolver import EnvResolver\n\n\nclass MyData:\n    def __init__(self, a, b):\n        self.a = a\n        self.b = b\n\n\ndef my_data_converter(e: str):\n    s = e.split(\".\")\n\n    # Raise ValueError if the given \n    # environment variable is in \n    # wrong format\n    if len(s) != 2:\n        raise ValueError\n\n    # Return parsed data\n    return MyData(a=s[0], b=s[1])\n\n\n# export data=\"john.smith\"\nr = EnvResolver()\nr.add_converter(MyData, my_data_converter)\nr.add_variable(\"data\", t=MyData)\nr.resolve()\nr.ns.data  # MyData(a = \"john\", b = \"smith\")\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmlepisto%2Fenvresolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmlepisto%2Fenvresolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmlepisto%2Fenvresolver/lists"}