dynamic config management tool
Project description
Dino 🦖
Dynamic config management.
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 avoidingKeyErrors orIndexErrors. - Dynamic Observer Payloads: Listeners actively receive the specific
config_namethat 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.3.0.tar.gz
(6.9 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dinocore-1.3.0.tar.gz.
File metadata
- Download URL: dinocore-1.3.0.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f1f034e6cb4c1b9b3d0fd8116fac7a226804d61b3aad20c4ec5b787fbf750b04
|
|
| MD5 |
0a6296eddb90b0e8850e3c70cb0db82b
|
|
| BLAKE2b-256 |
5334cd7cd91aabd1e04acbfce24caebf22d2376d1100aa50c3be872c787f1e65
|
File details
Details for the file dinocore-1.3.0-py3-none-any.whl.
File metadata
- Download URL: dinocore-1.3.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.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6819c42d4f2f5823124318d9d6953cd86506fa5ac189a197db6f462457674b0c
|
|
| MD5 |
2edfd3b96bed73a00926994e96fad9fd
|
|
| BLAKE2b-256 |
40cc26afb0478dfbccd9bb8931880a66ae25060ab80f21e4fa2fc23198588ef8
|