Get values 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 Ini/Json-File for your several home projects at ones.
And not open it in public.
Features
- load values to instance attrs from:
- Environment
- iniFile
- JsonFile
- attr access
- via any lettercase
see examples below - by instance attr
- via any lettercase
# {"AUTH": {"NAME": "MyName", "PWD": "MyPwd"}}
from private_values import *
class Cls:
data = PrivateAuthJson(_section="AUTH")
def connect(self):
name = self.data.NAME
name = self.data.NamE # case insensitive
- like dict key on instance
# {"AUTH": {"NAME": "MyName", "PWD": "MyPwd"}}
from private_values import *
class Cls:
data = PrivateAuthJson(_section="AUTH")
def connect(self):
name = self.data["NAME"]
name = self.data["NamE"] # case insensitive
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
use annotations for your param names (best practice!)
when instantiating if it will not get loaded these exact params from your private sources - RAISE!
but you could not use it and however keep access to all existed params in used section!
# {"AUTH": {"NAME": "MyName", "PWD": "MyPwd"}}
from private_values import *
class MyPrivateJson(PrivateJson):
NAME: str
PWD: str
name = MyPrivateJson().NAME
in example above you could simply use existed classes
from private_values import *
name = PrivateAuthJson().NAME
1. Env
from private_values import *
class Cls:
user = PrivateEnv["NAME"]
user = PrivateEnv.NAME
2. IniFile
- Use different sections
from private_values import *
class Cls:
user = PrivateIni(_section="CustomSection").NAME
- Change full settings
from private_values import *
class CustomIniValues(PrivateIni):
DIRPATH = "new/path/"
DIRPATH = pathlib.Path("new/path/")
FILENAME = "my.ini"
SECTION = "CustomSection"
class Cls:
user = CustomIniValues.NAME
- Without creating new class
from private_values import *
class Cls:
pv1 = PrivateIni(_filename="otherFilename").pv1
3. JsonFile
# {"AUTH": {"NAME": "MyName", "PWD": "MyPwd"}}
from private_values import *
class MyPrivateJson(PrivateJson):
SECTION = "AUTH"
NAME: str
PWD: str
class Cls:
data = MyPrivateJson()
def connect(self):
name = self.data.NAME
- use already created templates (PrivateAuthJson/PrivateTgBotAddressJson) for standard attributes
# {"AUTH": {"NAME": "MyName", "PWD": "MyPwd"}}
from private_values import *
class Cls:
data = PrivateAuthJson(_section="AUTH")
def connect(self):
name = self.data.NAME
4. Auto
you can use universal class
it will trying get all your annotated params from one source of Json/Ini/Env (in exact order)
in this case you cant use FileName and must use annotations!
# {"AUTH": {"NAME": "MyName", "PWD": "MyPwd"}}
from private_values import *
class MyPrivate(PrivateAuto):
SECTION = "AUTH"
NAME: str
PWD: str
name = MyPrivate().NAME
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
Built Distribution
Hashes for private_values-0.4.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af9dceed3f6442635164a4da4a1129f079652cc8ab772333f88a0c0f73f1e3f4 |
|
MD5 | eb93df3d4d3ae944659d0660be081344 |
|
BLAKE2b-256 | e6a768f8a5cbb467fc52455886865f29c16a0b7918fceea195bafc44d4feceef |