{"id":23428,"library":"class-resolver","title":"class-resolver","description":"A lightweight library for looking up and instantiating classes by name or key, with support for registration, aliases, and presets. Current version 0.7.1, requires Python >=3.10, weekly releases.","status":"active","version":"0.7.1","language":"python","source_language":"en","source_url":"https://github.com/cthoyt/class-resolver.git","tags":["class resolution","dependency injection","registration","python"],"install":[{"cmd":"pip install class-resolver","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"","wrong":"","symbol":"ClassResolver","correct":"from class_resolver import ClassResolver"},{"note":"","wrong":"","symbol":"Hint","correct":"from class_resolver import Hint"},{"note":"","wrong":"","symbol":"Resolver","correct":"from class_resolver import Resolver"},{"note":"","wrong":"","symbol":"Contributions","correct":"from class_resolver import Contributions"},{"note":"","wrong":"","symbol":"Optional","correct":"from class_resolver import Optional"}],"quickstart":{"code":"from class_resolver import ClassResolver\n\nclass MyModel:\n    name = 'my_model'\n\nclass AnotherModel:\n    name = 'another_model'\n\nresolver = ClassResolver.from_subclasses(MyModel)\n# Or manually:\n# resolver = ClassResolver([MyModel, AnotherModel])\n\n# Look up by name or class\nmodel_class = resolver.lookup('my_model')\n# Instantiate with parameters\ninstance = resolver.make('my_model', param1=10)\nprint(instance)","lang":"python","description":"Create a resolver from a base class or a list of classes, then look up and instantiate by registered name."},"warnings":[{"fix":"Use `ClassResolver(classes, suffix='')` or override with custom normalization.","message":"Class names are lowercased by default for lookup (e.g., 'MyModel' -> 'my_model'). To preserve original case, pass `suffix=''` or customize `suffix` parameter.","severity":"gotcha","affected_versions":"all"},{"fix":"Import all subclass modules explicitly before calling `from_subclasses()`.","message":"`ClassResolver.from_subclasses()` only finds subclasses that are imported. If you define classes in separate modules, ensure they are imported before calling `from_subclasses`.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure that kwargs passed to `make()` are valid constructor arguments for the resolved class.","message":"In version 0.7.0, `ClassResolver.make()` now passes extra kwargs to the constructor. Previously, extra kwargs were ignored. This may break code that relied on silent ignoring.","severity":"breaking","affected_versions":">=0.7.0"},{"fix":"Replace `Optional` with `Contributions` in type hints.","message":"The `Optional` alias for `Contributions` is deprecated since 0.7.0. Use `Contributions` directly.","severity":"deprecated","affected_versions":">=0.7.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"`from class_resolver import ClassResolver`","cause":"Misspelled or incorrect import name. The module is `class_resolver` (with underscore), not `classresolver`.","error":"AttributeError: module 'class_resolver' has no attribute 'ClassResolver'"},{"fix":"Check registered names with `resolver.names` or ensure the class is properly added.","cause":"Attempted to lookup a class that is not registered in the resolver.","error":"KeyError: 'xyz'"},{"fix":"Remove unexpected kwargs or filter them before calling `make()`.","cause":"Passed an unexpected keyword argument to `resolver.make()`. In versions >=0.7.0, extra kwargs are passed to the constructor, which may cause an error if the class does not accept them.","error":"TypeError: __init__() got an unexpected keyword argument 'unexpected'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}