Skip to main content

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)

Source distribution for ivcap_fastapi 0.3.1
File Size Uploaded
ivcap_fastapi-0.3.1.tar.gz 5.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ivcap_fastapi 0.3.1
File Interpreter ABI Platform
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

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page