Skip to content

Connect to and convert any web endpoint into an python SDK. Built-in threading, async jobs and fastapi/runpod/FastTaskAPI endpoint support.

License

Notifications You must be signed in to change notification settings

SocAIty/fastSDK

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

74 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fastSDK

Built your SDK for any hosted service

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.

Why?

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.

Service compatibility

Out of the box works with following services:

Can be used together with

Features:

  • Easy file upload, download thanks to media-toolkit.
  • 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.
  • Streaming of files
  • Automatic serialization of data types

Installation

To install from PyPI: This version includes all features needed to conveniently wrap your API into an SDK.

pip install fastsdk

Get started

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(...)

Authorization

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.

FastSDK 💕 FastTaskAPI

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.

Contribute

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.

Note: THE PACKAGE IS STILL IN DEVELOPMENT!

LEAVE A STAR TO SUPPORT US. ANY BUG REPORT OR CONTRIBUTION IS HIGHLY APPRECIATED.

About

Connect to and convert any web endpoint into an python SDK. Built-in threading, async jobs and fastapi/runpod/FastTaskAPI endpoint support.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published