from collections import defaultdict from threading import Lock _registry = defaultdict(list) _lock = Lock() def register_template(slot: str, template_name: str, *, order: int = 100): item = (order, template_name) with _lock: if item not in _registry[slot]: _registry[slot].append(item) _registry[slot].sort(key=lambda x: x[0]) def get_templates(slot: str): return [template_name for _, template_name in _registry.get(slot, [])]