A python library for helper functions
Project description
egos-helpers
A python library for helper functions. Used in the egos-tech projects.
Functions
gather_environ: Return a dict of environment variables correlating to the keys dict.get_environ_value: Resolve a single value from an environment variable or its_FILEcompanion (file-based secrets).short_msg: Truncates the message tocharscharacters and adds two dots at the end.strtobool: Converts a string to a booleanredact: Replaces inmessagetheparamstring withreplace_value
See egos_helpers/core.py for the full description of each function.
Usage example
Install egos-helpers:
python3 -m venv .venv
source .venv/bin/activate
# if you don't have a requirements.txt file
pip install -U egos-helpers
# if you do have a requirements.txt file
pip install -U -r requirements.txt
In your python project:
from egos_helpers import gather_environ
class MyClass:
keys = {
'key_one': {
'default': ['one', 2],
'type': "list",
},
'key_two':{
'hidden': True,
'default': False,
'type': "boolean",
},
'key_three': {
'default': [],
'type': "filter",
},
'key_four': {
'default': None,
'redact': True,
'type': 'string',
},
'key_five': {
'default': 12,
'type': 'int',
},
'key_six': {
'default': 'INFO',
'type': 'enum',
'values': [
'DEBUG',
'INFO',
'WARNING',
'ERROR'
],
},
'key_seven': {
'default': '12',
'deprecated': True,
'replaced_by': 'key_five',
'type': 'int',
}
}
def __init__(self):
envkeys = gather_environ(keys=MyClass.keys)
print(envkeys)
File-based secrets
Use get_environ_value to resolve a value from either an environment variable or a
<NAME>_FILE file path (the container secrets convention). It reads <NAME>_FILE
first (returning the file contents stripped of surrounding whitespace), falls back
to <NAME>, and returns None when neither is set. Setting both raises an error.
So does an unreadable <NAME>_FILE path.
from egos_helpers import get_environ_value
# MYAPP_TOKEN=secret123 -> "secret123"
# MYAPP_TOKEN_FILE=/run/secrets/t -> contents of the file, stripped
token = get_environ_value("MYAPP_TOKEN")
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
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 egos_helpers-1.3.0.tar.gz.
File metadata
- Download URL: egos_helpers-1.3.0.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.14.5 Linux/7.0.0-28-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6572bb0bcc34371fdbf7ef7705f2725e46291276607d49f255b63b7a1a4f6d4b
|
|
| MD5 |
b0a11015143f827785949bfe6b5782bf
|
|
| BLAKE2b-256 |
74c9fdd23dce85f6101d62edfd39bc910554b568d2162758581a018745cce74f
|
File details
Details for the file egos_helpers-1.3.0-py3-none-any.whl.
File metadata
- Download URL: egos_helpers-1.3.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.3.3 CPython/3.14.5 Linux/7.0.0-28-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdb0cadef5731b4700ceacc5880301d5d6af1cb166552b41728abc99074692b7
|
|
| MD5 |
c83a94dd07dbf3a8d6d618c727766508
|
|
| BLAKE2b-256 |
35066ee507d0369f39bd73d2e177c1eedfcbe7fa987e6f3cce5a7a2328c5d9ae
|