Helper functions for building FastAPI based IVCAP services
Project description
ivcap_fastapi: Python helpers for building FastAPI based IVCAP services
A python library containing various helper and middleware functions to support converting FastAPI based tools into IVCAP services.
Content
Try-Later Middleware
This middleware is supporting the use case where the execution of a requested service is taking longer than the caller is willing to wait. A typical use case is where the service is itself outsourcing the execution to some other long-running service but may immediately receive a reference to the eventual result.
In this case, raising a TryLaterException will return with a 204
status code and additional information on how to later check back for the
result.
from ivcap_fastapi import TryLaterException, use_try_later_middleware
use_try_later_middleware(app)
@app.post("/big_job")
def big_job(req: Request) -> Response:
jobID, expected_exec_time = scheduling_big_job(req)
raise TryLaterException(f"/jobs/{jobID}", expected_exec_time)
@app.get("/jobs/{jobID}")
def get_job(jobID: str) -> Response:
resp = find_result_for(job_id)
return resp
Specifically, raising TryLaterException(location, delay) will
return an HTTP response with a 204 status code with the additional
HTTP headers Location and Retry-Later set to location and
delay respectively.
JSON-RPC Middleware
This middleware will convert any POST / with a payload
following the JSON-RPC
specification to an internal POST /{method} and will return
the result formatted according to the JSON-RPC spec.
from ivcap_fastapi import use_json_rpc_middleware
use_json_rpc_middleware(app)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ivcap_fastapi-0.3.1.tar.gz.
File metadata
- Download URL: ivcap_fastapi-0.3.1.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.16 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d622a2b62bf299f6f90d97cc5bae02fcba4e89166290bcd635f7e0b4328f1428
|
|
| MD5 |
4774555f14fbe4de57f6e4e19f3f73b6
|
|
| BLAKE2b-256 |
5332183b93c9f723c53c3d0c2682a0ec5d1ee7e7c8f3272a831245b18dafc0e0
|
File details
Details for the file ivcap_fastapi-0.3.1-py2.py3-none-any.whl.
File metadata
- Download URL: ivcap_fastapi-0.3.1-py2.py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.9.16 Darwin/24.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a23db12156e3b678b58fcccf4c69663c7550f4b529c9629a6420d8fbf001f71
|
|
| MD5 |
30186fe4c173be8f3cd4808d41bf0652
|
|
| BLAKE2b-256 |
cb423282fbccabddf749e35b6b8e8e872e4246caecda390e0998176fe94f21ef
|