Skip to main content

Using environment variable to store global vars to the enrite project

Project description

GlobalVars

A way to implement global vars between classes using the environment variable "os.environ"

Last updates

  • Added a function to clear all setted vars clearAllVars and getAllVars. See the new functionalities in methods and methods exemples
  • Last update now adds dunders setitem, getitem and len making the class work as a dictionary. see the funcionalities in methods exemples setOrUpdateVar, getVar, and getAllVars

Importing

from globalVars import GlobalVars;
gv = GlobalVars()

Methods

This class has five classes to be used:

  • getAllVars
    • Description: return all vars setted in the environment
    • Params: no params needed
  • clearAllVars
    • Description: Delete all vars already setted
    • Params: no params needed
  • setVar
    • Description: Set a new variable
    • Params: Accepts a Dictionary with 'Name':Value containing one or more vars to add
  • getVar
    • Description: Get a setted variable
    • Params: Accepts a String with 'Name' containing the name of a var
  • removeVar
    • Description: Remove a variable
    • Params: accepts a Stringwith 'Name' or a List with "[Name1,Name2,...] containing one or more names of vars to remove
  • updateVar
    • Description: Update a variable
    • Params: accepts a Dictionary with {'Name':Value,...} containing one or more vars to update
  • setOrUpdateVar
    • Description: set a new variable or update it if already exists
    • Params: accepts a Dictionary with {'Name':Value,...} containing one or more vars to set or update

Methods Examples

*Remember that you imported GlobalVars as "gv"

getAllVars()

# Store all already setted vars in a local variable
myVars = gv.getAllVars()

# Print all the environment setted vars
print(gv.getAllVars())

# If you want to now how many vars are setted you can use len()
len(gv)

clearAllVars()

# Set a new var
gv.setVar({"test":"hello"})

# Clear all the vars setted
gv.clearAllVars()

# It will return an empty dictionary "{}"
gv.getAllVars()

setVar()

# Will be setted two vars: "foo" with value "bar" and "eggs" with value 16
gv.setVar({"foo":"bar","eggs":16}) 

# The "foo" var will be setted with a "bar" value
gv.setVar({"foo":"bar"}) 

getVar()

# Result var will be the value in "foo"
result = gv.get("foo") 

# Result var will be a list containing the result of all the three vars
result = gv.get(["foo","bars","eggs"]) 

# You can simply use gv as a dict to get the var
result = gv["foo"]

removeVar()

# Var "foo" will be removed
gv.removeVar("foo") 

# All the three vars ("foo", "bar" and "eggs") will be removed
gv.removeVar(["foo","bar","eggs"]) 

updateVar()

# Variable foo will be updated with the new value "bar"
gv.updateVar({"foo":"bar"}) 

# The two variables ("foo" and "eggs") will be updated with new values
gv.updateVar({"foo":"bar","eggs":16}) 

setOrUpdateVar()

# The var "foo" will set if not exist, or will update with a new value if already exist a var with "foo" name
gv.setOrUpdater({"foo":"bar"}) 

# Two vars will be setted (if not exist) or their values will be updated (if they already exist)
gv.setOrUpdateVar({"foo":"bar","eggs":16}) 

# You can use gv as a dict to add a new or update an existing var
gv["test"] = "Hello" 	      # setted a new one
gv["test"] "Oh, hey there"    # Update an existing one

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

GlobalVars-0.0.5.tar.gz (5.1 kB view details)

Uploaded Source

File details

Details for the file GlobalVars-0.0.5.tar.gz.

File metadata

  • Download URL: GlobalVars-0.0.5.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.2

File hashes

Hashes for GlobalVars-0.0.5.tar.gz
Algorithm Hash digest
SHA256 d828b99da1f72eec25620c37f3286177a624fb7b418a31237a6173930b64ff41
MD5 1de6428f79f2e86da6bcde00128f681a
BLAKE2b-256 bb566cf3c6d000a16e78258e34b75fc9fe83b9c90a7a384eb210788495621a82

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page