{"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.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install phx-class-registry"],"cli":null},"imports":["from class_registry import ClassRegistry","from class_registry import RegistryKeyError","from class_registry.base import AutoRegister"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}