Get from OsEnvironment or Ini/Json File
Reason this release was yanked:
while not used anywhere use new vertion!
Project description
private_values
Designed to use private data like username/pwd kept secure in OsEnvironment or IniFile for your several home projects at ones.
And not open it in public.
Main goals: short implementation and OOP usage.
Features
-
get values from:
- Environment
- iniFile
- JsonFile
-
raise if no name in destination
License
See the LICENSE file for license rights and limitations (MIT).
Release history
See the HISTORY.md file for release history.
Installation
pip install private-values
Import
from private_values import *
GUIDE
1. Env
- what a simple usage
can use bot class- and object-method
from private_values import *
class Cls:
user = PrivateEnv.get("NameInEnv_ForUser")
pwd = PrivateEnv().get("NameInEnv_ForPwd")
2. IniFile
- Use defaults (common usage)
from private_values import *
class Cls:
user = PrivateIni().get("NameInIni_ForUser")
pwd = PrivateIni().get("NameInIni_ForPwd")
- Use different sections
from private_values import *
class Cls:
user = PrivateIni().get("NameInIni_ForUser")
pwd = PrivateIni().get("NameInIni_ForPwd", _section="CustomSection")
- Change directory or filename or default section
from private_values import *
class CustomIniValues(PrivateIni):
DIRPATH = "new/path/"
DIRPATH = pathlib.Path("new/path/")
FILENAME = "my.ini"
SECTION = "CustomSection"
class Cls:
user = CustomIniValues.get("NameInIni_ForUser")
pwd = CustomIniValues.get("NameInIni_ForPwd")
- Without creating new class
from private_values import *
class Cls:
pv1 = PrivateIni(_filename="otherFilename").get("pv1")
pv2 = PrivateIni(_section="otherSection").get("pv2")
3. JsonFile
from private_values import *
class Cls:
user = PrivateJson().get("name1")
pwd = PrivateIni().get("name2")
or by instance attributes
# for Json
"""
{"AUTH": {"NAME": "MyName", "PWD": "MyPwd"}}
"""
from private_values import *
class MyPrivateJson(PrivateJson):
SECTION = "AUTH"
NAME: str
PWD: str
class Cls:
data = MyPrivateJson().get_section()
def connect(self):
name = self.data.NAME #
pwd = self.data.PWD
The same exists for PrivateIni
4. disable Exceptions
- in method
from private_values import *
class Cls:
user = PrivateEnv().get("Name_ForUser", _raise_exx=False)
pwd = PrivateIni().get("Name_ForPwd", _raise_exx=False)
def connect(self):
if None in [self.user, self.pwd]:
return
pass
- in whole class
from private_values import *
class CustomEnvValues(PrivateEnv):
RAISE_EXX = False
class CustomIniValues(PrivateIni):
RAISE_EXX = False
class Cls:
user = CustomEnvValues.get("Name_ForUser")
pwd = CustomIniValues.get("Name_ForPwd")
def connect(self):
if None in [self.user, self.pwd]:
return
pass
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
private_values-0.3.0.tar.gz
(5.8 kB
view hashes)
Built Distribution
Close
Hashes for private_values-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0cf2b0777cb6b8e902c40dcff21c715242c433e644f52df77891108fa9498855 |
|
MD5 | 91aa4f311b6c1d3cc79ba50ba1d4b89d |
|
BLAKE2b-256 | 212786f4d414a7bc3c25938bca70f22259ea5a4f6d8694b5a9e84c018bb15c69 |