Skip to main content

Helper functions for building AI Tools as 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ivcap_ai_tool-0.2.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ivcap_ai_tool-0.2.0-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file ivcap_ai_tool-0.2.0.tar.gz.

File metadata

  • Download URL: ivcap_ai_tool-0.2.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.16 Darwin/24.2.0

File hashes

Hashes for ivcap_ai_tool-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0900a04161bffb996cec8f9b5275ba2cbd9cc03d46e4a5daa70ccd34dcdec86d
MD5 724f6211d9ca08a42e91b877f4a1b6fe
BLAKE2b-256 4e1ab53f1efdae3e38c9704978c275318ac939d1ff3139e9fe649404d55eac48

See more details on using hashes here.

File details

Details for the file ivcap_ai_tool-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: ivcap_ai_tool-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.3 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

Hashes for ivcap_ai_tool-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f8222b4f5bd7c54dcff82b0094b5e8c21af90a93ed30e5e7fc1c49ef0d7aca27
MD5 f691c8768eb8b25692bfa3686f4b8ac6
BLAKE2b-256 c52054c69ea19215be4f5d898b14693e5140e5cfa59ac17b0f90711e09b6eb53

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page