{"id":15578322,"url":"https://github.com/grimen/python-envjoy","last_synced_at":"2025-03-29T07:27:10.859Z","repository":{"id":57426635,"uuid":"167799295","full_name":"grimen/python-envjoy","owner":"grimen","description":"A more enjoyable environment variable getter and setter - for Python.","archived":false,"fork":false,"pushed_at":"2019-05-17T05:52:05.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T06:51:32.201Z","etag":null,"topics":["caster","env","environ","environment","getter","key","parser","python","python2","python3","setter","value","variable"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/envjoy","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/grimen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"MIT-LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-27T11:05:21.000Z","updated_at":"2019-05-17T05:52:06.000Z","dependencies_parsed_at":"2022-09-19T06:41:17.161Z","dependency_job_id":null,"html_url":"https://github.com/grimen/python-envjoy","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-envjoy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-envjoy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-envjoy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/grimen%2Fpython-envjoy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/grimen","download_url":"https://codeload.github.com/grimen/python-envjoy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246153616,"owners_count":20732032,"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":["caster","env","environ","environment","getter","key","parser","python","python2","python3","setter","value","variable"],"created_at":"2024-10-02T19:08:45.325Z","updated_at":"2025-03-29T07:27:10.837Z","avatar_url":"https://github.com/grimen.png","language":"Python","readme":"\n# `envjoy` [![PyPI version](https://badge.fury.io/py/envjoy.svg)](https://badge.fury.io/py/envjoy) [![Build Status](https://travis-ci.com/grimen/python-envjoy.svg?branch=master)](https://travis-ci.com/grimen/python-envjoy) [![Coverage Status](https://codecov.io/gh/grimen/python-envjoy/branch/master/graph/badge.svg)](https://codecov.io/gh/grimen/python-envjoy)\n\n*A more enjoyable environment variable getter and setter - for Python.*\n\n## Introduction\n\nEnvironment variable getting and setting has a bit of an itch to it. This is a not-so-whiny library that makes it more easy to get and set environment variables, and optionally smarter data type interpretation.\n\n\n## Install\n\nInstall using **pip**:\n\n```sh\n$ pip install envjoy\n```\n\n\n## Use\n\nVery basic **[example](https://github.com/grimen/python-envjoy/tree/master/examples/basic.py)**:\n\n```python\nfrom __future__ import print_function # Optional: Python 2 support for `env.print`\n\nfrom envjoy import env\n\n# non-casted access - never throws annoying errors\n\nprint(env.FOO)\n\nenv.FOO = 1\n\nprint(env.FOO)\n\ndel env.FOO\n\nprint(env.FOO)\n\n# casted access - never throws annoying errors\n\ndel env['FOO']\n\nprint('---')\n\nprint(env['FOO']) # =\u003e None\n\nenv['FOO']= 1 # set value without complaints (casted to string)\n\nprint(env['FOO']) # =\u003e \"1\"\nprint(env['FOO']) # =\u003e 1\n\nprint('---')\n\nenv['FOO'] = None\n\nprint(env['FOO']) # =\u003e ''\nprint(env['FOO', bool]) # =\u003e False\nprint(env['FOO', int]) # =\u003e 0\nprint(env['FOO', float]) # =\u003e 0.0\nprint(env['FOO', str]) # =\u003e ''\nprint(env['FOO', tuple]) # =\u003e ()\nprint(env['FOO', list]) # =\u003e []\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = True\n\nprint(env['FOO']) # =\u003e 'True'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 1\nprint(env['FOO', float]) # =\u003e 1.0\nprint(env['FOO', str]) # =\u003e 'true'\nprint(env['FOO', tuple]) # =\u003e (True)\nprint(env['FOO', list]) # =\u003e [True]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = 'true' # =\u003e 'true'\n\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 1\nprint(env['FOO', float]) # =\u003e 1.0\nprint(env['FOO', str]) # =\u003e 'true'\nprint(env['FOO', tuple]) # =\u003e (True)\nprint(env['FOO', list]) # =\u003e [True]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = 0\n\nprint(env['FOO']) # =\u003e '0'\nprint(env['FOO', bool]) # =\u003e False\nprint(env['FOO', int]) # =\u003e 0\nprint(env['FOO', float]) # =\u003e 0.0\nprint(env['FOO', str]) # =\u003e '0'\nprint(env['FOO', tuple]) # =\u003e (0)\nprint(env['FOO', list]) # =\u003e [0]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = '0'\n\nprint(env['FOO']) # =\u003e '0'\nprint(env['FOO', bool]) # =\u003e False\nprint(env['FOO', int]) # =\u003e 0\nprint(env['FOO', float]) # =\u003e 0.0\nprint(env['FOO', str]) # =\u003e '0'\nprint(env['FOO', tuple]) # =\u003e (0)\nprint(env['FOO', list]) # =\u003e [0]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = 1\n\nprint(env['FOO']) # =\u003e '1'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 1\nprint(env['FOO', float]) # =\u003e 1.0\nprint(env['FOO', str]) # =\u003e '1'\nprint(env['FOO', tuple]) # =\u003e (1)\nprint(env['FOO', list]) # =\u003e [1]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = '1'\n\nprint(env['FOO']) # =\u003e '1'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 1\nprint(env['FOO', float]) # =\u003e 1.0\nprint(env['FOO', str]) # =\u003e '1'\nprint(env['FOO', tuple]) # =\u003e (1)\nprint(env['FOO', list]) # =\u003e [1]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = -1\n\nprint(env['FOO']) # =\u003e '-1'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e -1\nprint(env['FOO', float]) # =\u003e -1.0\nprint(env['FOO', str]) # =\u003e '-1'\nprint(env['FOO', tuple]) # =\u003e (-1)\nprint(env['FOO', list]) # =\u003e [1]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = '-1'\n\nprint(env['FOO']) # =\u003e '-1'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e -1\nprint(env['FOO', float]) # =\u003e -1.0\nprint(env['FOO', str]) # =\u003e '-1'\nprint(env['FOO', tuple]) # =\u003e (-1)\nprint(env['FOO', list]) # =\u003e [1]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = 12.34\n\nprint(env['FOO']) # =\u003e '12.34'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 12\nprint(env['FOO', float]) # =\u003e 12.34\nprint(env['FOO', str]) # =\u003e '12.34'\nprint(env['FOO', tuple]) # =\u003e (12.34)\nprint(env['FOO', list]) # =\u003e [12.34]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = '12.34'\n\nprint(env['FOO']) # =\u003e '12.34'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 12\nprint(env['FOO', float]) # =\u003e 12.34\nprint(env['FOO', str]) # =\u003e '12.34'\nprint(env['FOO', tuple]) # =\u003e (12.34)\nprint(env['FOO', list]) # =\u003e [12.34]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = -12.34\n\nprint(env['FOO']) # =\u003e '-12.34'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e -12\nprint(env['FOO', float]) # =\u003e -12.34\nprint(env['FOO', str]) # =\u003e '-12.34'\nprint(env['FOO', tuple]) # =\u003e (-12.34)\nprint(env['FOO', list]) # =\u003e [-12.34]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = '-12.34'\n\nprint(env['FOO']) # =\u003e '-12.34'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e -12\nprint(env['FOO', float]) # =\u003e -12.34\nprint(env['FOO', str]) # =\u003e '-12.34'\nprint(env['FOO', tuple]) # =\u003e (-12.34)\nprint(env['FOO', list]) # =\u003e [-12.34]\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = 'foo bar baz 1 2 3'\n\nprint(env['FOO']) # =\u003e 'foo bar baz 1 2 3'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 123\nprint(env['FOO', float]) # =\u003e 123.0\nprint(env['FOO', str]) # =\u003e 'foo bar baz 1 2 3'\nprint(env['FOO', tuple]) # =\u003e ('foo bar baz 1 2 3')\nprint(env['FOO', list]) # =\u003e ['foo bar baz 1 2 3']\nprint(env['FOO', dict]) # =\u003e {}\n\nprint('---')\n\nenv['FOO'] = 'foo,bar,baz,1,2,3'\n\nprint(env['FOO']) # =\u003e 'foo,bar,baz,1,2,3'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 123\nprint(env['FOO', float]) # =\u003e 123.0\nprint(env['FOO', str]) # =\u003e 'foo,bar,baz,1,2,3'\nprint(env['FOO', tuple]) # =\u003e ('foo', 'bar', 'baz')\nprint(env['FOO', list]) # =\u003e ['foo', 'bar', 'baz']\nprint(env['FOO', dict]) # =\u003e {0: 'foo', 1: 'bar', 2: 'baz'}\n\nprint('---')\n\nenv['FOO'] = ('foo', 'bar', 'baz', 1, 2, 3)\n\nprint(env['FOO']) # =\u003e '(foo,bar,baz,1,2,3)'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 123\nprint(env['FOO', float]) # =\u003e 123.0\nprint(env['FOO', str]) # =\u003e '(foo,bar,baz,1,2,3)'\nprint(env['FOO', tuple]) # =\u003e ('foo', 'bar', 'baz')\nprint(env['FOO', list]) # =\u003e ['foo', 'bar', 'baz', 1, 2, 3]\nprint(env['FOO', dict]) # =\u003e {} # TODO:  {0: 'foo', 1: 'bar', 2: 'baz', 3: 1, 4: 2, 5: 3}\n\nprint('---')\n\nenv['FOO'] = ['foo', 'bar', 'baz', 1, 2, 3]\n\nprint(env['FOO']) # =\u003e '[foo,bar,baz,1,2,3]'\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 123\nprint(env['FOO', float]) # =\u003e 123.0\nprint(env['FOO', str]) # =\u003e '[foo, bar, baz, 1, 2, 3]'\nprint(env['FOO', tuple]) # =\u003e ('foo', 'bar', 'baz', 1, 2, 3)\nprint(env['FOO', list]) # =\u003e ['foo', 'bar', 'baz', 1, 2, 3]\nprint(env['FOO', dict]) # =\u003e {} # TODO:  {0: 'foo', 1: 'bar', 2: 'baz', 3: 1, 4: 2, 5: 3}\n\nprint('---')\n\nenv['FOO'] = {'foo': 1, 'bar': 2, 'baz': 3}\n\nprint(env['FOO']) # =\u003e '{foo:1,bar:2,baz:3}' # REVIEW: handle nested json\nprint(env['FOO', bool]) # =\u003e True\nprint(env['FOO', int]) # =\u003e 123\nprint(env['FOO', float]) # =\u003e 123.0\nprint(env['FOO', str]) # =\u003e '{foo: 1, bar: 2, baz: 3}'\nprint(env['FOO', tuple]) # =\u003e ({0: 'foo', 1: 'bar', 2: 'baz', 3: 1, 4: 2, 5: 3})\nprint(env['FOO', list]) # =\u003e [{0: 'foo', 1: 'bar', 2: 'baz', 3: 1, 4: 2, 5: 3}]\nprint(env['FOO', dict]) # =\u003e {'foo': 1, 'bar': 2, 'baz': 3}\n\n# etc.\n\nprint('---')\n\nenv.inspect()\n\nprint('---')\n\nenv.print()\n\nprint('---')\n```\n\n\n## Test\n\nClone down source code:\n\n```sh\n$ make install\n```\n\nRun **colorful tests**, with only native environment (dependency sandboxing up to you):\n\n```sh\n$ make test\n```\n\nRun **less colorful tests**, with **multi-environment** (using **tox**):\n\n```sh\n$ make test-tox\n```\n\n\n## About\n\nThis project was mainly initiated - in lack of solid existing alternatives - to be used at our work at **[Markable.ai](https://markable.ai)** to have common code conventions between various programming environments where **Python** (research, CV, AI) is heavily used.\n\n\n## License\n\nReleased under the MIT license.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrimen%2Fpython-envjoy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgrimen%2Fpython-envjoy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgrimen%2Fpython-envjoy/lists"}