### Install fal-client Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/README.md Install the fal-client library using pip. ```bash pip install fal-client ``` -------------------------------- ### Install Fal Packages from Source Source: https://github.com/fal-ai/fal/blob/main/README.md Install the fal, fal-client, and isolate_proto packages in editable mode from the repository root. This is useful for development and contributing to the project. ```bash pip install -e 'projects/fal[dev]' pip install -e 'projects/fal_client[dev]' pip install -e 'projects/isolate_proto[dev]' ``` -------------------------------- ### Install Fal Client with Dev Dependencies Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/AGENTS.md Install the fal_client package in editable mode with development dependencies. Run this command from the repository root. ```bash pip install -e 'projects/fal_client[dev]' ``` -------------------------------- ### Install and Authenticate Fal Source: https://github.com/fal-ai/fal/blob/main/README.md Install the fal package and log in to your Fal account. This is the first step to deploying Python code to Fal. ```bash pip install fal fal auth login ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/fal-ai/fal/blob/main/AGENTS.md Installs development dependencies for the main fal package, fal_client, and isolate_proto from the repository root. Use individual package installations for faster iteration when working on a single package. ```bash python -m pip install --upgrade pip pip install -e 'projects/fal[dev]' pip install -e 'projects/fal_client[dev]' pip install -e 'projects/isolate_proto[dev]' ``` -------------------------------- ### Install Development Dependencies Source: https://github.com/fal-ai/fal/blob/main/projects/isolate_proto/AGENTS.md Install the isolate_proto package with development dependencies from the repository root. ```bash pip install -e 'projects/isolate_proto[dev]' ``` -------------------------------- ### Install Fal Client and Set API Key Source: https://github.com/fal-ai/fal/blob/main/README.md Install the fal-client package and set your Fal API key as an environment variable. This is necessary for making calls to Fal models and endpoints. ```bash pip install fal-client export FAL_KEY="your-api-key" ``` -------------------------------- ### Install Fal Package with Dev Dependencies Source: https://github.com/fal-ai/fal/blob/main/projects/fal/AGENTS.md Install the fal package in editable mode with development dependencies from the repository root. ```bash pip install -e 'projects/fal[dev]' ``` -------------------------------- ### Define a Minimal Fal App Source: https://github.com/fal-ai/fal/blob/main/README.md Create a basic Fal application using the `fal.App` class and define an endpoint. This serves as a starting point for serverless applications. ```python import fal class MyApp(fal.App): @fal.endpoint("/") def run(self) -> dict: return {"message": "Hello, World!"} ``` -------------------------------- ### Call a Fal Model API Source: https://github.com/fal-ai/fal/blob/main/README.md Use the fal-client to subscribe to and call a Fal model. This example demonstrates how to generate an image using a specified prompt and size. ```python import fal_client result = fal_client.subscribe( "fal-ai/flux/schnell", arguments={ "prompt": "a futuristic cityscape at sunset", "image_size": "landscape_16_9", }, ) print(result["images"][0]["url"]) ``` -------------------------------- ### Regenerate gRPC Definitions Source: https://github.com/fal-ai/fal/blob/main/projects/isolate_proto/README.md Run these commands in the 'projects/isolate_proto' directory to regenerate gRPC definitions. Ensure you have the development dependencies installed and provide a valid isolate version tag. ```bash $ cd projects/isolate_proto $ pip install -e '.[dev]' $ python ../../tools/regen_grpc.py --isolate-version $ pre-commit run --all-files ``` -------------------------------- ### Regenerate gRPC Code Source: https://github.com/fal-ai/fal/blob/main/projects/isolate_proto/AGENTS.md Workflow to regenerate gRPC code from proto definitions within the projects/isolate_proto directory. Ensure development dependencies are installed and run pre-commit hooks and tests afterward. ```bash pip install -e '.[dev]' python ../../tools/regen_grpc.py --isolate-version pre-commit run --all-files pytest tests ``` -------------------------------- ### Build Documentation Source: https://github.com/fal-ai/fal/blob/main/AGENTS.md Builds both SDK and client documentation from the repository root. This command delegates to project-level documentation builds and assembles the output. ```bash make docs ``` -------------------------------- ### Create a Basic Client Source: https://github.com/fal-ai/fal/blob/main/projects/fal/openapi-fal-rest/README.md Instantiate the client for making API requests to a specified base URL. ```python from openapi_fal_rest import Client client = Client(base_url="https://api.example.com") ``` -------------------------------- ### Run Local/Unit Tests Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/AGENTS.md Execute only the local and unit tests for the fal_client package. This is useful when cloud credentials are unavailable. Run this command from the repository root. ```bash pytest projects/fal_client/tests/unit ``` -------------------------------- ### Run All Repository Hooks with Pre-commit Source: https://github.com/fal-ai/fal/blob/main/projects/fal/README.md Execute all pre-commit hooks across the entire repository to ensure code quality and consistency before committing. ```bash pre-commit run --all-files ``` -------------------------------- ### Run Integration Tests for Fal Package Source: https://github.com/fal-ai/fal/blob/main/projects/fal/AGENTS.md Execute integration tests for the fal package, requiring FAL_KEY and FAL_HOST environment variables. ```bash FAL_KEY=... FAL_HOST=api.fal.dev FAL_RUN_HOST=run.fal.dev \ pytest -n auto -v projects/fal/tests/integration ``` -------------------------------- ### Create an Authenticated Client Source: https://github.com/fal-ai/fal/blob/main/projects/fal/openapi-fal-rest/README.md Instantiate the client for making authenticated API requests using a token. ```python from openapi_fal_rest import AuthenticatedClient client = AuthenticatedClient(base_url="https://api.example.com", token="SuperSecretToken") ``` -------------------------------- ### Run a Model Synchronously Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/README.md Use the client to run a model and print the resulting image URL. Ensure the API key is set. ```python import fal_client response = fal_client.run("fal-ai/fast-sdxl", arguments={"prompt": "a cute cat, realistic, orange"}) print(response["images"][0]["url"]) ``` -------------------------------- ### Run Fal App for Testing Source: https://github.com/fal-ai/fal/blob/main/README.md Execute your Fal application locally for testing purposes using the `fal run` command. This command allows you to quickly iterate on your code. ```bash fal run hello_world.py::MyApp ``` -------------------------------- ### Run End-to-End Tests for Fal Package Source: https://github.com/fal-ai/fal/blob/main/projects/fal/AGENTS.md Execute end-to-end tests for the fal package, requiring FAL_KEY and FAL_RUN_HOST environment variables, with gRPC host specified. ```bash FAL_KEY=... FAL_GRPC_HOST=api.fal.dev FAL_RUN_HOST=run.fal.dev \ pytest -n auto -v projects/fal/tests/e2e ``` -------------------------------- ### Authenticated Client with Custom SSL Certificate Source: https://github.com/fal-ai/fal/blob/main/projects/fal/openapi-fal-rest/README.md Instantiate an authenticated client using a custom certificate bundle for SSL verification. ```python client = AuthenticatedClient( base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl="/path/to/certificate_bundle.pem", ) ``` -------------------------------- ### Deploy Fal App to Production Source: https://github.com/fal-ai/fal/blob/main/README.md Deploy your Fal application to a persistent endpoint using the `fal deploy` command. This makes your application accessible in the cloud. ```bash fal deploy hello_world.py::MyApp ``` -------------------------------- ### Run Tests for fal_client package Source: https://github.com/fal-ai/fal/blob/main/AGENTS.md Executes tests for the 'fal_client' package using pytest. ```bash pytest projects/fal_client/tests ``` -------------------------------- ### Generate OpenAPI REST Client Source: https://github.com/fal-ai/fal/blob/main/AGENTS.md Generates the OpenAPI REST client for the 'fal' package. This command should be run from the 'projects/fal' directory using the provided configuration file and OpenAPI spec path. ```bash cd projects/fal openapi-python-client generate --config openapi_rest.config.yaml --path ``` -------------------------------- ### Set API Key Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/README.md Set your fal.ai API key as an environment variable. ```bash export FAL_KEY=your-api-key ``` -------------------------------- ### Authenticated Client with SSL Verification Disabled Source: https://github.com/fal-ai/fal/blob/main/projects/fal/openapi-fal-rest/README.md Instantiate an authenticated client with SSL verification disabled. This is a security risk and should be used with caution. ```python client = AuthenticatedClient( base_url="https://internal_api.example.com", token="SuperSecretToken", verify_ssl=False ) ``` -------------------------------- ### Upload File for Model Input Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/README.md Upload an audio file to fal.media and pass its URL to the model. This is suitable for larger files or when CDN usage is preferred. ```python 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"]) ``` -------------------------------- ### Run Unit Tests for Fal Package Source: https://github.com/fal-ai/fal/blob/main/projects/fal/AGENTS.md Execute unit tests for the fal package using pytest, leveraging parallel execution. ```bash pytest -n auto -v projects/fal/tests/unit ``` -------------------------------- ### Regenerate gRPC Bindings Source: https://github.com/fal-ai/fal/blob/main/AGENTS.md Regenerates gRPC bindings for the 'isolate_proto' package. This command should be run from the 'projects/isolate_proto' directory after changing .proto definitions. It requires the 'isolate-version' to be specified. ```bash pip install -e '.[dev]' python ../../tools/regen_grpc.py --isolate-version pre-commit run --all-files ``` -------------------------------- ### Run a Model Asynchronously Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/README.md Execute a model asynchronously and print the resulting image URL. This is useful for non-blocking operations. ```python 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()) ``` -------------------------------- ### Run Full Validation Workflow Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/AGENTS.md Execute the complete validation workflow, including pre-commit checks and all pytest tests. Run this command from the repository root. ```bash pre-commit run --all-files pytest projects/fal_client/tests ``` -------------------------------- ### Run Tests for isolate_proto package Source: https://github.com/fal-ai/fal/blob/main/AGENTS.md Executes tests for the 'isolate_proto' package using pytest. ```bash pytest projects/isolate_proto/tests ``` -------------------------------- ### Encode File as Data URL Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/README.md Encode a local audio file into a data URL for direct use with the client, avoiding CDN uploads. This can reduce latency for smaller files. ```python 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"]) ``` -------------------------------- ### Call an Endpoint (Synchronous) Source: https://github.com/fal-ai/fal/blob/main/projects/fal/openapi-fal-rest/README.md Make a synchronous API call to retrieve parsed data or detailed response information. ```python from openapi_fal_rest.models import MyDataModel from openapi_fal_rest.api.my_tag import get_my_data_model from openapi_fal_rest.types import Response my_data: MyDataModel = get_my_data_model.sync(client=client) # or if you need more info (e.g. status_code) response: Response[MyDataModel] = get_my_data_model.sync_detailed(client=client) ``` -------------------------------- ### Submit Request and Stream Updates Source: https://github.com/fal-ai/fal/blob/main/projects/fal_client/README.md Submit a request asynchronously and iterate through events to receive real-time status updates, logs, and the final result. This is ideal for long-running tasks. ```python 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()) ``` -------------------------------- ### Call an Endpoint (Asynchronous) Source: https://github.com/fal-ai/fal/blob/main/projects/fal/openapi-fal-rest/README.md Make an asynchronous API call to retrieve parsed data or detailed response information. ```python from openapi_fal_rest.models import MyDataModel from openapi_fal_rest.api.my_tag import get_my_data_model from openapi_fal_rest.types import Response my_data: MyDataModel = await get_my_data_model.asyncio(client=client) response: Response[MyDataModel] = await get_my_data_model.asyncio_detailed(client=client) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.