Package: envjoy
envjoyA more enjoyable environment variable getter and setter - for Python.IntroductionEnvironment variable getting and setting has a bit of an itch 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.InstallInstall usingpip:$pipinstallenvjoyUseVery basicexample:from__future__importprint_function# Optional: Python 2 support for `env.print`fromenvjoyimportenv# non-casted access - never throws annoying errorsenv.FOOenv.FOO=1delenv.FOOenv.FOO=1# casted access - never throws annoying errorsdelenv['FOO']print('---')print(env['FOO'])# => Noneenv['FOO']=1# set value without complaints (casted to string)print(env['FOO'])# => "1"print(env['FOO'])# => 1print('---')env['FOO']=Noneprint(env['FOO'])# => ''print(env['FOO',bool])# => Falseprint(env['FOO',int])# => 0print(env['FOO',float])# => 0.0print(env['FOO',str])# => ''print(env['FOO',tuple])# => ()print(env['FOO',list])# => []print(env['FOO',dict])# => {}print('---')env['FOO']=Trueprint(env['FOO'])# => 'True'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 1print(env['FOO',float])# => 1.0print(env['FOO',str])# => 'true'print(env['FOO',tuple])# => (True)print(env['FOO',list])# => [True]print(env['FOO',dict])# => {}print('---')env['FOO']='true'# => 'true'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 1print(env['FOO',float])# => 1.0print(env['FOO',str])# => 'true'print(env['FOO',tuple])# => (True)print(env['FOO',list])# => [True]print(env['FOO',dict])# => {}print('---')env['FOO']=0print(env['FOO'])# => '0'print(env['FOO',bool])# => Falseprint(env['FOO',int])# => 0print(env['FOO',float])# => 0.0print(env['FOO',str])# => '0'print(env['FOO',tuple])# => (0)print(env['FOO',list])# => [0]print(env['FOO',dict])# => {}print('---')env['FOO']='0'print(env['FOO'])# => '0'print(env['FOO',bool])# => Falseprint(env['FOO',int])# => 0print(env['FOO',float])# => 0.0print(env['FOO',str])# => '0'print(env['FOO',tuple])# => (0)print(env['FOO',list])# => [0]print(env['FOO',dict])# => {}print('---')env['FOO']=1print(env['FOO'])# => '1'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 1print(env['FOO',float])# => 1.0print(env['FOO',str])# => '1'print(env['FOO',tuple])# => (1)print(env['FOO',list])# => [1]print(env['FOO',dict])# => {}print('---')env['FOO']='1'print(env['FOO'])# => '1'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 1print(env['FOO',float])# => 1.0print(env['FOO',str])# => '1'print(env['FOO',tuple])# => (1)print(env['FOO',list])# => [1]print(env['FOO',dict])# => {}print('---')env['FOO']=-1print(env['FOO'])# => '-1'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => -1print(env['FOO',float])# => -1.0print(env['FOO',str])# => '-1'print(env['FOO',tuple])# => (-1)print(env['FOO',list])# => [1]print(env['FOO',dict])# => {}print('---')env['FOO']='-1'print(env['FOO'])# => '-1'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => -1print(env['FOO',float])# => -1.0print(env['FOO',str])# => '-1'print(env['FOO',tuple])# => (-1)print(env['FOO',list])# => [1]print(env['FOO',dict])# => {}print('---')env['FOO']=12.34print(env['FOO'])# => '12.34'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 12print(env['FOO',float])# => 12.34print(env['FOO',str])# => '12.34'print(env['FOO',tuple])# => (12.34)print(env['FOO',list])# => [12.34]print(env['FOO',dict])# => {}print('---')env['FOO']='12.34'print(env['FOO'])# => '12.34'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 12print(env['FOO',float])# => 12.34print(env['FOO',str])# => '12.34'print(env['FOO',tuple])# => (12.34)print(env['FOO',list])# => [12.34]print(env['FOO',dict])# => {}print('---')env['FOO']=-12.34print(env['FOO'])# => '-12.34'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => -12print(env['FOO',float])# => -12.34print(env['FOO',str])# => '-12.34'print(env['FOO',tuple])# => (-12.34)print(env['FOO',list])# => [-12.34]print(env['FOO',dict])# => {}print('---')env['FOO']='-12.34'print(env['FOO'])# => '-12.34'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => -12print(env['FOO',float])# => -12.34print(env['FOO',str])# => '-12.34'print(env['FOO',tuple])# => (-12.34)print(env['FOO',list])# => [-12.34]print(env['FOO',dict])# => {}print('---')env['FOO']='foo bar baz 1 2 3'print(env['FOO'])# => 'foo bar baz 1 2 3'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 123print(env['FOO',float])# => 123.0print(env['FOO',str])# => 'foo bar baz 1 2 3'print(env['FOO',tuple])# => ('foo bar baz 1 2 3')print(env['FOO',list])# => ['foo bar baz 1 2 3']print(env['FOO',dict])# => {}print('---')env['FOO']='foo,bar,baz,1,2,3'print(env['FOO'])# => 'foo,bar,baz,1,2,3'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 123print(env['FOO',float])# => 123.0print(env['FOO',str])# => 'foo,bar,baz,1,2,3'print(env['FOO',tuple])# => ('foo', 'bar', 'baz')print(env['FOO',list])# => ['foo', 'bar', 'baz']print(env['FOO',dict])# => {0: 'foo', 1: 'bar', 2: 'baz'}print('---')env['FOO']=('foo','bar','baz',1,2,3)print(env['FOO'])# => '(foo,bar,baz,1,2,3)'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 123print(env['FOO',float])# => 123.0print(env['FOO',str])# => '(foo,bar,baz,1,2,3)'print(env['FOO',tuple])# => ('foo', 'bar', 'baz')print(env['FOO',list])# => ['foo', 'bar', 'baz', 1, 2, 3]print(env['FOO',dict])# => {} # TODO:  {0: 'foo', 1: 'bar', 2: 'baz', 3: 1, 4: 2, 5: 3}print('---')env['FOO']=['foo','bar','baz',1,2,3]print(env['FOO'])# => '[foo,bar,baz,1,2,3]'print(env['FOO',bool])# => Trueprint(env['FOO',int])# => 123print(env['FOO',float])# => 123.0print(env['FOO',str])# => '[foo, bar, baz, 1, 2, 3]'print(env['FOO',tuple])# => ('foo', 'bar', 'baz', 1, 2, 3)print(env['FOO',list])# => ['foo', 'bar', 'baz', 1, 2, 3]print(env['FOO',dict])# => {} # TODO:  {0: 'foo', 1: 'bar', 2: 'baz', 3: 1, 4: 2, 5: 3}print('---')env['FOO']={'foo':1,'bar':2,'baz':3}print(env['FOO'])# => '{foo:1,bar:2,baz:3}' # REVIEW: handle nested jsonprint(env['FOO',bool])# => Trueprint(env['FOO',int])# => 123print(env['FOO',float])# => 123.0print(env['FOO',str])# => '{foo: 1, bar: 2, baz: 3}'print(env['FOO',tuple])# => ({0: 'foo', 1: 'bar', 2: 'baz', 3: 1, 4: 2, 5: 3})print(env['FOO',list])# => [{0: 'foo', 1: 'bar', 2: 'baz', 3: 1, 4: 2, 5: 3}]print(env['FOO',dict])# => {'foo': 1, 'bar': 2, 'baz': 3}# etc.print('---')env.inspect()print('---')env.print()print('---')TestClone down source code:$makeinstallRuncolorful tests, with only native environment (dependency sandboxing up to you):$maketestRunless colorful tests, withmulti-environment(usingtox):$maketest-toxAboutThis project was mainly initiated - in lack of solid existing alternatives - to be used at our work atMarkable.aito have common code conventions between various programming environments wherePython(research, CV, AI) is heavily used.LicenseReleased under the MIT license.