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.
Asynchronous call
An example to call Inferless API asynchronously
import inferless
import asyncio
import datetime
async def main():
t1 = datetime.datetime.now()
task = asyncio.create_task(inferless.async_call(URL, API_KEY, data))
# You can implement any other async methods here while this call is being executed
await asyncio.sleep(3)
data = await asyncio.gather(task)
t2 = datetime.datetime.now()
print(f"time taken: {t2-t1}")
asyncio.run(main())
Output
time taken: 0:00:05.646579
For the same url, the asynchronous call also took 5 seconds to complete despite the fact that we have added a 3 second delay in the code. This is because the call to Inferless API is being executed asynchronously while the other code is being executed.
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.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2679531941771e43c4c627e6404d803aa624333276cebe5c66c9d1dc9f6017b9 |
|
MD5 | 149d0d04b7caf26aefb8f833662c4478 |
|
BLAKE2b-256 | 78f7e21b07e1fc52a23f846ad70d43cc9b682a305f678aae29077f8152d1eb10 |