Skip to main content

Python client for fal.ai

Project description

fal.ai Python client

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

Getting started

To install the client, run:

pip install fal-client

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

export FAL_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 fal_client

response = fal_client.run("fal-ai/fast-sdxl", arguments={"prompt": "a cute cat, realistic, orange"})
print(response["images"][0]["url"])

Asynchronous requests

The client also supports asynchronous requests out of the box. Here's an example:

import asyncio
import fal_client

async def main():
    response = await fal_client.run_async("fal-ai/fast-sdxl", arguments={"prompt": "a cute cat, realistic, orange"})
    print(response["images"][0]["url"])


asyncio.run(main())

Uploading files

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

import fal_client

audio_url = fal_client.upload_file("path/to/audio.wav")
response = fal_client.run("fal-ai/whisper", arguments={"audio_url": audio_url})
print(response["text"])

Encoding files as in-memory data URLs

If you don't want to upload your file to our CDN service (for latency reasons, for example), you can encode it as a data URL and pass it directly to the client. Here's an example:

import fal_client

audio_data_url = fal_client.encode_file("path/to/audio.wav")
response = fal_client.run("fal-ai/whisper", arguments={"audio_url": audio_data_url})
print(response["text"])

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 fal_client

async def main():
    response = await fal_client.submit_async("fal-ai/fast-sdxl", arguments={"prompt": "a cute cat, realistic, orange"})

    logs_index = 0
    async for event in response.iter_events(with_logs=True):
        if isinstance(event, fal_client.Queued):
            print("Queued. Position:", event.position)
        elif isinstance(event, (fal_client.InProgress, fal_client.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["images"][0]["url"])


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

fal_client-0.14.1.tar.gz (35.0 kB view details)

Uploaded Source

Built Distribution

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

fal_client-0.14.1-py3-none-any.whl (21.4 kB view details)

Uploaded Python 3

File details

Details for the file fal_client-0.14.1.tar.gz.

File metadata

  • Download URL: fal_client-0.14.1.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fal_client-0.14.1.tar.gz
Algorithm Hash digest
SHA256 d62b1ff118e253de90484d5be27b953e2de57760ef5d7311e9ab42937e318b84
MD5 cbec45bb25e7b8fc4ef3460740b1cec9
BLAKE2b-256 a7c4a3d47a94a954f57ecde6b5c15325eb2144e680cf4cd6e10d05e45b8c7ac7

See more details on using hashes here.

Provenance

The following attestation bundles were made for fal_client-0.14.1.tar.gz:

Publisher: release.yaml on fal-ai/fal

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

File details

Details for the file fal_client-0.14.1-py3-none-any.whl.

File metadata

  • Download URL: fal_client-0.14.1-py3-none-any.whl
  • Upload date:
  • Size: 21.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for fal_client-0.14.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6881645080cd4f828ba50abfde3d0e2d18b4d10d1bc2e1fb4054a067fe8f1e87
MD5 83698c05bfe968a1260d5c6a1f09229a
BLAKE2b-256 fad7b65e59b15e18a02f559bb263d41e933570415ab1f3327887e64be8e14cdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for fal_client-0.14.1-py3-none-any.whl:

Publisher: release.yaml on fal-ai/fal

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