{"id":5746,"library":"autoregistry","title":"AutoRegistry","description":"AutoRegistry is a Python library that implements an automatic registry design pattern, enabling the mapping of string names to functionality (classes or functions) without manual lookup dictionaries. It supports inheritance-based registration, decorator-based registration, and module-level traversal for automatic setup. The library is actively maintained with consistent minor and patch releases, currently at version 1.2.1.","status":"active","version":"1.2.1","language":"en","source_language":"en","source_url":"https://github.com/BrianPugh/autoregistry","tags":["registry","design-pattern","plugins","configuration","metaclasses","pydantic","factory"],"install":[{"cmd":"pip install autoregistry","lang":"bash","label":"Install core library"},{"cmd":"pip install autoregistry[pydantic]","lang":"bash","label":"Install with Pydantic support"}],"dependencies":[{"reason":"Required only for the `autoregistry.pydantic.BaseModel` integration to combine Pydantic's data validation with AutoRegistry's registration features.","package":"pydantic","optional":true}],"imports":[{"symbol":"Registry","correct":"from autoregistry import Registry"},{"note":"The Pydantic-enhanced BaseModel is located in the `autoregistry.pydantic` submodule, not directly under `autoregistry`.","wrong":"from autoregistry import BaseModel","symbol":"BaseModel","correct":"from autoregistry.pydantic import BaseModel"}],"quickstart":{"code":"from abc import abstractmethod\nfrom dataclasses import dataclass\nfrom autoregistry import Registry\n\n@dataclass\nclass Pokemon(Registry):\n    level: int\n    hp: int\n\n    @abstractmethod\n    def attack(self, target):\n        \"\"\"Attack another Pokemon.\"\"\"\n\nclass Charmander(Pokemon):\n    def attack(self, target):\n        return 1\n\nclass Pikachu(Pokemon):\n    def attack(self, target):\n        return 2\n\n# Access registered subclasses\ncharmander = Pokemon[\"charmander\"](level=5, hp=40) # Name is auto-derived from class name\npikachu = Pokemon[\"pikachu\"](level=7, hp=50)\n\nassert charmander.attack(pikachu) == 1\nassert isinstance(charmander, Charmander)\nassert isinstance(pikachu, Pikachu)\n\nprint(f\"Created {charmander.__class__.__name__} (Level: {charmander.level}, HP: {charmander.hp})\")\nprint(f\"Created {pikachu.__class__.__name__} (Level: {pikachu.level}, HP: {pikachu.hp})\")","lang":"python","description":"This example demonstrates how to use `Registry` with class inheritance. Subclasses of `Pokemon` are automatically registered by their lowercase name, allowing them to be retrieved via dictionary-like access on the base `Pokemon` class."},"warnings":[{"fix":"Upgrade to `autoregistry` version 1.2.1 or later, which includes fixes to reduce the strictness of `KeyCollisionError` for hot-reloading scenarios.","message":"Encountering `KeyCollisionError` during module hot-reloading (e.g., in development environments like IPython with `%autoreload`). This could occur if modules containing registered classes were reloaded, leading to re-registration.","severity":"gotcha","affected_versions":"<1.2.1"},{"fix":"Update to `autoregistry` 1.2.1 or newer. This version specifically addresses `KeyCollisionErrors` when registering multiple same-name classes to `autoregistry.pydantic.BaseModel`.","message":"When using `autoregistry.pydantic.BaseModel`, registering multiple classes with the same derived name could trigger `KeyCollisionError`.","severity":"gotcha","affected_versions":"<1.2.1"},{"fix":"Upgrade to `autoregistry` version 1.0.2 or later, which contains fixes for `attrs` decorator compatibility issues with `Registry` subclasses and `slots`. Users should ensure their `attrs` integration is on a supported `autoregistry` version.","message":"Potential issues when combining `autoregistry.Registry` subclasses with `attrs` decorators, especially when `slots` are enabled, leading to unexpected behavior or errors.","severity":"gotcha","affected_versions":"<1.0.2"},{"fix":"Upgrade to `autoregistry` version 1.1.2 or later, which includes a fix for module registry name preprocessing, ensuring consistent and correct naming.","message":"Unexpected behavior or incorrect naming due to issues with module registry name preprocessing, potentially leading to incorrect keys in the registry when using module-based registration.","severity":"gotcha","affected_versions":"<1.1.2"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}