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.0.3.tar.gz (11.2 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.0.3-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: noob_gradio-1.0.3.tar.gz
  • Upload date:
  • Size: 11.2 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.0.3.tar.gz
Algorithm Hash digest
SHA256 515cd8828484aff6ff9a40ffc7591e094dd9e31ceefd0caa98f6f8a67ba4ff56
MD5 e06ea8e9b19cbe27d3597a787303396c
BLAKE2b-256 d3d2963bc2e67db000ebb27a115c41469ad93f1ceb1cfe883ac16ea4fafbb945

See more details on using hashes here.

Provenance

The following attestation bundles were made for noob_gradio-1.0.3.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.0.3-py3-none-any.whl.

File metadata

  • Download URL: noob_gradio-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 9.3 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.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2d7383105a6ed937d0b9e3f231eb9ead6f21dbd1a8e03d492296027fb11673b6
MD5 c15d95e888e08467c7145bae502ae3f0
BLAKE2b-256 c8710ce66a53d6e101a7dd9a89b6d4895bd26160ae2a10fe9e31a4fb30be25e4

See more details on using hashes here.

Provenance

The following attestation bundles were made for noob_gradio-1.0.3-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