Skip to main content

Python client for modelrunner.ai

Project description

modelrunner.ai Python client

This is a Python client library for interacting with ML models deployed on modelrunner.ai.

Getting started

To install the client, run:

pip install modelrunner-ai

To use the client, you need to have an API key. You can get one by signing up at modelrunner.ai. Once you have it, set it as an environment variable:

export MODELRUNNER_KEY=your-api-key

Now you can use the client to interact with your models. Here's an example of how to use it:

import asyncio
import modelrunner_ai

async def main():
    response = await modelrunner_ai.run_async("bytedance/sdxl-lightning-4step", arguments={"prompt": "two friends cooking together"})
    print(response["output"])


asyncio.run(main())

Uploading files

If the model requires files as input, you can upload them directly to media.modelrunner.ai (our CDN) and pass the URLs to the client. Here's an example:

import modelrunner_ai

input_image = modelrunner_ai.upload_file("./image.jpg")
print(input_image)
response = modelrunner_ai.run("swook/inspyrenet", arguments={"image_path": input_image})
print(response["output"])

Queuing requests

When you want to send a request and keep receiving updates on its status, you can use the submit method. Here's an example:

import asyncio
import modelrunner_ai

async def main():
    response = await modelrunner_ai.submit_async("bytedance/sdxl-lightning-4step", arguments={"prompt": "two friends cooking together"})

    logs_index = 0
    async for event in response.iter_events(with_logs=True):
        if isinstance(event, modelrunner_ai.Queued):
            print("Queued. Position:", event.position)
        elif isinstance(event, (modelrunner_ai.InProgress, modelrunner_ai.Completed)):
            new_logs = event.logs[logs_index:]
            for log in new_logs:
                print(log["message"])
            logs_index = len(event.logs)

    result = await response.get()
    print(result["output"])


asyncio.run(main())

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

modelrunner_ai-0.0.13.tar.gz (133.0 kB view details)

Uploaded Source

Built Distribution

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

modelrunner_ai-0.0.13-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file modelrunner_ai-0.0.13.tar.gz.

File metadata

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

File hashes

Hashes for modelrunner_ai-0.0.13.tar.gz
Algorithm Hash digest
SHA256 dd76f2c2bac23253ab35260351a33e87e018049186ea77f4fa7a1e880e5d2351
MD5 0c0822d9c519dd54dc3ddf9e3fc8998c
BLAKE2b-256 aceddbdf81f8dca4219427275b23d09d50a47ed85af1c9e2ca0d825e80a039d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for modelrunner_ai-0.0.13.tar.gz:

Publisher: release.yaml on modelrunner/modelrunner

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

File details

Details for the file modelrunner_ai-0.0.13-py3-none-any.whl.

File metadata

File hashes

Hashes for modelrunner_ai-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 77b48b077de88de71b23f230efdae656ba19f9a76adc9797dfa9d215a7035437
MD5 a84b22a07cbd5159ab219ff08c4bbb74
BLAKE2b-256 069e020cb13f5141c5f1ebdd162aa6dce993c11296dd9d9ed231dd16be1a6763

See more details on using hashes here.

Provenance

The following attestation bundles were made for modelrunner_ai-0.0.13-py3-none-any.whl:

Publisher: release.yaml on modelrunner/modelrunner

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