Guiosoft Python Configuration Class
Project description
GS PY Config
Configuration class
Usage
Create your configuration class, extending config_guiosoft.ConfigClass
from config_guiosoft import ConfigClass
from datetime import datetime, time
class Config(ConfigClass):
STRING_CONF = "DEFAULT VALUE"
INT_CONF = 10
FLOAT_CONF = 0.0
BOOL_CONF = False
DATE = date.today()
DATETIME = datetime.now()
config = Config()
print(config)
>>> __main__.Config(BOOL_CONF:False,DATE:datetime.date(2020, 7, 30),DATETIME:datetime.datetime(2020, 7, 30, 18, 39, 55, 374515),FLOAT_CONF:0.0,INT_CONF:10,STRING_CONF:'DEFAULT VALUE')
When this class is instantiated, it loads values from environment variables with same name. If the variable is undefined, default values will be used.
Advanced usage
You can use ConfigType for special field behavior.
from config_guiosoft import ConfigClass, ConfigType
from datetime import datetime, time
class SpecialConfig(ConfigClass):
STRING_CONF = ConfigType(
'STRING_CONF', str, 'DEFAULT_STRING', lambda value: len(value) > 1)
INT_CONF = ConfigType(
'INT_CONF', int, 100, range(1000))
FLOAT_CONF = ConfigType(
"FLOAT_CONF", float, 0.5, [0, 0.1, 0.5, 3.14])
BOOL_CONF = ConfigType(
"BOOL_CONF", bool, False)
DEFAULT_CONF = ConfigType("DEFAULT_CONF")
DATE = ConfigType(
"DATE", date, date.today(), lambda value: value <= date.today())
DATETIME = ConfigType(
"DATETIME", datetime, datetime.now(),
lambda value: value <= datetime.now())
# ConfigType constructor
ConfigType(env_name: str, type=str, default=None, validation: callable = None)
| Field | Description |
|---|---|
| env_name | Environment variable name, string, required |
| type | python type (str, int, float, bool, datetime, date) |
| default | default value (must be compatible with type) |
| validation | callable to validate data |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file config_guiosoft-0.1.5.tar.gz.
File metadata
- Download URL: config_guiosoft-0.1.5.tar.gz
- Upload date:
- Size: 7.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11f87d6b7aed0a2b39d5e6aa3eb9863fd10d1e237fc616ee2c18ba1d3d273304
|
|
| MD5 |
24403cda60c487dfc27c5408982e3297
|
|
| BLAKE2b-256 |
9f2ba93dc2855b7ad9dddb7237d000b261a417866445d9154f000cb4d35445a3
|
File details
Details for the file config_guiosoft-0.1.5-py3-none-any.whl.
File metadata
- Download URL: config_guiosoft-0.1.5-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3784217a3ce7e39489bef6fda54f67b066d0b4ed7bfd180bc5bcf8f89276966e
|
|
| MD5 |
7254c6f6994219f500ddb214d9a5c795
|
|
| BLAKE2b-256 |
386027b3c298c83ef7fdf903f21252e7a101ea0dc26fd1fcd6bcd617c6f4a617
|