Package: adi-env-parser
Environment parserRequirementsPython - Minimum required version is 3.8Using the environment parserEnvironmentParser class parses all environment variables with certain prefix and
creates a Python dictionary based on the structure of these variables. The values
are converted to booleans and integers when detected as such by default.General variable structure rules:variable name after prefix should not be emptyfirst character of variable name after prefix should not be "_"different levels of depth within environment variables are specified by using
"__" string.arrays can be specified by using numeric index as a key within particular levelarray numeric indices should be defined in order, variables with invalid index
will be discardedValue conversion rules:value will be converted to boolean if it matchestrueorfalsewhen lower
casedvalue will be converted to integer if it contains digits onlyUsing the EnvironmentParser classExample of instantiating of EnvironmentParser object usingMYPREFIXas a prefix
for environment variables. Upon instantiation, the object will automatically parse
the current environment variables and store them in itsconfigurationproperty.importjsonfromadi_env_parserimportEnvironmentParserparser=EnvironmentParser(prefix="MYPREFIX")print(json.dump(json.dumps(parser.configuration,indent=4)))It is possible to provide existing JSON formatted file as a configuration base.importjsonfromadi_env_parserimportEnvironmentParserparser=EnvironmentParser(prefix="MYPREFIX",config_file="configuration.json")print(json.dump(json.dumps(parser.configuration,indent=4)))It is possible to disable value conversion by settingconvert_valuesparameter
when instantiatingEnvironmentParserobject.fromadi_env_parserimportEnvironmentParserparser=EnvironmentParser(prefix="MYPREFIX",convert_values=False)ExamplesExamples use PYENV as environment variable prefix. This is default prefix used
when not specifying one explicitly when instatiating EnvironmentParser.Creating dictionaryEnvironment variables:PYENV_hotel_name="Blue Falcon"PYENV_rooms__room_1="James Holden"PYENV_rooms__room_2="Amos Burton"PYENV_rooms__room_3="Naomi Nagata"PYENV_rooms__room_4="Alex Kamal"Resulting object:{"hotel_name":"Blue Falcon","rooms":{"room_1":"James Holden","room_2":"Amos Burton","room_3":"Naomi Nagata","room_4":"Alex Kamal"}}Creating arrayEnvironment variables:PYENV_hotel_name="Blue Falcon"PYENV_room_1__inventory__0="Wardrobe"PYENV_room_1__inventory__1="Table"PYENV_room_1__inventory__2="Lamp"Resulting object:{"hotel_name":"Blue Falcon","room_1":{"inventory":["Wardrobe","Table","Lamp"]}}Dictionaries within listEnvironment variables:PYENV_hotel_name="Blue Falcon"PYENV_rooms__0__name="Room 1"PYENV_rooms__0__capacity="2"PYENV_rooms__2__name="Room 2"PYENV_rooms__2__capacity="2"Resulting object:{"hotel_name":"Blue Falcon","rooms":[{"name":"Room 1","capacity":"2"},{"name":"Room 2","capacity":"2"}]}Console utilityModule provides console utility which can be used for parsing of environment
variables. It also supports reading of existing JSON formatted file and setting
indentation for output of created configuration JSON object.➜adi-env-parser--help
usage:adi-env-parser-p<prefix>-j<base_json_file>

ParsesenvironmentvariableswithdefinedprefixandcreatesJSONoutputfromtheparsedstructure.

optionalarguments:-h,--helpshowthishelpmessageandexit--prefix[PREFIX],-p[PREFIX]Environmentvariableprefix.Default:PYENV--json[JSON],-j[JSON]JSONformattedfiletoreadasbaseconfiguration--indent[INDENT],-i[INDENT]NumberofspacestouseforindentationofoutputJSONstringDevelopmentInstall development packagespipinstall-e".[dev]"pipinstall-e".[test]"# Install build-local package group if you want to build packages locallypipinstall-e".[build-local]"Install pre-commitpre-commitinstallBuilding and publishing new versionNew version is built and published on tag in GitHub repository. The package version is infered from commit name.