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.2.0.tar.gz (7.0 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.2.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dinocore-1.2.0.tar.gz
Algorithm Hash digest
SHA256 c052f0c2fa325a66cb168a11ed863d5fb76a7d25f78971f14cee9e9cce0f4b6c
MD5 a3c51e52d426a19ad8f3fe7c2f41998e
BLAKE2b-256 c324b4ac83e1586baad425b5bf963d79c4de68e229309f3af67af4a40f2873c6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for dinocore-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a43be53c2163e246df16023d2443e13ade144890260b1265764e5ad6bdc235a5
MD5 02bc45702ae6098a05fe9545770e285e
BLAKE2b-256 5fcbd6d5f052a8f030d2ca74887e7bf6d5f6594c8a9d6983c6a4376044ea3e31

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