Skip to main content

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

Script

Create ./config/config.yml in the same directory as the script.

In the script initialise a CONFIG object:

import pathlib

import panaetius

CONFIG = panaetius.Config(
    "teenagers_scraper", str(pathlib.Path(__file__).parents[0] / ".config"), skip_header_init=True
)

Set variables in the same way as the module above.

quickstart logging

import panaetius


def get_logger():
    logging_dir = pathlib.Path(__file__).parents[0] / "logs"
    logging_dir.mkdir(parents=True, exist_ok=True)

    CONFIG = panaetius.Config("training_data_into_gcp", skip_header_init=True)
    panaetius.set_config(CONFIG, "logging.level", "DEBUG")
    panaetius.set_config(CONFIG, "logging.path", logging_dir)
    return panaetius.set_logger(CONFIG, panaetius.SimpleLogger(logging_level=CONFIG.logging_level))

Utility Functions

Squasher

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

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.5.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

panaetius-2.3.5-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: panaetius-2.3.5.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.7.12 Darwin/21.2.0

File hashes

Hashes for panaetius-2.3.5.tar.gz
Algorithm Hash digest
SHA256 dd2712f124449b6bc1c3e0fed6baf6b42a9802a5c5fe25411f11a7d7751899ce
MD5 1ca102d058d91a060800a7448c15416f
BLAKE2b-256 9be10f27e15cfe61b842a3b84eb5e9fc747c583425ff84000d749e11e73a771e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: panaetius-2.3.5-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.12 CPython/3.7.12 Darwin/21.2.0

File hashes

Hashes for panaetius-2.3.5-py3-none-any.whl
Algorithm Hash digest
SHA256 96794e7fd63b4f156ee2ca4c6380b4a3c13d2d1c7e550f92de476b5cd91ea9c5
MD5 257082d6e6b66a08846c043f06f9bb3c
BLAKE2b-256 adbc3d12bd9a03bd7591fd7e36bdd93b02dc45d04b6d460b9af82b89e9bc5eb5

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

2.3.5 This release

2 files

2.3.4

2 files

2.3.3

2 files

2.3.2

2 files

2.3.1

2 files

2.2.2

2 files

2.2.1

2 files

2.2.0

2 files

2.1.0

2 files

2.0.0

2 files

1.1

2 files

1.0.2

2 files

1.0.1

2 files

1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page