Registry / serialization / class-resolver

class-resolver

JSON →
library0.7.1pypypi✓ verified 85d ago

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.

pip install class-resolver
INSTALL
IMPORT
SIG · CLASS-RESOLVER
C
class-resolver
serializationpythonv0.7.1
Install
1.6s avg
Import
124ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.7.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.132s · 18.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.116s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ClassResolver
from class_resolver import ClassResolver
Hint
from class_resolver import Hint
Resolver
from class_resolver import Resolver
Contributions
from class_resolver import Contributions
Optional
from class_resolver import Optional

Create a resolver from a base class or a list of classes, then look up and instantiate by registered name.

from class_resolver import ClassResolver class MyModel: name = 'my_model' class AnotherModel: name = 'another_model' resolver = ClassResolver.from_subclasses(MyModel) # Or manually: # resolver = ClassResolver([MyModel, AnotherModel]) # Look up by name or class model_class = resolver.lookup('my_model') # Instantiate with parameters instance = resolver.make('my_model', param1=10) print(instance)
Debug
Known issues
gotchaClass names are lowercased by default for lookup (e.g., 'MyModel' -> 'my_model'). To preserve original case, pass `suffix=''` or customize `suffix` parameter.
fix
Use `ClassResolver(classes, suffix='')` or override with custom normalization.
affects: all
gotcha`ClassResolver.from_subclasses()` only finds subclasses that are imported. If you define classes in separate modules, ensure they are imported before calling `from_subclasses`.
fix
Import all subclass modules explicitly before calling `from_subclasses()`.
affects: all
breakingIn 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.
fix
Ensure that kwargs passed to `make()` are valid constructor arguments for the resolved class.
affects: >=0.7.0
deprecatedThe `Optional` alias for `Contributions` is deprecated since 0.7.0. Use `Contributions` directly.
fix
Replace `Optional` with `Contributions` in type hints.
affects: >=0.7.0
Errors
Common errors & fixes
AttributeError: module 'class_resolver' has no attribute 'ClassResolver'
Misspelled or incorrect import name. The module is `class_resolver` (with underscore), not `classresolver`.
fix
`from class_resolver import ClassResolver`
KeyError: 'xyz'
Attempted to lookup a class that is not registered in the resolver.
fix
Check registered names with `resolver.names` or ensure the class is properly added.
TypeError: __init__() got an unexpected keyword argument 'unexpected'
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.
fix
Remove unexpected kwargs or filter them before calling `make()`.
Upgrade
Version history
0.7.1latest on PyPI · released Aug 28, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
8
OpenAI (training)
1
Resources
class-resolver — pip install class-resolver · libregistry