Skip to main content

A lightweight async alternative to gradio_client without heavy dependencies.

Project description

noob-gradio

A lightweight, async, dependency-free alternative to the official python gradio_client — written for speed, simplicity, and control.

PyPI Python Version License


Features

  • Fast & Async – built on top of aiohttp and aiofiles, thats all
  • Smart Parameter Checking – validates types, min/max/step before sending
  • Tiny Dependency Footprint – no heavy huggingface_hub and it's reqiurements (a lot)
  • Drop-in familiar syntax – like the official client, but simpler and async

Installation

pip install noob-gradio

Details

This project was inspired by the official gradio_client but rewritten to:

remove unnecessary dependencies,

run fully async,

and perform parameter validation before sending data to the server.

  • gradio_client is ok, but it installs a ton of stuff, so this is a noob remake of it.
  • Available functions: "handle_file", "client.predict" and "client.view_api".
  • Client functions are async and must be awaited.
  • The syntax is exacly the same as in official gradio_client.

New in 1.0.1

You can pass existing session to Client, to reuse it.

import aiohttp
from noob_gradio import Client

async def main():
    session = aiohttp.ClientSession()
    client = Client("url", session=session)
    # added in 1.0.2, will also work
    client.set_session(session)
    result = await client.predict(kwargs)
    print(result)
    # in on_close or similar event/function, at exit
    await session.close()

Example

import asyncio
from noob_gradio import Client, handle_file

async def main():
    async with Client("black-forest-labs/FLUX.1-schnell") as client:
        result = await client.predict(
            prompt="a cat sitting on a chair",
            width=512,
            height=512,
            api_name="/infer",
        )
        print(result)
        # you should get a path to downloaded image and image seed - (Result, Seed) or whatever the space returns
        # to not download you can add download_files=False in Client

asyncio.run(main())

Also this supports the hf_token and other methods of creating a Client and session, here is example of everything

client = Client("black-forest-labs/FLUX.1-schnell", hf_token="secret", download_files=False, headers={"User-Agent": "gradio_real/1.0"})

async def main():
    async with client:
        # args and kwargs are suported
        res = await client.predict("a white cat", width=512, api_name="/infer")
        print(res)
    
    # "async with" alternative
    await client.connect()
    await client.view_api()
    # example file
    file = handle_file("https://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.png")
    # also you can choose different space for each predict or view_api, with src
    res = await client.predict(src="some space with file support", file=file, api_name="/predict")
    print(res)

    await client.close()
    # "async with" or "connect+close" is required because its async

handle_file is needed for input of image or any file, local or from url - predict(image=handle_file("local_path_or_url"), ...)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

noob_gradio-1.2.0.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

noob_gradio-1.2.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file noob_gradio-1.2.0.tar.gz.

File metadata

  • Download URL: noob_gradio-1.2.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for noob_gradio-1.2.0.tar.gz
Algorithm Hash digest
SHA256 951c0edaf3253a830415c8b640a9bb1d13a6f461851290ad28812ba439058055
MD5 7c3babee0b3f74bbf7ab0cb5fe5f5d23
BLAKE2b-256 8177a92122cca2e961c6bf1fff4bcbb00d84f7cb0014e30059b64ec41bb0b9ac

See more details on using hashes here.

Provenance

The following attestation bundles were made for noob_gradio-1.2.0.tar.gz:

Publisher: python-publish.yml on Noob-Lol/noob-gradio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file noob_gradio-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: noob_gradio-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for noob_gradio-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 55061d6d3598c6d4ef6b1a400f14ed165be2d717784c9628d94830a63535a401
MD5 2e9d36c299135e969c082c38c5d8be9e
BLAKE2b-256 a2b547d7d15ebc4cfcab3a636630e700d7c3ea653d93471bff5184516da708d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for noob_gradio-1.2.0-py3-none-any.whl:

Publisher: python-publish.yml on Noob-Lol/noob-gradio

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page