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)
Metadata
Release files for ivcap_fastapi 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ivcap_fastapi-0.3.1.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ivcap_fastapi-0.3.1-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details |
Total release size: 13.5 kB
Release files / ivcap_fastapi-0.3.1.tar.gz
| Download URL | ivcap_fastapi-0.3.1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d622a2b62bf299f6f90d97cc5bae02fcba4e89166290bcd635f7e0b4328f1428
|
|
BLAKE2b-256 checksum How to use checksums |
5332183b93c9f723c53c3d0c2682a0ec5d1ee7e7c8f3272a831245b18dafc0e0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.16 Darwin/24.2.0
|
Release files / ivcap_fastapi-0.3.1-py2.py3-none-any.whl
| Download URL | ivcap_fastapi-0.3.1-py2.py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0a23db12156e3b678b58fcccf4c69663c7550f4b529c9629a6420d8fbf001f71
|
|
BLAKE2b-256 checksum How to use checksums |
cb423282fbccabddf749e35b6b8e8e872e4246caecda390e0998176fe94f21ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.9.16 Darwin/24.2.0
|