Skip to main content

No project description provided

Project description

Python Client to call Inferless API

Installation

$ pip install inferless

Usage

This client can be used to call Inferless API from your python code. It supports both synchronous and asynchronous calls.

Constants

Fetch the URL and API_KEY from the Inferless console https://console-dev.inferless.com/

URL = "<url>"
API_KEY = "<api_key>"

Input Data

Input data can be provided in two formats, as shown below as inputs and data.

INPUTS = { "inputs" : 
          [
              {
                "name": "prompt",
                "shape": [
                  1
                ],
                "datatype": "BYTES",
                "data": [
                  "Once upon a time"
                ]
              }
          ]
        }

This other format is simpler and can be used if other parameters are not required. datatype and shape are automatically inferred.

DATA = {
    "prompt": "Once upon a time"
}

Synchrounous call

An example to call Inferless API synchronously

import inferless
import datetime
def main():
    t1 = datetime.datetime.now()
    data = inferless.call(url=URL, workspace_api_key=API_KEY, inputs=INPUTS)
    t2 = datetime.datetime.now()
    print(f"time taken: {t2-t1}")

main()

Output

time taken: 0:00:05.218835

For a particular url, the synchronous call took approximately 5 seconds to complete.

Async call with callback

This library also supports async calls to Inferless API. The following example shows how to call Inferless API in background with a callback function.

import inferless
import datetime

def callback_func(e, response):
    # e is the error object
    # response is the response object
    with open("response.json", "w") as f:
        f.write(json.dumps(response))
    

t1 = datetime.now()
inferless.call_async(url=URL, workspace_api_key=KEY, data=data, callback=callback_func)
t2 = datetime.now()
print(t2 - t1)

Output

time taken: 0:00:00.000141

It can be seen that the program continues without waiting for the response. The response is written to a file by the callback function after it is received.

Batch call

If the model is configured for batch processing, is_batch should be set to True

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

inferless-0.2.4.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

inferless-0.2.4-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file inferless-0.2.4.tar.gz.

File metadata

  • Download URL: inferless-0.2.4.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.15 Darwin/23.6.0

File hashes

Hashes for inferless-0.2.4.tar.gz
Algorithm Hash digest
SHA256 22dfdb4ad0fa119d5c39d25b74026c4a69d54065e09fe3291ded62066307fee9
MD5 8decdb0a9478faa7e66325a2ed19e5a6
BLAKE2b-256 39c6b6ab195bfa9bdbf2a2b1ced8ca0f2dbd67ade88da0d986b5b04ec3e35ab0

See more details on using hashes here.

File details

Details for the file inferless-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: inferless-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.15 Darwin/23.6.0

File hashes

Hashes for inferless-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 a18b051e19219e5ae9c3290f06a07d58f8cdfd59c7bc33e8d09bb6475b0a3d15
MD5 1a1f0ad89d3b22f699cb34854a7df2ff
BLAKE2b-256 90c0e001b56f57a102867c4cf47d9cd8ed58bcd97d3d088bdf47b2cc2a616f28

See more details on using hashes here.

Supported by

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