Skip to main content

SJI - Eine einfache Python-Bibliothek für Job-Initialisierung

Project description

SJI

Eine einfache Python-Bibliothek für die Initialisierung von Jobs/Skripten (Logging, Konfiguration, Ordnerstruktur).

Installation

pip install sji

Verwendung

from sji import SimpleJobInit, get_script_version

# __file__ an SimpleJobInit übergeben
sji = SimpleJobInit(__file__)

# Logger verwenden
sji.logger.info("Starte Job...")

# Konfiguration lesen (INI)
cfg = sji.config
value = cfg.get('section', 'key', fallback='default')

# Persistente Datei-Pfade erhalten
csv_path = sji.get_persistent_file_path('csv')

# Temporäre Datei-Pfade erhalten
tmp_path = sji.get_tmp_file_path('work.tmp')

# Versionen ermitteln
sji.logger.info(f"script_version={sji.get_job_script_version(include_git_tag=True)}")
sji.logger.info(f"config_file_hash={sji.get_config_file_hash()}")
sji.logger.info(f"config_file_version={sji.get_config_file_version()}")

# Top-Level-Funktion (unabhängig von der Klasse):
script_version = get_script_version(__file__, include_git_tag=True)

# Konfiguration mit Maskierung loggen
sji.log_config(secret_fields=["password", "db_password", "api_key", "token"]) 

Dabei werden automatisch erzeugt/genutzt:

  • logs/.log (mit optionaler Rotation)
  • tmp/ Verzeichnis
  • .config.ini für Einstellungen

Minimalbeispiel für die INI-Datei

Datei: <skriptname>.config.ini im selben Verzeichnis wie das Skript

[logging]
level = INFO
log_rotation_when = midnight
log_rotation_backup_count = 7

[section]
key = some-value

API

Klasse: SimpleJobInit

  • SimpleJobInit(script_file_path: str)
    • Initialisiert Logging, lädt/prüft INI-Config, erzeugt Ordner (logs, tmp)
  • Eigenschaften
    • logger: konfigurierter logging.Logger
    • config: configparser.ConfigParser
  • Methoden
    • get_tmp_file_path(file_name: str) -> str: Pfad im tmp/-Verzeichnis
    • get_persistent_file_path(file_ending: str) -> str: Pfad <skriptname>.<file_ending>
    • get_job_script_version(include_git_tag: bool = False) -> str: ermittelt Skriptversion (Git/FS)
    • get_config_file_hash() -> str: SHA-256 Hash der INI-Datei
    • get_config_file_version() -> str: cfg_<UTC-Zeit>_<sha256> basierend auf Datei-mtime und Hash
    • log_config(secret_fields) -> None: loggt INI-Inhalt, maskiert definierte Felder (case-insensitive)
    • get_postgres_sqlalchemy_engine(db_config): baut SQLAlchemy-Engine aus INI-Werten

Top-Level-Funktion

  • get_script_version(script_file_path: str, include_git_tag: bool = False) -> str
    • Wie get_job_script_version, aber als freie Funktion für eigenständige Nutzung

Lizenz

MIT-Lizenz - siehe LICENSE für Details.

  • Project build with support of AI (Cursor IDE).

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

sji-0.2.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

sji-0.2.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file sji-0.2.0.tar.gz.

File metadata

  • Download URL: sji-0.2.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for sji-0.2.0.tar.gz
Algorithm Hash digest
SHA256 5e3689d0d9631b686c4c25f257f85b30c620a44d7b037a2c0f16e439e945f9a0
MD5 62d06a9d143fa1dcd51c5f61916e4559
BLAKE2b-256 6f0d5a5cb7786b02612a177ad91b0b413943eff95166eac1b9b0b0f805a2ae57

See more details on using hashes here.

File details

Details for the file sji-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: sji-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for sji-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a2c87b554fc93d105d0322b518768b0a20c2b86c72f36075b9af9e9e43794702
MD5 684a6329585e2fcf64ef02f5ee3412d0
BLAKE2b-256 30da3ee5f39187b298e24d97ce38061f54c69141e587d31bb56476d352657d98

See more details on using hashes here.

Supported by

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