Procodile API
The Procodile Python API is provided by the procodile package.
procodile.ProcessRegistry
Bases: Mapping[str, Process]
A registry for processes.
Processes are Python functions with extra metadata and can be extended
to create workflows using steps decorator.
A Workflow consists of one or more Python functions with metadata, designed to execute sequentially by resolving dependencies and passing outputs to downstream steps.
This class provides a read-only mapping from unique identifiers to facade-like Process instances. While the user interacts with these processes, the registry internally manages full [Workflow][procodile.workflow.Workflow] instances.
The internal Workflow objects hold the source-of-truth metadata required for dependency resolution and execution, while the exposed Process objects serve as the public interface for client interaction.
Source code in procodile\src\procodile\registry.py
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 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 162 163 164 165 166 167 168 169 | |
main(function=None, /, *, id=None, version=None, title=None, description=None, inputs=None, outputs=None, inputs_arg=False)
A decorator that can be applied to a user function in order to register it as a process in this registry.
Note:
- Use `main` decorator to express a process that comprises multiple steps
that require a reference to the main entry point.
- Use `process` decorator to express a process that has no steps,
hence requires no reference to a main step.
The decorator can be used with or without parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
Callable | None
|
The decorated function that is passed automatically since
|
None
|
id
|
Optional[str]
|
Optional process identifier. Must be unique within the registry. If not provided, the fully qualified function name will be used. |
None
|
version
|
Optional[str]
|
Optional version identifier. If not provided, |
None
|
title
|
Optional[str]
|
Optional, short process title. |
None
|
description
|
Optional[str]
|
Optional, detailed description of the process. If not provided, the function's docstring, if any, will be used. |
None
|
inputs
|
Optional[dict[str, FieldInfo | InputDescription]]
|
Optional mapping from function argument names
to |
None
|
outputs
|
Optional[dict[str, FieldInfo | OutputDescription]]
|
Mapping from output names to
|
None
|
inputs_arg
|
str | bool
|
Specifies the use of an inputs argument. An inputs argument
is a container for the actual process inputs. If specified, it must
be the only function argument (besides an optional job context
argument) and must be a subclass of |
False
|
Source code in procodile\src\procodile\registry.py
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 | |
options: show_source: false heading_level: 3
procodile.Process
dataclass
A process comprises a process description and executable code in form of a Python function.
Instances of this class are be managed by the ProcessRegistry.
Attributes:
| Name | Type | Description |
|---|---|---|
function |
Callable
|
The user's Python function. |
signature |
Signature
|
The signature of |
job_ctx_arg |
str | None
|
Names of |
model_class |
type[BaseModel]
|
Pydantic model class for the arguments of |
description |
ProcessDescription
|
Process description modeled after OGC API - Processes - Part 1: Core. |
Source code in procodile\src\procodile\process.py
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 | |
create(function, id=None, version=None, title=None, description=None, inputs=None, outputs=None, inputs_arg=False)
classmethod
Create a new instance of this dataclass.
Called by the process_registry.main() and by the your_function.step()
decorator, where your_function is the function decorated with main().
Not intended to be used by clients.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
function
|
Callable
|
The decorated function that is passed automatically since
|
required |
id
|
Optional[str]
|
Optional process identifier. Must be unique within the registry. If not provided, the fully qualified function name will be used. |
None
|
version
|
Optional[str]
|
Optional version identifier. If not provided, |
None
|
title
|
Optional[str]
|
Optional, short process title. |
None
|
description
|
Optional[str]
|
Optional, detailed description of the process. If not provided, the function's docstring, if any, will be used. |
None
|
inputs
|
Optional[dict[str, FieldInfo | InputDescription]]
|
Optional mapping from function argument names
to |
None
|
outputs
|
Optional[dict[str, FieldInfo | OutputDescription]]
|
Mapping from output names to
|
None
|
inputs_arg
|
str | bool
|
Specifies the use of an inputs argument. An inputs argument
is a container for the actual process inputs. If specified, it must
be the only function argument (besides an optional job context
argument) and must be a subclass of |
False
|
Source code in procodile\src\procodile\process.py
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 | |
options: show_source: false heading_level: 3
gavicore.models.ProcessRequest
Bases: BaseModel
Source code in gavicore\src\gavicore\models.py
284 285 286 287 288 | |
options: show_source: false heading_level: 3
gavicore.models.Subscriber
Bases: BaseModel
Optional URIs for callbacks for this job.
Support for this parameter is not required and the parameter may be
removed from the API definition, if conformance class 'callback'
is not listed in the conformance declaration under /conformance.
Source code in gavicore\src\gavicore\models.py
99 100 101 102 103 104 105 106 107 108 109 110 | |
options: show_source: false heading_level: 3
gavicore.models.Output
Bases: BaseModel
Source code in gavicore\src\gavicore\models.py
301 302 303 | |
options: show_source: false heading_level: 3
gavicore.util.request.ExecutionRequest
Bases: ProcessRequest
Process execution request. Extends ProcessRequest
- to allow the process identifier being part of the request,
- to allow creating nested object values for input names with dots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process_id
|
Process identifier |
required | |
dotpath
|
Whether dots in input names should be used to create
nested object values. Defaults to |
required | |
inputs
|
Optional process inputs given as key-value mapping. Values may be of any JSON-serializable type accepted by the given process. |
required | |
outputs
|
Optional process outputs given as key-value mapping. Values are of type Output supported by the given process. |
required | |
subscriber
|
Optional subscriber of type Subscriber comprising callback URLs that are informed about process status changes while the processing takes place. |
required |
Source code in gavicore\src\gavicore\util\request.py
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 | |
to_process_request()
Convert this execution request into a process request as used by the
execute-process operation.
Source code in gavicore\src\gavicore\util\request.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
create(process_id=None, dotpath=False, request_path=None, inputs=None, subscribers=None)
classmethod
A factory method to create an execution request.
The method is intended to support CLI implementations parsing user inputs and creating validated execution requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process_id
|
str | None
|
Process identifier |
None
|
dotpath
|
bool
|
Whether dots in input names should be used to create
nested object values. Defaults to |
False
|
request_path
|
str | None
|
Local path to a file that contains an execution request in YAML or JSON format. |
None
|
inputs
|
list[str] | None
|
Optional process inputs given as a list of " |
None
|
subscribers
|
list[str] | None
|
Optional subscribers given as a list of
" |
None
|
Return
A validated execution request of type ExecutionRequest.
Raise
ValueError: if a validation error occurs.
Source code in gavicore\src\gavicore\util\request.py
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 | |
from_process_description(process_description, dotpath=False)
classmethod
Create an execution request from the given process description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
process_description
|
ProcessDescription
|
The process description |
required |
dotpath
|
bool
|
Whether to allow for dot-separated input names for nested object values |
False
|
Returns:
| Type | Description |
|---|---|
ExecutionRequest
|
The execution requests populated with default values. |
Source code in gavicore\src\gavicore\util\request.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
options: show_source: false heading_level: 3
procodile.JobContext
Bases: ABC
Report process progress and check for task cancellation.
A process function can retrieve the current job context
- via JobContext.get() from within a process function, or
- as a function argument of type JobContext.
Source code in procodile\src\procodile\job.py
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 | |
get()
classmethod
Get the current job context.
Returns the current job context that can be used by process functions to report job progress in percent or via messages and to check whether cancellation has been requested. This function is intended to be called from within a process function executed as a job. If called as a usual Python function (without a job serving as context), the returned context will have no-op methods only.
Returns:
| Type | Description |
|---|---|
JobContext
|
An instance of the current job context. |
Source code in procodile\src\procodile\job.py
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 | |
report_progress(progress=None, message=None)
abstractmethod
Report task progress.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
progress
|
Optional[int]
|
Progress in percent. |
None
|
message
|
Optional[str]
|
Detail progress message. |
None
|
Raises:
| Type | Description |
|---|---|
JobCancellationException
|
if an attempt has been made to cancel this job. |
Source code in procodile\src\procodile\job.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
is_cancelled()
abstractmethod
Test whether an attempt has been made to cancel this job. It may still be running though.
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in procodile\src\procodile\job.py
96 97 98 99 100 101 102 103 | |
check_cancelled()
abstractmethod
Raise a JobCancellationException, if
an attempt has been made to cancel this job.
Source code in procodile\src\procodile\job.py
105 106 107 108 109 | |
options: show_source: false heading_level: 3
procodile.JobCancelledException
Bases: Exception
Raised if a job's cancellation has been requested.
Source code in procodile\src\procodile\job.py
30 31 | |
options: show_source: false heading_level: 3
procodile.cli.new_cli(registry, name, version, help=None, summary=None, context=None)
Get the CLI instance configured to use the process registry that is given either by
- a reference of the form "path.to.module:attribute",
- or process registry instance,
- or as a no-arg process registry getter function.
The process registry is usually a singleton in your application.
The context object obj of the returned CLI object
will be of type dict and will contain
a process registry getter function using the key
get_process_registry.
The function must be called before any CLI command or
callback has been invoked. Otherwise, the provided
get_process_registry getter will not be recognized and
all commands that require the process registry will
fail with an AssertionError.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
The name of the CLI application. |
required |
registry
|
Union[str, ProcessRegistry, Callable[[], ProcessRegistry]]
|
A registry reference string, or a registry instance, or a no-arg function that returns a registry instance. |
required |
help
|
str | None
|
Optional CLI application help text. If not provided, the default
|
None
|
summary
|
str | None
|
A one-sentence human-readable description of the tool that
will be used by the default help text. Hence, used only,
if |
None
|
version
|
str
|
Optional version string. If not provided, the
|
required |
context
|
dict[str, Any] | None
|
Additional context values that will be registered with the CLI
and can be accessed by commands that you add to the
returned |
None
|
Return
a typer.Typer instance
Source code in procodile\src\procodile\cli\cli.py
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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 | |
options: show_source: false heading_level: 3