Python library for easily interacting with trained machine learning models
Actively maintained. Last release 3 weeks ago, commits in 26 of the last 26 weeks. A safe choice.
pip install gradio-clientgradio_client: Use a Gradio app as an API -- in 3 lines of Python
This directory contains the source code for gradio_client, a lightweight Python library that makes it very easy to use any Gradio app as an API.
As an example, consider this Hugging Face Space that transcribes audio files that are recorded from the microphone.

Using the gradio_client library, we can easily use the Gradio as an API to transcribe audio files programmatically.
Here's the entire code to do it:
from gradio_client import Client
client = Client("abidlabs/whisper")
client.predict("audio_sample.wav")
>> "This is a test of the whisper speech recognition model."
The Gradio client works with any Gradio Space, whether it be an image generator, a stateful chatbot, or a tax calculator.
Installation
If you already have a recent version of gradio, then the gradio_client is included as a dependency.
Otherwise, the lightweight gradio_client package can be installed from pip (or pip3) and works with Python versions 3.10 or higher:
$ pip install gradio_client
Basic Usage
Connecting to a Space or a Gradio app
Start by connecting instantiating a Client object and connecting it to a Gradio app that is running on Spaces (or anywhere else)!
Connecting to a Space
from gradio_client import Client
client = Client("abidlabs/en2fr") # a Space that translates from English to French
You can also connect to private Spaces by passing in your HF token with the hf_token parameter. You can get your HF token here: https://huggingface.co/settings/tokens
from gradio_client import Client
client = Client("abidlabs/my-private-space", hf_token="...")
Duplicating a Space for private use
While you can use any public Space as an API, you may get rate limited by Hugging Face if you make too many requests. For unlimited usage of a Space, simply duplicate the Space to create a private Space, and then use it to make as many requests as you'd like!