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>"
data = { "inputs" :
[
{
"name": "prompt",
"shape": [
1
],
"datatype": "BYTES",
"data": [
"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, API_KEY, data)
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, KEY, DATA, callback_func)
t2 = datetime.now()
print(t2 - t1)
Output
time taken: 0:00:00.000141
It can be seen that the program exits without waiting for the response. The response is written to a file by the callback function after it is received.
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
Hashes for inferless-0.1.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 318c8380c96dd1cadab6d4978d84113b765182e1e18bd19cb8dce265574d2455 |
|
MD5 | da86c0db037d54a429ad192c604bfd8d |
|
BLAKE2b-256 | 53c731f38fc0a256496a1bec4d23024a7ee6fe6ff40feae6bd1434d88dc7c75c |