This document provides a complete API reference for the MSB Framework.
Abstract base class for entities with type validation and serialization.
BaseEntity(name: str, isactive: bool = True, use_cache: bool = False, **kwargs)Parameters:
name(str): Entity identifier (required, cannot be None)isactive(bool): Activation status (default: True)use_cache(bool): Enable caching for serialization (default: False)**kwargs: Additional attributes defined in type annotations
Raises: TypeError, ValueError
Update multiple attributes with validation.
Parameters:
params(Dict[str, Any]): Attributes to update
Raises: ValueError, TypeError
Retrieve attribute(s).
Parameters:
key(str, List[str], or None): Attribute name(s) to retrieve
Returns: Attribute value, dict of values, or all public attributes
Raises: KeyError
Set entity as active.
Set entity as inactive.
Create a deep copy of the entity.
Returns: New entity instance
Serialize entity to dictionary.
Returns: Serialized dictionary
Create entity from dictionary.
Parameters:
data(dict): Serialized data
Returns: New entity instance
Raises: TypeError, ValueError
Check if attribute exists.
Parameters:
key(str): Attribute name
Returns: True if attribute exists and is set
Clear all non-internal attributes to release references.
Access an attribute using dictionary-like syntax.
Parameters:
key(str): Attribute name
Returns: Attribute value
Raises: KeyError
Set an attribute using dictionary-like syntax.
Parameters:
key(str): Attribute namevalue(Any): Value to set
Raises: KeyError, TypeError
Check if attribute exists using 'in' operator.
Parameters:
key(str): Attribute name
Returns: True if attribute exists
Get current cache usage setting.
Returns: True if caching is enabled
Get cached dictionary representation if available.
Returns: Cached dictionary or None
Generic container for managing collections of BaseEntity objects.
BaseContainer(items: Dict[str, T] = None, name: str = None, isactive: bool = True, use_cache: bool = False)Parameters:
items(Dict[str, T]): Initial items dictionaryname(str): Container identifierisactive(bool): Activation statususe_cache(bool): Enable caching
Add item(s) to container.
Parameters:
item: Single item, list of items, or another containercopy_items(bool): Whether to deep copy items
Set/replace item by name.
Parameters:
name(str): Item nameitem(T): Item to set
Remove item by name.
Parameters:
name(str): Item name to remove
Get item by name.
Parameters:
name(str): Item name
Returns: Item or None
Get all items as dictionary.
Returns: Dictionary of all items
Get all items as list.
Returns: List of all items
Get only active items.
Returns: List of active items
Get only inactive items.
Returns: List of inactive items
Query items by attribute values.
Parameters:
conditions(Dict[str, Any]): Attribute conditions
Returns: Matching items
Set or replace all items in the container.
Parameters:
items(Dict[str, T]): Items to set
Raises: ValueError, TypeError
Remove all items.
Create container copy.
Parameters:
deep(bool): Deep copy items
Returns: New container
Activate specific item.
Parameters:
name(str): Item name
Deactivate specific item.
Parameters:
name(str): Item name
Activate all items.
Deactivate all items.
Remove all active items.
Remove all inactive items.
Check if item exists.
Parameters:
name(str): Item name
Returns: True if exists
Serialize container to dictionary.
Parameters:
handle_cyclic_refs(str): How to handle cycles ("mark", "ignore", "raise")
Returns: Serialized dictionary
Create container from dictionary.
Parameters:
data(dict): Serialized data
Returns: New container
Raises: TypeError, ValueError
Abstract base class for operation handlers.
Super(manipulator: Manipulator = None, methods: Optional[Dict[Type, Dict[str, Callable]]] = None, cache_size: int = 2048)Parameters:
manipulator(Manipulator): Associated manipulatormethods(Optional[Dict]): Custom method registrycache_size(int): Method cache size
Execute operation on object.
Parameters:
obj(Any): Target objectattributes(Dict): Operation attributesmethod(str): Specific method to call
Returns: Response dictionary
Register custom method for type.
Parameters:
obj_type(Type): Object typemethod_name(str): Method namemethod(Callable): Method function
Clear the method cache.
Clear all references for cleanup.
Abstract base class for managing entity projects.
Project(name: str, items: Dict[str, BaseEntity] = None)Parameters:
name(str): Project nameitems(Dict): Initial items
Add item to project.
Parameters:
item(BaseEntity): Item to add
Create new item (must be implemented by subclasses).
Set/replace item by name.
Remove item by name.
Get item by name.
Returns: Item instance
Get all items.
Returns: Items dictionary
Get active items.
Returns: List of active items
Get inactive items.
Returns: List of inactive items
Activate specific item.
Deactivate specific item.
Activate all items.
Deactivate all items.
Remove active items.
Remove inactive items.
Serialize project.
Returns: Serialized dictionary
Create project from dictionary.
Parameters:
data(Dict): Serialized data
Returns: New project
Clear all items.
Central orchestrator for operations and objects.
Manipulator(managing_object: Optional[Any] = None, base_classes: Optional[List[Type]] = None, operations: Optional[Dict[str, Callable]] = None, strict_type_check: bool = False)Parameters:
managing_object(Optional[Any]): Default object for operationsbase_classes(Optional[List[Type]]): Base classes for method discoveryoperations(Optional[Dict]): Initial operationsstrict_type_check(bool): Enforce strict typing
Set default managing object.
Parameters:
obj(Any): Object to set
Get current managing object.
Returns: Managing object or None
Register operation handler.
Parameters:
super_instance(Callable): Super instance with execute methodoperation(Optional[str]): Operation name (auto from OPERATION if None)
Raises: ValueError
Process single or batch request.
Parameters:
request(Dict[str, Any]): Request specification
Returns: Response dictionary
Raises: TypeError, ValueError
Get methods for object type.
Parameters:
obj_type(Type): Object type
Returns: Methods dictionary
Raises: ValueError
update_registry(additional_classes: Optional[List[Type]] = None, clear_operations: bool = False) -> None
Update method registry.
Parameters:
additional_classes(Optional[List[Type]]): Additional classesclear_operations(bool): Clear existing operations
Get list of supported operations.
Returns: List of operation names
Clear method resolution cache.
Clear base classes registry.
Clear all operations.
setup_logging(log_file: str = "output.log", log_level: int = logging.INFO, clear_log: bool = False) -> logging.Logger
Configure logging system.
Parameters:
log_file(str): Log file pathlog_level(int): Logging levelclear_log(bool): Clear log file
Returns: Logger instance
Update logging level.
Parameters:
log_level(int): New logging level
Update log clearing behavior.
Parameters:
log_file(str): Log file pathclear_log(bool): Clear log file
Validate value type.
Parameters:
value: Value to checkexpected_type: Expected typename(str): Parameter name
Raises: TypeError
Validate numeric range.
Parameters:
value(float): Value to checkmin_val(float): Minimum valuemax_val(float): Maximum valuename(str): Parameter name
Raises: TypeError, ValueError
Validate positive value.
Parameters:
value(float): Value to checkname(str): Parameter name
Raises: TypeError, ValueError
Validate non-negative value.
Parameters:
value(float): Value to checkname(str): Parameter name
Raises: TypeError, ValueError
Validate non-empty string.
Parameters:
value(str): String to checkname(str): Parameter name
Raises: TypeError, ValueError
Validate list element types.
Parameters:
lst(list): List to checkexpected_type: Expected element typename(str): Parameter name
Raises: TypeError
Validate non-zero value.
Parameters:
value(float): Value to checkname(str): Parameter name
Raises: TypeError, ValueError
Update the logging level for the singleton logger.
Parameters:
log_level(int): New logging level
Update logging configuration to clear the log file.
Parameters:
log_file(str): Path to the log fileclear_log(bool): Whether to clear the log file
All operations return responses in this format:
{
"status": bool, # Operation success
"object": Any, # Target object name/id
"method": str, # Executed method name
"result": Any, # Operation result (if status=True)
"error": str # Error message (if status=False)
}Batch operations return dictionaries mapping request IDs to responses:
{
"request_id_1": { /* response dict */ },
"request_id_2": { /* response dict */ }
}TypeError: Type validation failuresValueError: Value constraint violationsKeyError: Missing keys or attributesAttributeError: Missing object attributesNotImplementedError: Abstract methods not implemented
The framework uses comprehensive type hints:
T: Generic type variable for BaseEntity subclassesUnion[A, B]: Alternative typesOptional[T]: Optional types (Union[T, None])List[T]: Lists of specific typesDict[K, V]: Dictionaries with key/value typesCallable: Function types
logging.DEBUG,logging.INFO,logging.WARNING,logging.ERROR: Log levelsinspect.Parameter.empty: Empty parameter defaultABC: Abstract base class marker
- Template Method: Base classes define algorithms, subclasses customize steps
- Strategy: Super classes as pluggable operation strategies
- Factory: Project.create_item() for object creation
- Composite: Containers managing entity collections
- Observer: Logging system observing operations
- Registry: Manipulator maintaining operation and method registries