Reference
cattle_grid.extensions
BaseConfig
Extension
dataclass
Data model for an extension
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
|
required |
module
|
str
|
|
required |
lifespan
|
Callable[list, Awaitable[None]] | None
|
|
None
|
config_class
|
Any
|
|
<class 'cattle_grid.extensions.BaseConfig'>
|
Config
|
Any | None
|
|
None
|
configuration
|
Any | None
|
|
None
|
activity_router
|
RabbitRouter
|
Includable to RabbitBroker router. |
<dynamic>
|
api_router
|
APIRouter
|
Read more about it in the FastAPI docs for Bigger Applications - Multiple Files. Example |
<dynamic>
|
api_prefix
|
str
|
|
''
|
transformer
|
Callable[list, Awaitable[Dict]] | None
|
|
None
|
transformer_inputs
|
List[str] | None
|
|
None
|
transformer_outputs
|
List[str] | None
|
|
None
|
lookup_method
|
Callable[list, Awaitable[Dict]] | None
|
|
None
|
lookup_order
|
int | None
|
|
None
|
method_information
|
List[MethodInformation]
|
Built-in mutable sequence. If no argument is given, the constructor creates a new empty list. The argument must be an iterable if specified. |
<dynamic>
|
Source code in cattle_grid/extensions/__init__.py
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
Config = None
class-attribute
instance-attribute
config_class = BaseConfig
class-attribute
instance-attribute
Expected configuration class
lifespan = None
class-attribute
instance-attribute
The lifespan function
module
instance-attribute
module the extension is defined in, should be set to __name__
name
instance-attribute
name of the extension, must be unique
configure(config)
Configures the extension
The configuration is validated using the config_class.
get(path)
Allows one to add a get endpoint to the API Router of the extension
lookup()
Allows building the extension via decorator.
extension = Extension("my extension")
@extension.lookup()
async def lookup(l: Lookup) -> Lookup:
...
Source code in cattle_grid/extensions/__init__.py
subscribe(routing_key, description=None)
Allows building the extension via decorator.
extension = Extension("my extension")
@extension.subscribe("routing_key")
async def subscriber(msg: dict): ...
Dependency injection is available for the subscriber function.
Source code in cattle_grid/extensions/__init__.py
transform(inputs=[], outputs=[])
Allows building the extension via decorator. Usage:
extension = Extension("my extension")
@extension.transform(inputs=["inputs"], outputs=["outputs"])
async def transformer(a: dict):
...
Source code in cattle_grid/extensions/__init__.py
cattle_grid.extensions.load
add_routers_to_broker(broker, extensions)
Adds the routers to the broker
add_routes_to_api(app, extensions)
Adds the routes to the api
Source code in cattle_grid/extensions/load/__init__.py
build_lookup(extensions)
Builds the lookup method
Source code in cattle_grid/extensions/load/__init__.py
build_transformer(extensions)
Build the transformer
Source code in cattle_grid/extensions/load/__init__.py
collect_method_information(extensions)
Collects the method information from the extensions
lifespan_from_extensions(extensions)
async
Creates the lifespan from the extensions
load_extension(extension_information)
Loads a single extension
Source code in cattle_grid/extensions/load/__init__.py
load_extensions(settings)
Loads the extensions from settings
Source code in cattle_grid/extensions/load/__init__.py
set_globals(extensions)
Sets global variables in cattle_grid.dependencies