Ever wanted to use web APIs as if they are any other python function? It was never easier to build an SDK for your hosted services, than it is with fastSDK. FastSDK creates a full functioning client for any openapi service.
Let's say you have created a webservice for example with fastAPI or flask and now you want to write a python client for it. In a first approach you would just use the requests library and send the requests to the server. However, while you do so, your cpu is idle waiting for the request to finish. Over time your requirements get bigger, suddenly you do not only have one endpoint but multiples. You will do different requests in parallel, you need to transfer files, and you struggle to do so in a structured, performant way. Suddenly you end up in a threading, asyncio and complexity hell with many inconsistencies. You realize that you cannot transfer your 1GB video via an simple web request to your beautiful API. All these problems are solved with the fastSDK. Simple API calls, file uploads, job handling, and cloud storage providers are just a few features of the fastSDK.
FastSDK is designed to work beautifully with long-running services like machine learning and data processing endpoints. It works hand-in-hand with FastTaskAPI that let's you build and deploy those services and endpoints easily.
Out of the box works with following services:
- Services created with FastTaskAPI which return a job object.
- Runpod services
- Cog services
- OpenAPI 3.0 / RestAPIs
Can be used together with
- Socaity.ai services
- Replicate.ai services
- Easy file upload, download thanks to media-toolkit.
- Support for cloud storage providers like Azure Blob Storage and Amazon S3.
- Async and Threaded job support. Execute multiple requests and heavy preprocessing tasks in parallel and with high speed.
- Massively parallel job and request execution.
- Working with services that create "Jobs". The SDK will wait for the job to finish and return the result.
- Support for FastTaskAPI and runpod (serverless) endpoints.
- Retrieving the job status, progres and print status updates.
- Streaming of files
- Automatic serialization of data types
To install from PyPI: This version includes all features needed to conveniently wrap your API into an SDK.
pip install fastsdk
First get your openapi.json file from your service usully under: http://localhost:8000/openapi.json. You can use an example openapi.json from our face2face service located in this repos under /test/test_files/face2face.json
# create a full working client stub
create_sdk("openapi.json", save_path="my_service.py")
# Import the client. It will have a method for each of your service endpoints including all parameters and its default values.
from my_service import awesome_client
awesome_client.my_method(...)
Let's say you have created your SDK (client) with @fastSDK
and named it face2face
Then you can init it with arguments. In this moment you can pass the api key.
f2f = face2face(api_key="my_api_key")
api_job = f2f.swap_img_to_img(source_img="my_face_1.jpg", target_img="my_face_2.jpg")
swapped_img = api_job.get_result()
Alternatively you can set the api_keys in the settings and give them names like "runpod". Add this at the beginning of your script.
import os
import settings
settings.api_keys["runpod"] = os.getenv("my_api_key")
API keys can be set in environment variables, when creating the Service Client or when initializing your SDK. In settings.py the default environment variables are set.
FastTaskAPI allows you to easily create and deploy services that can be used with fastSDK. They are two beating hearts 💕 beating in harmony for client <--> service interaction. Create your service now.
We at socaity want to provide the best tools to bring generative AI to the cloud. Please report bugs, your ideas and feature requests in the issues section. fastSDK is licensed under the MIT license and free-to-use.