Access system variables in your code as native Python data types.
Project description
sys-vars
Access system variables in your code as native Python data types.
Usage
Requires Python 3.8+
Load system variables for used in applications as secrets, variables, and other related contexts as
native Python data types. Searches for a file in SYS_VARS_PATH
, falling back to os.enviorn
.
If the package is installed with the dotenv
extra (pip install sys-vars[dotenv]
), there is a
final check in the contents of a .env
file located in SYS_VARS_PATH
, if one exists.
SYS_VARS_PATH
must be a defined OS environment variable that is set
before app start. If it is not found, a KeyError
exception will be raised.
import sys_vars
# Returns <class 'str'>
# Default values can be specified if the key is missing
sys_vars.get("HOST_ADDRESS", default="localhost")
# Returns <class 'bool'>
# Default values are supported for casting methods too
# Also treats "t", "true", "y", "yes" as True value
sys_vars.get_bool("DEBUG_MODE", default=False)
# Returns <class 'datetime.datetime'>
sys_vars.get_datetime("LAST_SYNC_RUN")
# Returns <class 'float'>
sys_vars.get_float("pi")
# Returns <class 'int'>
sys_vars.get_int("THE_MEANING_OF_LIFE")
# Returns <class 'dict'> or <class 'list'>
# Automatically decodes JSON strings into dictionaries/lists
sys_vars.get_json("CONFIGURED_TERMS")
# Returns <class 'pathlib.Path'>
sys_vars.get_path("CONFIG_PATH")
# Raises `sys_vars.SysVarNotFoundError`
sys_vars.get("DOES_NOT_EXIST")
Building
- Install Poetry 1.6.0+
- Run
poetry install
- Run
poetry build
- Tests can be run via the provided VS Code test runner config.
The resulting .whl
file will be located at
./dist/sys_vars-<x.y.z>-py3-none-any.whl
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
File details
Details for the file sys_vars-5.1.0.tar.gz
.
File metadata
- Download URL: sys_vars-5.1.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.2 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ef7276aca3a94d1442161662066bf5464921ba1c481262923e1f0762e88bf08 |
|
MD5 | 20f04fa3803a1e2eade38c74e5e5d60f |
|
BLAKE2b-256 | deda3e737f324e97fbb1fb459410ffbd9dedcd05e7e637ac68cc2e445f1a2fa0 |
File details
Details for the file sys_vars-5.1.0-py3-none-any.whl
.
File metadata
- Download URL: sys_vars-5.1.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.10.2 Linux/6.5.0-1021-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0063af5fb03e03f8c19d42cd76d7eaf456a956053e2959ba77f237404fbb0b0 |
|
MD5 | 80673386cb639d284f6c025a3fb36037 |
|
BLAKE2b-256 | 121ecc4e2275b39038ca4c4ac218b3c14b75affba268df4ca0d50284b9e11de6 |