kaira.constraints.ConstraintRegistry

Inheritance diagram for ConstraintRegistry
- class kaira.constraints.ConstraintRegistry[source]
Bases:
objectA registry for constraints in Kaira.
This class provides a centralized registry for all constraints, making it easier to instantiate them by name with appropriate parameters.
Methods
Create a constraint instance by name.
Get a constraint class by name.
List all available constraints in the registry.
Register a new constraint in the registry.
Decorator to register a constraint class in the registry.
- classmethod register(name: str, constraint_class: Type[BaseConstraint]) None[source]
Register a new constraint in the registry.
- Parameters:
name (str) – The name to register the constraint under.
constraint_class (Type[BaseConstraint]) – The constraint class to register.
- classmethod register_constraint(name: str | None = None) Callable[source]
Decorator to register a constraint class in the registry.
- Parameters:
name (Optional[str], optional) – The name to register the constraint under. If None, the class name will be used (converted to lowercase).
- Returns:
A decorator function that registers the constraint class.
- Return type:
callable
- classmethod get(name: str) Type[BaseConstraint][source]
Get a constraint class by name.
- Parameters:
name (str) – The name of the constraint to get.
- Returns:
The constraint class.
- Return type:
Type[BaseConstraint]
- Raises:
KeyError – If the constraint is not registered.
- classmethod create(name: str, **kwargs) BaseConstraint[source]
Create a constraint instance by name.
- Parameters:
name (str) – The name of the constraint to create.
**kwargs – Additional arguments to pass to the constraint constructor.
- Returns:
The instantiated constraint.
- Return type:
- classmethod list_constraints() list[source]
List all available constraints in the registry.
- Returns:
A list of constraint names.
- Return type:
- __init__()