Class registry¶
A registry of Schema
classes. This allows for string
lookup of schemas, which may be used with
class:fields.Nested
.
Warning
This module is treated as private API. Users should not need to use this module directly.
- marshmallow.class_registry.get_class(classname: str, *, all: Literal[False] = False) SchemaType [source]¶
- marshmallow.class_registry.get_class(classname: str, *, all: Literal[True] = False) list[SchemaType]
Retrieve a class from the registry.
- Raises:
marshmallow.exceptions.RegistryError
if the class cannot be found or if there are multiple entries for the given class name.
- marshmallow.class_registry.register(classname, cls)[source]¶
Add a class to the registry of serializer classes. When a class is registered, an entry for both its classname and its full, module-qualified path are added to the registry.
Example:
class MyClass: pass register("MyClass", MyClass) # Registry: # { # 'MyClass': [path.to.MyClass], # 'path.to.MyClass': [path.to.MyClass], # }
- Parameters:
classname (str)
cls (SchemaType)
- Return type:
None