Skip to main content

dynamic config management tool

Project description

Dino 🦖

Dynamic config management.

PyPI version License

Dino is a high-performance, thread-safe configuration management library for Python. It parses YAML files, watches them for background changes using daemon threads, natively supports deep object queries via duck-typing, and alerts attached observers dynamically.

Installation

pip install dinocore

Features

  • Daemon Watchers: Native background threads using OS file timestamps (os.path.getmtime) to reload configuration precisely when the YAML is edited.
  • Thread-Safety: Atomic locking (threading.Lock()) protects the config state to entirely prevent read/write race conditions across environments.
  • Context Manager Support: Graceful teardown out-of-the-box (with dino: ...).
  • Duck-Typing & Defaults: Retrieve nested dictionaries, lists, or Python objects gracefully using dot-notation ("foo.bar.0"). Fallback to standard defaults avoiding KeyErrors or IndexErrors.
  • Dynamic Observer Payloads: Listeners actively receive the specific config_name that updated, skipping guesswork.

Example Usage

# config.yml

client:
  my_client:
    url: example.com
    features:
      - logging
      - retries
# main.py
import logging
import signal
import time
from dino.dino import dino, DinoObserver

logging.basicConfig(level=logging.INFO)

def signal_handler(sig, frame):
    logging.info("Shutdown signal received")
    dino.stop()  # Stop Dino watchers gracefully.


# Implement DinoObserver to update configs dynamically
class MyClient(DinoObserver):

    def __init__(self, url):
        self.url = url
        logging.info(f"MyClient initialized with url: {self.url}")

    def update_config(self, config_name: str):
        # Payload 'config_name' gives you explicit detail on which file triggered this
        if config_name == "appconfig":
            # Native fallback using 'default' parameter avoids breaking your app
            self.url = dino.get_config_value("appconfig", "client.my_client.url", default="localhost")
            logging.info(f"MyClient config updated. New url: {self.url}")


def main():
    # Register your config YAML file(s).
    dino.register_config(
        "appconfig",  # Config name
        "./config.yml",  # Yaml file path
        10,  # File read interval in seconds
    )

    # Use context managers optionally to auto-stop watchers on exit
    with dino:
        initial_url = dino.get_config_value("appconfig", "client.my_client.url", default="localhost")
        my_client = MyClient(initial_url)
        
        # Test duck-typing array retrieval (indexing lists via dot-notation)
        feature_0 = dino.get_config_value("appconfig", "client.my_client.features.0", default="n/a")
        logging.info(f"First feature enabled: {feature_0}")

        # Attach single or multiple listeners using *args
        dino.attach(my_client)

        # Keep main thread alive to watch daemon threads react
        while not dino._stop_event.is_set():
            time.sleep(1)

if __name__ == "__main__":
    signal.signal(signal.SIGINT, signal_handler)
    signal.signal(signal.SIGTERM, signal_handler)
    main()

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

dinocore-1.1.0.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

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

dinocore-1.1.0-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file dinocore-1.1.0.tar.gz.

File metadata

  • Download URL: dinocore-1.1.0.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for dinocore-1.1.0.tar.gz
Algorithm Hash digest
SHA256 f3dafe7ddf66eb4f7a53dd7e2992693a51ce2a8bd571f70c695415be0510709e
MD5 b70baafb9a5885fb5db6227787fd6d73
BLAKE2b-256 28985e8354a45d861d80b559ea6745901961c2a6484351bae424c4161e3324f7

See more details on using hashes here.

File details

Details for the file dinocore-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: dinocore-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 5.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.4

File hashes

Hashes for dinocore-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1793a9735cea49292c462472aeff551c6a719aad97b75293c193cc68120d1604
MD5 1da46d9b26db738f403e98cc29de65e4
BLAKE2b-256 6c867912e03fa645b05de8a0ee700bf8f088d768f56d415ffab4026a62ce7240

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