class-resolver
Lookup and instantiate classes with style.
What it is and what it does
class-resolver provides a ClassResolver object that maintains a registry of classes and resolves them by string name, class reference, or pre-instantiated object. It accepts flexible input formats (lowercase strings, stylized names, class objects, or instances) and instantiates them with optional constructor arguments. The package is designed to eliminate boilerplate dictionary-based class lookup patterns and hard-coded conditional logic, making it especially useful for building extensible machine learning models and plugin systems where users need to specify components via configuration strings.
The core use case is replacing manual if-elif chains or static lookup dictionaries with a declarative registry that handles case-insensitive string matching, class validation against a base type, and optional default instantiation. It includes contrib modules for common frameworks, reducing repetitive setup code across projects that need flexible component selection.
Use it for:
- Build extensible neural network architectures where activation functions are selected by string configuration.
- Create plugin systems where users register custom classes and reference them by name in config files.
- Integrate with hyperparameter optimization libraries that require serializable string representations of class choices.
- Reduce boilerplate in factory patterns by replacing manual class-to-string mappings with automatic registry-based lookup.
- Support both programmatic (class/instance) and declarative (string) class selection in the same API.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Dynamically lookup and instantiate classes by string name, class object, or instance, with optional constructor arguments.
Yes. The package is actively maintained, has no known vulnerabilities, minimal dependencies, and solves a genuine pain point in extensible system design. It's particularly valuable if you're building configurable ML models, plugin architectures, or any system where users need to specify classes via strings. The low install friction and permissive license make adoption straightforward.
Install
class-resolver on PyPI
pip
pip install class-resolveruv
uv add class-resolverpoetry
poetry add class-resolverInstalling class-resolver
Before you install
Low friction: pure Python wheel with only typing-extensions as a runtime dependency. Active maintenance with latest release on 2025-08-28.
License in practice
MIT license (permissive) means you can use, modify, and distribute this package freely in commercial or private projects with minimal restrictions.
Quickstart
from class_resolver import ClassResolver
class Base: pass
class A(Base): pass
class B(Base): pass
resolver = ClassResolver([A, B], base=Base)
assert A == resolver.lookup('A')
assert A(name='hi') == resolver.make('A', {'name': 'hi'})
Requires Python 3.10 or later
Verify before relying
- Whether the package handles circular imports or late-binding class registration patterns
- Performance characteristics when resolving from large class registries
- Whether contrib.torch module requires PyTorch to be installed or is optional
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — typing-extensions |
| Maintenance | actively maintained — 351 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 89,789/month — #13,635 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: class_resolver-0.7.1-py3-none-any.whl
Keywords: snekpack, cookiecutter, development tool, configurability
Tags
More Application Frameworks packages
FastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
textualTextual is a Python framework for building…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
mcpBuild and connect to Model Context Protocol…
permissive · top 1,000 on PyPI
WerkzeugWerkzeug is a WSGI utility library providing…
permissive · top 1,000 on PyPI
daciteConverts dictionaries into dataclass instances…
permissive · top 1,000 on PyPI
dataclass-factoryConverts dataclasses to and from dictionaries…
permissive · top 15,000 on PyPI
objectoryProvides dynamic object factory implementations…
permissive · top 15,000 on PyPI
nslookupProvides high-level DNS lookups (A, AAAA, and…
copyleft · top 15,000 on PyPI
bioversionsRetrieves and caches the current version…
permissive · top 15,000 on PyPI
curiesConverts between URIs and compact URIs (CURIEs)…
permissive · top 15,000 on PyPI
phx-class-registryImplements the Registry and Factory patterns to…
permissive · top 15,000 on PyPI
argparse-dataclassBuilds command-line interfaces declaratively by…
permissive · top 5,000 on PyPI
resolvelibResolveLib provides a generic dependency…
permissive · top 1,000 on PyPI
polyfactoryPolyfactory generates mock data objects from…
permissive · top 5,000 on PyPI