function get_all_model_classes
Retrieves a copy of the internal model registry containing all registered model classes mapped by their names.
/tf/active/vicechatdev/CDocs/models/__init__.py
98 - 105
simple
Purpose
This function provides read-only access to the global model registry (_model_registry) that stores all BaseModel subclasses registered in the CDocs system. It returns a shallow copy to prevent external modification of the internal registry while allowing inspection of all available model classes. This is useful for dynamic model discovery, introspection, validation, and plugin systems that need to enumerate available models.
Source Code
def get_all_model_classes() -> Dict[str, Type[BaseModel]]:
"""
Get all registered model classes.
Returns:
Dictionary of model name to model class
"""
return _model_registry.copy()
Return Value
Type: Dict[str, Type[BaseModel]]
Returns a dictionary where keys are string model names and values are Type[BaseModel] class objects. The dictionary is a shallow copy of the internal registry, containing all model classes that have been registered in the system (e.g., 'DocUser', 'ControlledDocument', 'DocumentVersion', 'ReviewCycle', 'ReviewComment', 'ApprovalCycle'). Returns an empty dictionary if no models are registered.
Required Imports
from typing import Dict, Type
from CDocs.models.user_extensions import DocUser
from CDocs.models.document import ControlledDocument, DocumentVersion
from CDocs.models.review import ReviewCycle, ReviewComment
from CDocs.models.approval import ApprovalCycle
Usage Example
# Get all registered model classes
all_models = get_all_model_classes()
# Iterate through registered models
for model_name, model_class in all_models.items():
print(f"Model: {model_name}, Class: {model_class.__name__}")
# Check if a specific model is registered
if 'ControlledDocument' in all_models:
doc_class = all_models['ControlledDocument']
# Instantiate the model
doc = doc_class()
# Get count of registered models
model_count = len(all_models)
print(f"Total registered models: {model_count}")
Best Practices
- This function returns a copy of the registry, so modifications to the returned dictionary will not affect the internal registry
- Use this function for read-only operations like model discovery and validation
- Do not cache the result if models may be registered dynamically at runtime; call the function each time you need current registry state
- The returned dictionary contains class types, not instances; use the classes to instantiate models as needed
- Ensure all required models are registered before calling this function if you expect specific models to be present
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function get_model_class 70.0% similar
-
function register_model 67.8% similar
-
class BaseModel 56.3% similar
-
function api_get_models 45.9% similar
-
function get_available_models 45.8% similar