Skip to main content

Python module to gracefully handle a .config file/environment variables for scripts, with built in masking for sensitive options. Provides a Splunk friendly formatted logger instance.

Project description

Panaetius

This package provides:

  • Functionality to read user variables from a config.yml or environment variables.
  • A convenient default logging formatter printing json that can save to disk and rotate.
  • Utility functions.

Config

options

skip_header_init

If skip_header_init=True then the config_path will not use the header_variable as the sub-directory in the config_path.

E.g

CONFIG = panaetius.Config("tembo", "~/tembo/.config", skip_header_init=True)

Will look in ~/tembo/config/config.yml.

If skip_header_init=False then would look in ~/tembo/config/tembo/config.yml.

Module

Convenient to place in a package/sub-package __init__.py.

See Tembo for an example: https://github.com/tembo-pages/tembo-core/blob/main/tembo/cli/__init__.py

Example snippet to use in a module:

"""Subpackage that contains the CLI application."""

import os
from typing import Any

import panaetius
from panaetius.exceptions import LoggingDirectoryDoesNotExistException


if (config_path := os.environ.get("TEMBO_CONFIG")) is not None:
    CONFIG: Any = panaetius.Config("tembo", config_path, skip_header_init=True)
else:
    CONFIG = panaetius.Config(
        "tembo", "~/tembo/.config", skip_header_init=True
    )


panaetius.set_config(CONFIG, "base_path", "~/tembo")
panaetius.set_config(CONFIG, "template_path", "~/tembo/.templates")
panaetius.set_config(CONFIG, "scopes", {})
panaetius.set_config(CONFIG, "logging.level", "DEBUG")
panaetius.set_config(CONFIG, "logging.path")

try:
    logger = panaetius.set_logger(
        CONFIG, panaetius.SimpleLogger(logging_level=CONFIG.logging_level)
    )
except LoggingDirectoryDoesNotExistException:
    _LOGGING_PATH = CONFIG.logging_path
    CONFIG.logging_path = ""
    logger = panaetius.set_logger(
        CONFIG, panaetius.SimpleLogger(logging_level=CONFIG.logging_level)
    )
    logger.warning("Logging directory %s does not exist", _LOGGING_PATH)

This means in ./tembo/cli/cli.py you can

import tembo.cli

# access the CONFIG instance + variables from the config.yml
tembo.cli.CONFIG

Utility Functions

Squasher

Squashes a json object or Python dictionary into a single level dictionary.

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

panaetius-2.3.3.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

panaetius-2.3.3-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file panaetius-2.3.3.tar.gz.

File metadata

  • Download URL: panaetius-2.3.3.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.9 Linux/4.19.128-microsoft-standard

File hashes

Hashes for panaetius-2.3.3.tar.gz
Algorithm Hash digest
SHA256 d984596a54f74763bc76664dcf04e41d080d20d8e458ccf42a9e7da1846cfcf2
MD5 55588aef68fed37280131c0b4d418cc0
BLAKE2b-256 55244d07b952f3d233431c192a792b23001b7111953b01f1354f4e47a78a19d6

See more details on using hashes here.

File details

Details for the file panaetius-2.3.3-py3-none-any.whl.

File metadata

  • Download URL: panaetius-2.3.3-py3-none-any.whl
  • Upload date:
  • Size: 9.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.4 CPython/3.7.9 Linux/4.19.128-microsoft-standard

File hashes

Hashes for panaetius-2.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 44d8554dbeea25f16c7c36bc97e35369eb87c09b339a6347c6053ded00890569
MD5 3ed95e70feff5e72de948fc9f9e149e7
BLAKE2b-256 81da7a8ee1a50352a3bb44d8ed431f47732bb4f5dedcf2bc3e5fd369cd9c1c74

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page