Package: envist
EnvistA simple, lightweight, and easy to use environment variable manager for Python.Created byMd. Almas AliTable of ContentsIntroductionFeaturesInstallationFunctionsData TypesExamplesLicenseContributingFeaturesEnvist a simple, lightweight, and easy to use environment variable manager for Python. It can be used to get, set, unset, and save environment variables to a file. It also supports casting environment variables to a specific types as you need. It not only supports the casting from language spacific types but also supports casting from.envfile spacific types. For example, if you have a.envfile like this:# .env
name = John Doe
age = 20
is_admin = TrueThen you can get thenamevariable asstr,agevariable asint, andis_adminvariable asboollike this:importenvistenv=envist.Envist()name=env.get('name',cast=str)# Output: 'John Doe'age=env.get('age',cast=int)# Output: 20is_admin=env.get('is_admin',cast=bool)# Output: TrueIt has a spacial feature like never before. Now, withenvistyou can typecast your environment variables inside your.envfile. For example, if you have a.envfile like this:# .env
name <str> = John Doe
age <int> = 20
is_admin <bool> = TrueThen you can get thenamevariable asstr,agevariable asint, andis_adminvariable asboollike this:importenvistenv=envist.Envist()name=env.get('name')# Output: 'John Doe'print(type(name))# Output: <class 'str'>age=env.get('age')# Output: 20print(type(age))# Output: <class 'int'>is_admin=env.get('is_admin')# Output: Trueprint(type(is_admin))# Output: <class 'bool'>Here you don't need to specify thecastparameter. It will automatically cast the environment variables to the types you specified in your.envfile. This is like a constant typecasting. You can also override the typecasting by specifying thecastparameter.Envist also supports variable expansion. For example, if you have a.envfile like this:# .env
server <str> = 127.0.0.1
port <int> = 8080
url <str> = http://${server}:${port}Then you can get theurlvariable like this:importenvistenv=envist.Envist()url=env.get('url')# Output: 'http://127.0.0.1:8080'InstallationInstallenvistusingpip:pipinstallenvistFunctionsEnvist class has the following functions:FunctionDescriptionParametersReturn TypegetGet a specific env variablekey(str),default(any),cast(type)anyget_allGet all env variablesNonedictsetSet a specific env variablekey(str),value(any)Noneset_allSet multiple env variablesvariables(dict)NoneunsetUnset a specific env variablekey(str)Noneunset_allUnset multiple env variableskeys(list)NonesaveSave updated env variables to filepretty(bool),sort_keys(bool)NoneData TypesEnvist supports the following data types:Data TypeDescriptionStatusstrStringSupportedfloatFloatSupportedboolBooleanSupportedlist,ListArraySupporteddict,DictObjectDevelopmenttuple,TupleTupleDevelopmentset,SetSetDevelopmentCSVCSVDevelopmentJSONJSONDevelopmentNote:Multi-line expressions are not supported yet. It will be supported in the next version.ExamplesfromenvistimportEnvistenv=Envist()# Print env object as stringprint(env)# <Envist path=".env"># Get default env file pathprint(env.path)# .env# Custom env file path or file nameenv=Envist(path='my/path/.env')# Get a specific env variableenv.get('name')# Get a specific env variable with default valueenv.get('name',default='John Doe')# Get a specific env variable with default value and castenv.get('name',default='John Doe',cast=int)# Get all env variablesenv.get_all()# Set a specific env variableenv.set('name','John Doe')env.set('age',20)env.set('is_admin',True)# Set multiple env variablesenv.set_all({'name':'John Doe','age':20,'is_admin':True})# Unset a specific env variableenv.unset('name')# Unset multiple env variablesenv.unset_all(['name','age'])# Unset all env variablesenv.unset_all()# Save updated env variables to file# Save to default file, i.e. .env. You can also specify a custom file path in Emvist constructor object.env.save(pretty=True,# Pretty printsort_keys=True# Sort keys)# Get a list from env variable# list_elements <list> = 1, 2, 3, 4, 5env.get('list_elements',cast=list)# Working with variables# server <str> = 127.0.0.1# port <int> = 8080# url <str> = http://${server}:${port}env.get('url')# Output: 'http://127.0.0.1:8080'LicenseThis project is licensed under the MIT License - see theLICENSEfile for details.ContributingFork it.Create your feature branch (git checkout -b feature/feature-name).Commit your changes (git commit -am 'Add some feature').Push to the branch (git push origin feature/feature-name).Create a new Pull Request.