Skip to main content

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 _FILE companion (file-based secrets).
  • short_msg: Truncates the message to chars characters and adds two dots at the end.
  • strtobool: Converts a string to a boolean
  • redact: Replaces in message the param string with replace_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")

Metadata

Release files for egos-helpers 1.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for egos-helpers 1.3.2
File Size Uploaded
egos_helpers-1.3.2.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for egos-helpers 1.3.2
File Interpreter ABI Platform
egos_helpers-1.3.2-py3-none-any.whl Python 3 none any Details

Total release size: 19.7 kB

Release files / egos_helpers-1.3.2.tar.gz

Download URL egos_helpers-1.3.2.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8a0061343a7c3e02a402a81356e7cc131dfcb7e47caeed4c6d6d945fd1a34a3f
BLAKE2b-256 checksum
How to use checksums
325d43b7e1cdc0088aad72570dd19cbecebb823e7d4541b66f32ba098e56ef6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.3 CPython/3.14.5 Linux/7.0.0-28-generic

Release files / egos_helpers-1.3.2-py3-none-any.whl

Download URL egos_helpers-1.3.2-py3-none-any.whl
Size 10.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fcc1eda043fd0302ac11becee1d571c42106440df8fa613879e0b46cf4a4a7ad
BLAKE2b-256 checksum
How to use checksums
8ae7fd23727ea1dfaa9ed349f52213d28a68f45505930cc0055ee663ccfc5b99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.3.3 CPython/3.14.5 Linux/7.0.0-28-generic

Release history Release notifications | RSS feed

1.4.11

2 release files

1.4.9

2 release files

1.4.8

2 release files

1.4.7

2 release files

1.4.6

2 release files

1.4.5

2 release files

1.4.4

2 release files

1.4.3

2 release files

1.4.2

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.4

2 release files

1.3.3

2 release files

This release

1.3.2 This release

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.9

2 release files

1.2.8

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.5

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.9

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page