fastprocesses 0.7.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- fastprocesses-0.7.4/AUTHORS.md +1 -0
- fastprocesses-0.7.4/PKG-INFO +274 -0
- fastprocesses-0.7.4/README.md +243 -0
- fastprocesses-0.7.4/pyproject.toml +117 -0
- fastprocesses-0.7.4/src/fastprocesses/__init__.py +8 -0
- fastprocesses-0.7.4/src/fastprocesses/api/__init__.py +0 -0
- fastprocesses-0.7.4/src/fastprocesses/api/manager.py +377 -0
- fastprocesses-0.7.4/src/fastprocesses/api/router.py +177 -0
- fastprocesses-0.7.4/src/fastprocesses/api/server.py +24 -0
- fastprocesses-0.7.4/src/fastprocesses/celery_worker.py +45 -0
- fastprocesses-0.7.4/src/fastprocesses/common.py +59 -0
- fastprocesses-0.7.4/src/fastprocesses/core/__init__.py +0 -0
- fastprocesses-0.7.4/src/fastprocesses/core/base_process.py +137 -0
- fastprocesses-0.7.4/src/fastprocesses/core/cache.py +55 -0
- fastprocesses-0.7.4/src/fastprocesses/core/config.py +17 -0
- fastprocesses-0.7.4/src/fastprocesses/core/logging.py +75 -0
- fastprocesses-0.7.4/src/fastprocesses/core/models.py +188 -0
- fastprocesses-0.7.4/src/fastprocesses/processes/__init__.py +0 -0
- fastprocesses-0.7.4/src/fastprocesses/processes/process_registry.py +114 -0
- fastprocesses-0.7.4/src/fastprocesses/py.typed +0 -0
- fastprocesses-0.7.4/src/fastprocesses/worker/__init__.py +0 -0
- fastprocesses-0.7.4/src/fastprocesses/worker/celery_app.py +154 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Authors
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: fastprocesses
|
|
3
|
+
Version: 0.7.4
|
|
4
|
+
Summary: A library to create a FastAPI-based OGC API Processes wrapper around existing projects.
|
|
5
|
+
Author: Stefan Schuhart
|
|
6
|
+
Author-email: stefan.schuhart@gv.hamburg.de
|
|
7
|
+
Requires-Python: >=3.10
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Intended Audience :: Developers
|
|
10
|
+
Classifier: Programming Language :: Python
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development
|
|
17
|
+
Classifier: Topic :: Utilities
|
|
18
|
+
Classifier: Typing :: Typed
|
|
19
|
+
Requires-Dist: celery (>=5.4.0,<6.0.0)
|
|
20
|
+
Requires-Dist: fastapi (>=0.115.8,<0.116.0)
|
|
21
|
+
Requires-Dist: loguru (>=0.7.3,<0.8.0)
|
|
22
|
+
Requires-Dist: pydantic (>=2.10.6,<3.0.0)
|
|
23
|
+
Requires-Dist: pydantic-settings (>=2.7.1,<3.0.0)
|
|
24
|
+
Requires-Dist: redis (>=5.2.1,<6.0.0)
|
|
25
|
+
Requires-Dist: uvicorn (>=0.34.0,<0.35.0)
|
|
26
|
+
Project-URL: Changelog, https://github.com/geowerkstatt-hamburg/fastProcesses/CHANGELOG.md
|
|
27
|
+
Project-URL: Documentation, https://github.com/geowerkstatt-hamburg/fastProcesses/README.md
|
|
28
|
+
Project-URL: Homepage, https://geowerkstatt-hamburg.github.io/fastProcesses
|
|
29
|
+
Project-URL: Repository, https://github.com/geowerkstatt-hamburg/fastProcesses
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# fastprocesses
|
|
33
|
+
|
|
34
|
+
A library to create a FastAPI-based OGC API Processes wrapper around existing projects. This library simplifies the process of defining and registering processes, making it easy to build and deploy OGC API Processes.
|
|
35
|
+
|
|
36
|
+
AI was used to create this code.
|
|
37
|
+
|
|
38
|
+
## Version: 0.7.4
|
|
39
|
+
|
|
40
|
+
### Description
|
|
41
|
+
|
|
42
|
+
fastprocesses is a Python library that provides a simple and efficient way to create OGC API Processes using FastAPI. It allows you to define processes, register them, and expose them through a FastAPI application with minimal effort, following the OGC API Processes 1.0.0 specification.
|
|
43
|
+
|
|
44
|
+
### Features
|
|
45
|
+
|
|
46
|
+
- **OGC API Processes Compliance**: Fully implements the OGC API Processes 1.0.0 Core specification
|
|
47
|
+
- **FastAPI Integration**: Leverages FastAPI for building high-performance APIs
|
|
48
|
+
- **Process Management**: Supports both synchronous and asynchronous process execution
|
|
49
|
+
- **Job Control**: Implements job control options (sync-execute, async-execute)
|
|
50
|
+
- **Output Handling**: Supports various output transmission modes (value, reference)
|
|
51
|
+
- **Result Caching**: Built-in Redis-based caching for process results
|
|
52
|
+
- **Celery Integration**: Asynchronous task processing using Celery
|
|
53
|
+
- **Pydantic Models**: Strong type validation for process inputs and outputs
|
|
54
|
+
- **Logging**: Uses `loguru` for modern logging with rotation support
|
|
55
|
+
|
|
56
|
+
### Architecture
|
|
57
|
+
|
|
58
|
+
```mermaid
|
|
59
|
+
graph TB
|
|
60
|
+
subgraph Client
|
|
61
|
+
CLI[Client Request]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
subgraph FastAPI Application
|
|
65
|
+
API[OGCProcessesAPI]
|
|
66
|
+
Router[API Router]
|
|
67
|
+
PM[ProcessManager]
|
|
68
|
+
PR[ProcessRegistry]
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
subgraph Redis
|
|
72
|
+
RC[Redis Cache]
|
|
73
|
+
RR[Redis Registry]
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
subgraph Process
|
|
77
|
+
BP[BaseProcess]
|
|
78
|
+
SP[SimpleProcess]
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
subgraph Worker
|
|
82
|
+
CW[Celery Worker]
|
|
83
|
+
CT[CacheResultTask]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
%% Client interactions
|
|
87
|
+
CLI -->|HTTP Request| API
|
|
88
|
+
API -->|Route Request| Router
|
|
89
|
+
Router -->|Execute Process| PM
|
|
90
|
+
|
|
91
|
+
%% Process Manager flow
|
|
92
|
+
PM -->|Get Process| PR
|
|
93
|
+
PM -->|Check Cache| RC
|
|
94
|
+
PM -->|Submit Task| CW
|
|
95
|
+
PM -->|Get Result| RC
|
|
96
|
+
|
|
97
|
+
%% Process Registry
|
|
98
|
+
PR -->|Store/Retrieve| RR
|
|
99
|
+
PR -.->|Registers| SP
|
|
100
|
+
SP -->|Inherits| BP
|
|
101
|
+
|
|
102
|
+
%% Worker flow
|
|
103
|
+
CW -->|Execute| SP
|
|
104
|
+
CW -->|Cache Result| CT
|
|
105
|
+
CT -->|Store| RC
|
|
106
|
+
|
|
107
|
+
%% Styling
|
|
108
|
+
classDef api fill:#f9f,stroke:#333,stroke-width:2px
|
|
109
|
+
classDef cache fill:#bbf,stroke:#333,stroke-width:2px
|
|
110
|
+
classDef process fill:#bfb,stroke:#333,stroke-width:2px
|
|
111
|
+
classDef worker fill:#fbb,stroke:#333,stroke-width:2px
|
|
112
|
+
|
|
113
|
+
class API,Router api
|
|
114
|
+
class RC,RR cache
|
|
115
|
+
class BP,SP process
|
|
116
|
+
class CW,CT worker
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Usage
|
|
120
|
+
|
|
121
|
+
1. **Define a Process**: Create a new process by subclassing `BaseProcess` and using the `@register_process` decorator.
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from fastprocesses.core.base_process import BaseProcess
|
|
125
|
+
from fastprocesses.core.models import (
|
|
126
|
+
ProcessDescription,
|
|
127
|
+
ProcessInput,
|
|
128
|
+
ProcessJobControlOptions,
|
|
129
|
+
ProcessOutput,
|
|
130
|
+
ProcessOutputTransmission,
|
|
131
|
+
Schema,
|
|
132
|
+
)
|
|
133
|
+
from fastprocesses.processes.process_registry import register_process
|
|
134
|
+
|
|
135
|
+
@register_process("simple_process")
|
|
136
|
+
class SimpleProcess(BaseProcess):
|
|
137
|
+
# Define process description as a class variable
|
|
138
|
+
process_description = ProcessDescription(
|
|
139
|
+
id="simple_process",
|
|
140
|
+
title="Simple Process",
|
|
141
|
+
version="1.0.0",
|
|
142
|
+
description="A simple example process",
|
|
143
|
+
jobControlOptions=[
|
|
144
|
+
ProcessJobControlOptions.SYNC_EXECUTE,
|
|
145
|
+
ProcessJobControlOptions.ASYNC_EXECUTE
|
|
146
|
+
],
|
|
147
|
+
outputTransmission=[
|
|
148
|
+
ProcessOutputTransmission.VALUE
|
|
149
|
+
],
|
|
150
|
+
inputs={
|
|
151
|
+
"input_text": ProcessInput(
|
|
152
|
+
title="Input Text",
|
|
153
|
+
description="Text to process",
|
|
154
|
+
schema=Schema(
|
|
155
|
+
type="string",
|
|
156
|
+
minLength=1,
|
|
157
|
+
maxLength=1000
|
|
158
|
+
)
|
|
159
|
+
)
|
|
160
|
+
},
|
|
161
|
+
outputs={
|
|
162
|
+
"output_text": ProcessOutput(
|
|
163
|
+
title="Output Text",
|
|
164
|
+
description="Processed text",
|
|
165
|
+
schema=Schema(
|
|
166
|
+
type="string"
|
|
167
|
+
)
|
|
168
|
+
)
|
|
169
|
+
},
|
|
170
|
+
keywords=["text", "processing"],
|
|
171
|
+
metadata={
|
|
172
|
+
"created": "2024-02-19",
|
|
173
|
+
"provider": "Example Organization"
|
|
174
|
+
}
|
|
175
|
+
)
|
|
176
|
+
|
|
177
|
+
async def execute(self, inputs: Dict[str, Any]) -> Dict[str, Any]:
|
|
178
|
+
input_text = inputs["inputs"]["input_text"]
|
|
179
|
+
output_text = input_text.upper()
|
|
180
|
+
return {"output_text": output_text}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
2. **Create the FastAPI Application**:
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
import uvicorn
|
|
187
|
+
from fastprocesses.api.server import OGCProcessesAPI
|
|
188
|
+
|
|
189
|
+
app = OGCProcessesAPI(
|
|
190
|
+
title="Simple Process API",
|
|
191
|
+
version="1.0.0",
|
|
192
|
+
description="A simple API for running processes"
|
|
193
|
+
).get_app()
|
|
194
|
+
|
|
195
|
+
if __name__ == "__main__":
|
|
196
|
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
3. **Start the Services**:
|
|
200
|
+
|
|
201
|
+
Start Redis (required for caching and Celery):
|
|
202
|
+
```bash
|
|
203
|
+
docker run -d -p 6379:6379 redis
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Start the Celery worker:
|
|
207
|
+
```bash
|
|
208
|
+
celery -A fastprocesses.worker.celery_app worker
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
Start the FastAPI application:
|
|
212
|
+
```bash
|
|
213
|
+
poetry run python examples/run_example.py
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
4. **Use the API**:
|
|
217
|
+
|
|
218
|
+
Execute a process (async):
|
|
219
|
+
```bash
|
|
220
|
+
curl -X POST "http://localhost:8000/processes/simple_process/execution" \
|
|
221
|
+
-H "Content-Type: application/json" \
|
|
222
|
+
-d '{
|
|
223
|
+
"inputs": {
|
|
224
|
+
"input_text": "hello world"
|
|
225
|
+
},
|
|
226
|
+
"mode": "async"
|
|
227
|
+
}'
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Execute a process (sync):
|
|
231
|
+
```bash
|
|
232
|
+
curl -X POST "http://localhost:8000/processes/simple_process/execution" \
|
|
233
|
+
-H "Content-Type: application/json" \
|
|
234
|
+
-d '{
|
|
235
|
+
"inputs": {
|
|
236
|
+
"input_text": "hello world"
|
|
237
|
+
},
|
|
238
|
+
"mode": "sync"
|
|
239
|
+
}'
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### API Endpoints
|
|
243
|
+
|
|
244
|
+
- `GET /`: Landing page
|
|
245
|
+
- `GET /conformance`: OGC API conformance declaration
|
|
246
|
+
- `GET /processes`: List available processes
|
|
247
|
+
- `GET /processes/{process_id}`: Get process description
|
|
248
|
+
- `POST /processes/{process_id}/execution`: Execute a process
|
|
249
|
+
- `GET /jobs`: List all jobs
|
|
250
|
+
- `GET /jobs/{job_id}`: Get job status
|
|
251
|
+
- `GET /jobs/{job_id}/results`: Get job results
|
|
252
|
+
|
|
253
|
+
### Configuration
|
|
254
|
+
|
|
255
|
+
The library can be configured using environment variables:
|
|
256
|
+
|
|
257
|
+
```bash
|
|
258
|
+
REDIS_CACHE_URL=redis://localhost:6379/0
|
|
259
|
+
CELERY_BROKER_URL=redis://localhost:6379/1
|
|
260
|
+
CELERY_RESULT_BACKEND=redis://localhost:6379/2
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
### Notes:
|
|
264
|
+
How to serialize pydantic models within celery? -> https://benninger.ca/posts/celery-serializer-pydantic/
|
|
265
|
+
|
|
266
|
+
!IMPORTANT!: Cache hash key is based on original unprocessed inputs always this ensures consistent caching and cache retrieval which does not depend on arbitrary processed data, which can change when the process is updated or changed!
|
|
267
|
+
|
|
268
|
+
### Version Notes
|
|
269
|
+
- **Version: 0.7.4**: added paging to processes and jobs, including limit and offset query params
|
|
270
|
+
- **0.5.0**: Extended Schema model
|
|
271
|
+
- **0.4.0**: Added full OGC API Processes 1.0.0 Core compliance
|
|
272
|
+
- **0.3.0**: Added job control and output transmission options
|
|
273
|
+
- **0.2.0**: Added Redis caching and Celery integration
|
|
274
|
+
- **0.1.0**: Initial release with basic process support
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
# fastprocesses
|
|
2
|
+
|
|
3
|
+
A library to create a FastAPI-based OGC API Processes wrapper around existing projects. This library simplifies the process of defining and registering processes, making it easy to build and deploy OGC API Processes.
|
|
4
|
+
|
|
5
|
+
AI was used to create this code.
|
|
6
|
+
|
|
7
|
+
## Version: 0.7.4
|
|
8
|
+
|
|
9
|
+
### Description
|
|
10
|
+
|
|
11
|
+
fastprocesses is a Python library that provides a simple and efficient way to create OGC API Processes using FastAPI. It allows you to define processes, register them, and expose them through a FastAPI application with minimal effort, following the OGC API Processes 1.0.0 specification.
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
- **OGC API Processes Compliance**: Fully implements the OGC API Processes 1.0.0 Core specification
|
|
16
|
+
- **FastAPI Integration**: Leverages FastAPI for building high-performance APIs
|
|
17
|
+
- **Process Management**: Supports both synchronous and asynchronous process execution
|
|
18
|
+
- **Job Control**: Implements job control options (sync-execute, async-execute)
|
|
19
|
+
- **Output Handling**: Supports various output transmission modes (value, reference)
|
|
20
|
+
- **Result Caching**: Built-in Redis-based caching for process results
|
|
21
|
+
- **Celery Integration**: Asynchronous task processing using Celery
|
|
22
|
+
- **Pydantic Models**: Strong type validation for process inputs and outputs
|
|
23
|
+
- **Logging**: Uses `loguru` for modern logging with rotation support
|
|
24
|
+
|
|
25
|
+
### Architecture
|
|
26
|
+
|
|
27
|
+
```mermaid
|
|
28
|
+
graph TB
|
|
29
|
+
subgraph Client
|
|
30
|
+
CLI[Client Request]
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
subgraph FastAPI Application
|
|
34
|
+
API[OGCProcessesAPI]
|
|
35
|
+
Router[API Router]
|
|
36
|
+
PM[ProcessManager]
|
|
37
|
+
PR[ProcessRegistry]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
subgraph Redis
|
|
41
|
+
RC[Redis Cache]
|
|
42
|
+
RR[Redis Registry]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
subgraph Process
|
|
46
|
+
BP[BaseProcess]
|
|
47
|
+
SP[SimpleProcess]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
subgraph Worker
|
|
51
|
+
CW[Celery Worker]
|
|
52
|
+
CT[CacheResultTask]
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
%% Client interactions
|
|
56
|
+
CLI -->|HTTP Request| API
|
|
57
|
+
API -->|Route Request| Router
|
|
58
|
+
Router -->|Execute Process| PM
|
|
59
|
+
|
|
60
|
+
%% Process Manager flow
|
|
61
|
+
PM -->|Get Process| PR
|
|
62
|
+
PM -->|Check Cache| RC
|
|
63
|
+
PM -->|Submit Task| CW
|
|
64
|
+
PM -->|Get Result| RC
|
|
65
|
+
|
|
66
|
+
%% Process Registry
|
|
67
|
+
PR -->|Store/Retrieve| RR
|
|
68
|
+
PR -.->|Registers| SP
|
|
69
|
+
SP -->|Inherits| BP
|
|
70
|
+
|
|
71
|
+
%% Worker flow
|
|
72
|
+
CW -->|Execute| SP
|
|
73
|
+
CW -->|Cache Result| CT
|
|
74
|
+
CT -->|Store| RC
|
|
75
|
+
|
|
76
|
+
%% Styling
|
|
77
|
+
classDef api fill:#f9f,stroke:#333,stroke-width:2px
|
|
78
|
+
classDef cache fill:#bbf,stroke:#333,stroke-width:2px
|
|
79
|
+
classDef process fill:#bfb,stroke:#333,stroke-width:2px
|
|
80
|
+
classDef worker fill:#fbb,stroke:#333,stroke-width:2px
|
|
81
|
+
|
|
82
|
+
class API,Router api
|
|
83
|
+
class RC,RR cache
|
|
84
|
+
class BP,SP process
|
|
85
|
+
class CW,CT worker
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Usage
|
|
89
|
+
|
|
90
|
+
1. **Define a Process**: Create a new process by subclassing `BaseProcess` and using the `@register_process` decorator.
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from fastprocesses.core.base_process import BaseProcess
|
|
94
|
+
from fastprocesses.core.models import (
|
|
95
|
+
ProcessDescription,
|
|
96
|
+
ProcessInput,
|
|
97
|
+
ProcessJobControlOptions,
|
|
98
|
+
ProcessOutput,
|
|
99
|
+
ProcessOutputTransmission,
|
|
100
|
+
Schema,
|
|
101
|
+
)
|
|
102
|
+
from fastprocesses.processes.process_registry import register_process
|
|
103
|
+
|
|
104
|
+
@register_process("simple_process")
|
|
105
|
+
class SimpleProcess(BaseProcess):
|
|
106
|
+
# Define process description as a class variable
|
|
107
|
+
process_description = ProcessDescription(
|
|
108
|
+
id="simple_process",
|
|
109
|
+
title="Simple Process",
|
|
110
|
+
version="1.0.0",
|
|
111
|
+
description="A simple example process",
|
|
112
|
+
jobControlOptions=[
|
|
113
|
+
ProcessJobControlOptions.SYNC_EXECUTE,
|
|
114
|
+
ProcessJobControlOptions.ASYNC_EXECUTE
|
|
115
|
+
],
|
|
116
|
+
outputTransmission=[
|
|
117
|
+
ProcessOutputTransmission.VALUE
|
|
118
|
+
],
|
|
119
|
+
inputs={
|
|
120
|
+
"input_text": ProcessInput(
|
|
121
|
+
title="Input Text",
|
|
122
|
+
description="Text to process",
|
|
123
|
+
schema=Schema(
|
|
124
|
+
type="string",
|
|
125
|
+
minLength=1,
|
|
126
|
+
maxLength=1000
|
|
127
|
+
)
|
|
128
|
+
)
|
|
129
|
+
},
|
|
130
|
+
outputs={
|
|
131
|
+
"output_text": ProcessOutput(
|
|
132
|
+
title="Output Text",
|
|
133
|
+
description="Processed text",
|
|
134
|
+
schema=Schema(
|
|
135
|
+
type="string"
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
},
|
|
139
|
+
keywords=["text", "processing"],
|
|
140
|
+
metadata={
|
|
141
|
+
"created": "2024-02-19",
|
|
142
|
+
"provider": "Example Organization"
|
|
143
|
+
}
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
async def execute(self, inputs: Dict[str, Any]) -> Dict[str, Any]:
|
|
147
|
+
input_text = inputs["inputs"]["input_text"]
|
|
148
|
+
output_text = input_text.upper()
|
|
149
|
+
return {"output_text": output_text}
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
2. **Create the FastAPI Application**:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
import uvicorn
|
|
156
|
+
from fastprocesses.api.server import OGCProcessesAPI
|
|
157
|
+
|
|
158
|
+
app = OGCProcessesAPI(
|
|
159
|
+
title="Simple Process API",
|
|
160
|
+
version="1.0.0",
|
|
161
|
+
description="A simple API for running processes"
|
|
162
|
+
).get_app()
|
|
163
|
+
|
|
164
|
+
if __name__ == "__main__":
|
|
165
|
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
3. **Start the Services**:
|
|
169
|
+
|
|
170
|
+
Start Redis (required for caching and Celery):
|
|
171
|
+
```bash
|
|
172
|
+
docker run -d -p 6379:6379 redis
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
Start the Celery worker:
|
|
176
|
+
```bash
|
|
177
|
+
celery -A fastprocesses.worker.celery_app worker
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
Start the FastAPI application:
|
|
181
|
+
```bash
|
|
182
|
+
poetry run python examples/run_example.py
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
4. **Use the API**:
|
|
186
|
+
|
|
187
|
+
Execute a process (async):
|
|
188
|
+
```bash
|
|
189
|
+
curl -X POST "http://localhost:8000/processes/simple_process/execution" \
|
|
190
|
+
-H "Content-Type: application/json" \
|
|
191
|
+
-d '{
|
|
192
|
+
"inputs": {
|
|
193
|
+
"input_text": "hello world"
|
|
194
|
+
},
|
|
195
|
+
"mode": "async"
|
|
196
|
+
}'
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
Execute a process (sync):
|
|
200
|
+
```bash
|
|
201
|
+
curl -X POST "http://localhost:8000/processes/simple_process/execution" \
|
|
202
|
+
-H "Content-Type: application/json" \
|
|
203
|
+
-d '{
|
|
204
|
+
"inputs": {
|
|
205
|
+
"input_text": "hello world"
|
|
206
|
+
},
|
|
207
|
+
"mode": "sync"
|
|
208
|
+
}'
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### API Endpoints
|
|
212
|
+
|
|
213
|
+
- `GET /`: Landing page
|
|
214
|
+
- `GET /conformance`: OGC API conformance declaration
|
|
215
|
+
- `GET /processes`: List available processes
|
|
216
|
+
- `GET /processes/{process_id}`: Get process description
|
|
217
|
+
- `POST /processes/{process_id}/execution`: Execute a process
|
|
218
|
+
- `GET /jobs`: List all jobs
|
|
219
|
+
- `GET /jobs/{job_id}`: Get job status
|
|
220
|
+
- `GET /jobs/{job_id}/results`: Get job results
|
|
221
|
+
|
|
222
|
+
### Configuration
|
|
223
|
+
|
|
224
|
+
The library can be configured using environment variables:
|
|
225
|
+
|
|
226
|
+
```bash
|
|
227
|
+
REDIS_CACHE_URL=redis://localhost:6379/0
|
|
228
|
+
CELERY_BROKER_URL=redis://localhost:6379/1
|
|
229
|
+
CELERY_RESULT_BACKEND=redis://localhost:6379/2
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### Notes:
|
|
233
|
+
How to serialize pydantic models within celery? -> https://benninger.ca/posts/celery-serializer-pydantic/
|
|
234
|
+
|
|
235
|
+
!IMPORTANT!: Cache hash key is based on original unprocessed inputs always this ensures consistent caching and cache retrieval which does not depend on arbitrary processed data, which can change when the process is updated or changed!
|
|
236
|
+
|
|
237
|
+
### Version Notes
|
|
238
|
+
- **Version: 0.7.4**: added paging to processes and jobs, including limit and offset query params
|
|
239
|
+
- **0.5.0**: Extended Schema model
|
|
240
|
+
- **0.4.0**: Added full OGC API Processes 1.0.0 Core compliance
|
|
241
|
+
- **0.3.0**: Added job control and output transmission options
|
|
242
|
+
- **0.2.0**: Added Redis caching and Celery integration
|
|
243
|
+
- **0.1.0**: Initial release with basic process support
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["poetry-core"]
|
|
3
|
+
build-backend = "poetry.core.masonry.api"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "fastprocesses"
|
|
7
|
+
description = "A library to create a FastAPI-based OGC API Processes wrapper around existing projects."
|
|
8
|
+
authors = [{name = "Stefan Schuhart", email = "stefan.schuhart@gv.hamburg.de"}]
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
keywords = []
|
|
12
|
+
dynamic = ["version"]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 3 - Alpha",
|
|
15
|
+
"Intended Audience :: Developers",
|
|
16
|
+
"Programming Language :: Python",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Topic :: Software Development",
|
|
23
|
+
"Topic :: Utilities",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
dependencies = ["pydantic (>=2.10.6,<3.0.0)", "celery (>=5.4.0,<6.0.0)", "fastapi (>=0.115.8,<0.116.0)", "uvicorn (>=0.34.0,<0.35.0)", "pydantic-settings (>=2.7.1,<3.0.0)", "redis (>=5.2.1,<6.0.0)", "loguru (>=0.7.3,<0.8.0)"]
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://geowerkstatt-hamburg.github.io/fastProcesses"
|
|
30
|
+
Documentation = "https://github.com/geowerkstatt-hamburg/fastProcesses/README.md"
|
|
31
|
+
Changelog = "https://github.com/geowerkstatt-hamburg/fastProcesses/CHANGELOG.md"
|
|
32
|
+
Repository = "https://github.com/geowerkstatt-hamburg/fastProcesses"
|
|
33
|
+
|
|
34
|
+
[tool.ruff]
|
|
35
|
+
# Enable the pycodestyle (`E`) and Pyflakes (`F`) rules by default.
|
|
36
|
+
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
|
|
37
|
+
# McCabe complexity (`C901`) by default.
|
|
38
|
+
select = ["E", "F"]
|
|
39
|
+
# same as isort, black
|
|
40
|
+
line-length = 88
|
|
41
|
+
# Assume Python 3.8
|
|
42
|
+
target-version = "py310"
|
|
43
|
+
# Exclude a variety of commonly ignored directories.
|
|
44
|
+
exclude = [
|
|
45
|
+
".bzr",
|
|
46
|
+
".direnv",
|
|
47
|
+
".eggs",
|
|
48
|
+
".git",
|
|
49
|
+
".git-rewrite",
|
|
50
|
+
".hg",
|
|
51
|
+
".mypy_cache",
|
|
52
|
+
".nox",
|
|
53
|
+
".pants.d",
|
|
54
|
+
".pytype",
|
|
55
|
+
".ruff_cache",
|
|
56
|
+
".svn",
|
|
57
|
+
".tox",
|
|
58
|
+
".venv",
|
|
59
|
+
"__pypackages__",
|
|
60
|
+
"_build",
|
|
61
|
+
"buck-out",
|
|
62
|
+
"build",
|
|
63
|
+
"dist",
|
|
64
|
+
"node_modules",
|
|
65
|
+
"venv",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[tool.poetry]
|
|
69
|
+
name = "fastprocesses"
|
|
70
|
+
version = "0.7.4"
|
|
71
|
+
description = "A library to create a FastAPI-based OGC API Processes wrapper around existing projects."
|
|
72
|
+
authors = ["Stefan Schuhart <stefan.schuhart@gv.hamburg.de>"]
|
|
73
|
+
readme = "README.md"
|
|
74
|
+
|
|
75
|
+
[tool.poetry.dependencies]
|
|
76
|
+
python = ">=3.10,<4.0"
|
|
77
|
+
|
|
78
|
+
[tool.poetry.group.dev.dependencies]
|
|
79
|
+
# formatting, quality, tests
|
|
80
|
+
autoflake = ">=1.4"
|
|
81
|
+
black = ">=23.7"
|
|
82
|
+
isort = ">=5.7.0"
|
|
83
|
+
mypy = ">=0.812"
|
|
84
|
+
pytest = ">=6.2.2"
|
|
85
|
+
pytest-cov = ">=2.11.1"
|
|
86
|
+
pytest-randomly = ">=3.5.0"
|
|
87
|
+
pytest-sugar = ">=0.9.4,<1"
|
|
88
|
+
pytest-xdist = ">=2.2.0,<3"
|
|
89
|
+
types-toml = ">=0.10.1,<1"
|
|
90
|
+
pre-commit = ">=3.4.0,<4"
|
|
91
|
+
bump2version = "^1.0.1"
|
|
92
|
+
|
|
93
|
+
[tool.poetry.group.docs]
|
|
94
|
+
optional = true
|
|
95
|
+
|
|
96
|
+
[tool.poetry.group.docs.dependencies]
|
|
97
|
+
jupyter-book = "^0.15"
|
|
98
|
+
sphinx-autoapi = "^2"
|
|
99
|
+
sphinxcontrib-autoyaml = "^1.1"
|
|
100
|
+
|
|
101
|
+
[tool.poetry.scripts]
|
|
102
|
+
start-celery-worker = "fastprocesses.celery_worker:main"
|
|
103
|
+
|
|
104
|
+
[tool.black]
|
|
105
|
+
line-length = 88
|
|
106
|
+
exclude = "tests/fixtures"
|
|
107
|
+
|
|
108
|
+
[tool.isort]
|
|
109
|
+
profile = "black"
|
|
110
|
+
line_length = 88
|
|
111
|
+
not_skip = "__init__.py"
|
|
112
|
+
multi_line_output = 3
|
|
113
|
+
force_single_line = false
|
|
114
|
+
balanced_wrapping = true
|
|
115
|
+
default_section = "THIRDPARTY"
|
|
116
|
+
known_first_party = "fastprocesses"
|
|
117
|
+
include_trailing_comma = true
|
|
File without changes
|