Skip to content

Component Registries

lariv.registry

Central module for registering and retrieving decoupled plugin resources.

This module provides the BaseRegistry and its specialized subclasses for registering Views, Schemas, UI Components, Tools, Generators, and Environments across independent Django apps without hard dependencies.

BaseRegistry

Base registry class. Provides a generic dictionary-based registration pattern. Should be subclassed for each specific resource type (e.g., UI, View, Generator).

Source code in lariv/registry.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
class BaseRegistry:
    """
    Base registry class. Provides a generic dictionary-based registration pattern.
    Should be subclassed for each specific resource type (e.g., UI, View, Generator).
    """

    _registry = {}
    _type_name: str = "item"

    @classmethod
    def register(cls, key: str):
        """
        Decorator to register a class under a specific string key.

        Args:
            key (str): The unique string identifier for the registered item.
                       Conventionally formatted as `app_name.ClassName`.

        Returns:
            callable: The decorator function wrapping the targeted class.
        """
        def decorator(klass):
            cls._registry[key] = klass
            return klass

        return decorator

    @classmethod
    def get(cls, key: str):
        """
        Retrieve a registered class by its string key.

        Args:
            key (str): The unique identifier.

        Returns:
            type: The registered class.

        Raises:
            ValueError: If no item is registered under the provided key.
        """
        rVal = cls._registry.get(key)
        if not rVal:
            raise ValueError(f"Component {key} not found")
        return rVal

    @classmethod
    def all(cls):
        """Return all registered items."""
        return dict(cls._registry)

    @classmethod
    def keys(cls):
        """Return all registered keys."""
        return list(cls._registry.keys())

all() classmethod

Return all registered items.

Source code in lariv/registry.py
55
56
57
58
@classmethod
def all(cls):
    """Return all registered items."""
    return dict(cls._registry)

get(key) classmethod

Retrieve a registered class by its string key.

Parameters:

Name Type Description Default
key str

The unique identifier.

required

Returns:

Name Type Description
type

The registered class.

Raises:

Type Description
ValueError

If no item is registered under the provided key.

Source code in lariv/registry.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@classmethod
def get(cls, key: str):
    """
    Retrieve a registered class by its string key.

    Args:
        key (str): The unique identifier.

    Returns:
        type: The registered class.

    Raises:
        ValueError: If no item is registered under the provided key.
    """
    rVal = cls._registry.get(key)
    if not rVal:
        raise ValueError(f"Component {key} not found")
    return rVal

keys() classmethod

Return all registered keys.

Source code in lariv/registry.py
60
61
62
63
@classmethod
def keys(cls):
    """Return all registered keys."""
    return list(cls._registry.keys())

register(key) classmethod

Decorator to register a class under a specific string key.

Parameters:

Name Type Description Default
key str

The unique string identifier for the registered item. Conventionally formatted as app_name.ClassName.

required

Returns:

Name Type Description
callable

The decorator function wrapping the targeted class.

Source code in lariv/registry.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
@classmethod
def register(cls, key: str):
    """
    Decorator to register a class under a specific string key.

    Args:
        key (str): The unique string identifier for the registered item.
                   Conventionally formatted as `app_name.ClassName`.

    Returns:
        callable: The decorator function wrapping the targeted class.
    """
    def decorator(klass):
        cls._registry[key] = klass
        return klass

    return decorator

EnvironmentRegistry

Bases: BaseRegistry

Registry for application-specific environment/context handlers.

Source code in lariv/registry.py
144
145
146
147
148
149
150
151
152
class EnvironmentRegistry(BaseRegistry):
    """Registry for application-specific environment/context handlers."""
    _registry = {}
    _type_name = "environment"

    @classmethod
    def get_for_app(cls, app_name):
        """Get environment class for a specific app."""
        return cls.get(app_name)

get_for_app(app_name) classmethod

Get environment class for a specific app.

Source code in lariv/registry.py
149
150
151
152
@classmethod
def get_for_app(cls, app_name):
    """Get environment class for a specific app."""
    return cls.get(app_name)

GeneratorRegistry

Bases: BaseRegistry

Registry for data generators used to seed databases. Implements topological sorting to ensure generators run in the correct dependency order.

Source code in lariv/registry.py
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
class GeneratorRegistry(BaseRegistry):
    """
    Registry for data generators used to seed databases.
    Implements topological sorting to ensure generators run in the correct
    dependency order.
    """
    _registry = {}
    _type_name = "generator"

    @classmethod
    def run_all(cls):
        """
        Run all registered data generators in their declared dependency order.
        Each generator must implement a `.run()` method.
        """
        ordered = cls._resolve_order()
        for key in ordered:
            generator_cls = cls._registry[key]
            print(f"\n=== Running {key} ===")
            generator_cls().run()

    @classmethod
    def _resolve_order(cls) -> list[str]:
        """
        Perform a topological sort based on generator dependencies.

        Returns:
            list[str]: A list of generator keys ordered by dependency resolution.
        """
        from collections import deque

        in_degree = {k: 0 for k in cls._registry}
        graph = {k: [] for k in cls._registry}

        for key, gen_cls in cls._registry.items():
            for dep in getattr(gen_cls, "dependencies", []):
                if dep in cls._registry:
                    graph[dep].append(key)
                    in_degree[key] += 1

        queue = deque([k for k, d in in_degree.items() if d == 0])
        result = []

        while queue:
            node = queue.popleft()
            result.append(node)
            for neighbor in graph[node]:
                in_degree[neighbor] -= 1
                if in_degree[neighbor] == 0:
                    queue.append(neighbor)

        return result

run_all() classmethod

Run all registered data generators in their declared dependency order. Each generator must implement a .run() method.

Source code in lariv/registry.py
 99
100
101
102
103
104
105
106
107
108
109
@classmethod
def run_all(cls):
    """
    Run all registered data generators in their declared dependency order.
    Each generator must implement a `.run()` method.
    """
    ordered = cls._resolve_order()
    for key in ordered:
        generator_cls = cls._registry[key]
        print(f"\n=== Running {key} ===")
        generator_cls().run()

SchemaRegistry

Bases: BaseRegistry

Registry for Pydantic or Django REST Framework schemas.

Source code in lariv/registry.py
72
73
74
75
class SchemaRegistry(BaseRegistry):
    """Registry for Pydantic or Django REST Framework schemas."""
    _registry = {}
    _type_name = "schema"

ToolRegistry

Bases: BaseRegistry

Registry for LangChain or MCP tools exposed by plugins.

Source code in lariv/registry.py
84
85
86
87
class ToolRegistry(BaseRegistry):
    """Registry for LangChain or MCP tools exposed by plugins."""
    _registry = {}
    _type_name = "tool"

UIRegistry

Bases: BaseRegistry

Registry for python-based UI Components.

Source code in lariv/registry.py
78
79
80
81
class UIRegistry(BaseRegistry):
    """Registry for python-based UI Components."""
    _registry = {}
    _type_name = "ui"

ViewRegistry

Bases: BaseRegistry

Registry for Django View classes.

Source code in lariv/registry.py
66
67
68
69
class ViewRegistry(BaseRegistry):
    """Registry for Django View classes."""
    _registry = {}
    _type_name = "view"