{"id":9179,"library":"phx-class-registry","title":"ClassRegistry","description":"ClassRegistry (phx-class-registry) is a Python library that implements a powerful Factory+Registry pattern for Python classes, enabling the definition of global factories that generate new class instances based on configurable keys. It supports service registries and integration with setuptools's entry_points system for extensibility. The current version is 5.2.1 and it maintains an active release cadence, supporting the three most recent Python versions.","status":"active","version":"5.2.1","language":"en","source_language":"en","source_url":"https://github.com/todofixthis/class-registry","tags":["registry","factory","class","pattern","dependency injection","decorators"],"install":[{"cmd":"pip install phx-class-registry","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"ClassRegistry","correct":"from class_registry import ClassRegistry"},{"symbol":"RegistryKeyError","correct":"from class_registry import RegistryKeyError"},{"note":"The direct import from `class_registry.auto_register` is deprecated in v5.x; `AutoRegister` is now intended for use as a base class mixin imported from `class_registry.base`.","wrong":"from class_registry.auto_register import AutoRegister","symbol":"AutoRegister (as a base class mixin)","correct":"from class_registry.base import AutoRegister"}],"quickstart":{"code":"from class_registry import ClassRegistry\n\nclass Pokemon:\n    pass\n\npokedex = ClassRegistry[Pokemon]()\n\n@pokedex.register('fire')\nclass Charizard(Pokemon):\n    def attack(self): return 'Flamethrower'\n\n@pokedex.register('water')\nclass Squirtle(Pokemon):\n    def attack(self): return 'Water Gun'\n\n# Create instances\nfire_pokemon = pokedex['fire']\nwater_pokemon = pokedex['water']\n\nassert isinstance(fire_pokemon, Charizard)\nassert fire_pokemon.attack() == 'Flamethrower'\nassert isinstance(water_pokemon, Squirtle)\nassert water_pokemon.attack() == 'Water Gun'\n\nprint(f\"Created {fire_pokemon.__class__.__name__}: {fire_pokemon.attack()}\")\nprint(f\"Created {water_pokemon.__class__.__name__}: {water_pokemon.attack()}\")","lang":"python","description":"This example demonstrates creating a typed ClassRegistry, registering classes using a decorator with keys, and then instantiating objects from the registry using subscript notation."},"warnings":[{"fix":"Consult the official 'Upgrading to ClassRegistry v5' guide on ReadTheDocs to adapt your imports and code structure.","message":"ClassRegistry v5.0.0 introduced backwards-incompatible changes by cleaning up the top-level `class_registry` namespace. Code upgrading from v4.x or earlier must review the 'Upgrading to ClassRegistry v5' documentation for migration instructions.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Upgrade your Python environment to version 3.12 or newer. For projects requiring older Python versions, pin `phx-class-registry` to `<5.1.0` (for Python 3.10) or `<5.2.0` (for Python 3.11).","message":"ClassRegistry v5.1.0 and v5.2.0 dropped support for Python 3.10 and 3.11 respectively. The library now strictly requires Python >=3.12.","severity":"breaking","affected_versions":">=5.1.0"},{"fix":"Change `from class_registry.auto_register import AutoRegister` to `from class_registry.base import AutoRegister` and use `AutoRegister(my_registry)` as a base class for auto-registration.","message":"The `AutoRegister` function from `class_registry.auto_register` is deprecated in v5.x. It should now be imported as a base class mixin from `class_registry.base`.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Always use `pip install phx-class-registry`. If you have `class-registry` installed, uninstall it with `pip uninstall class-registry`.","message":"Users often mistakenly install `class-registry` instead of `phx-class-registry`. The `class-registry` package is an older, unmaintained fork and will not receive updates.","severity":"gotcha","affected_versions":"All"},{"fix":"If you subclassed `MutableRegistry`, update your base class to `BaseMutableRegistry`.","message":"In v4.0.3, `class_registry.MutableRegistry` was renamed to `class_registry.BaseMutableRegistry`. This primarily impacts users who subclass `MutableRegistry`.","severity":"breaking","affected_versions":">=4.0.3"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Uninstall `class-registry` with `pip uninstall class-registry` and then install the correct package: `pip install phx-class-registry`.","cause":"You likely installed the abandoned `class-registry` package instead of `phx-class-registry`. The `phx-class-registry` package installs the `class_registry` module.","error":"ModuleNotFoundError: No module named 'class_registry'"},{"fix":"Update your import and usage to `from class_registry import BaseMutableRegistry` and use `BaseMutableRegistry` instead of `MutableRegistry`.","cause":"In ClassRegistry v4.0.3, `MutableRegistry` was renamed to `BaseMutableRegistry` for clarity and to better reflect its role as a base class.","error":"AttributeError: module 'class_registry' has no attribute 'MutableRegistry'"},{"fix":"Ensure that the class you intend to retrieve has been correctly decorated with `@your_registry.register('my_key')` using the exact key string, and that the key used for retrieval matches it.","cause":"This error occurs when you try to access a key in a `ClassRegistry` that has not been registered with a corresponding class, or the key name is misspelled.","error":"RegistryKeyError: No class registered for key 'my_key'"}]}