Skip to main content

Classes

Audio

!!! abstract “Usage Documentation” Models A base class for creating Pydantic models.
Inherits from: File

Constructor Parameters

CompressedFile

!!! abstract “Usage Documentation” Models A base class for creating Pydantic models.
Inherits from: File

Constructor Parameters

Class Variables

Methods

glob

FalBaseModel

Base model for fal applications with field ordering, visibility control, and context binding for error reporting. Features:
  • FIELD_ORDERS: Control field order in JSON schema, useful for nested models.
  • Hidden(Field(…)): Mark fields as hidden from OpenAPI schema, useful for hidden params.
Example:
Inherits from: BaseModel

Constructor Parameters

Class Variables

File

!!! abstract “Usage Documentation” Models A base class for creating Pydantic models.
Inherits from: BaseModel

Constructor Parameters

Class Variables

Methods

as_bytes

Returns: bytes

from_bytes

Returns: File

from_path

Returns: File

save

Returns: Path

Image

Represents an image file.
Inherits from: File

Constructor Parameters

Class Variables

Methods

from_bytes

Returns: Image

from_pil

to_pil

KVStore

A key-value store client for interacting with the FAL KV service.

Constructor Parameters

Properties

Methods

get

Retrieve a value from the key-value store.Returns: Optional[str]

set

Store a value in the key-value store.Returns: NoneType

Video

!!! abstract “Usage Documentation” Models A base class for creating Pydantic models.
Inherits from: File

Constructor Parameters

FalTookitException

Base exception for all toolkit exceptions
Inherits from: Exception

Constructor Parameters

FileUploadException

Raised when file upload fails
Inherits from: FalTookitException

Constructor Parameters

KVStoreException

Raised when KV store operation fails
Inherits from: FalTookitException

Constructor Parameters

DownloadError

Common base class for all non-exit exceptions.
Inherits from: Exception

Constructor Parameters


Functions

Hidden

Wrapper that marks a Field as hidden in the UI. The field MUST have a default or default_factory set since hidden fields cannot be required inputs in the UI. Usage: class Input(FalBaseModel): prompt: str = Field(…) hidden_flag: bool = Hidden(Field(default=False)) Returns: _T Raises:
  • ValueError: If field has no default or default_factory

get_image_size

Returns: ImageSize

optimize

Optimize the given torch module with dynamic compilation and quantization techniques. Only applicable under fal’s cloud environment. Warning: This function is experimental and may not work as expected.

clone_repository

Clones a Git repository from the specified HTTPS URL into a local directory. This function clones a Git repository from the specified HTTPS URL into a local directory. It can also checkout a specific commit if the commit_hash is provided. If a custom target_dir or repo_name is not specified, a predefined directory is used for the target directory, and the repository name is determined from the URL. Returns: Path

download_file

Downloads a file from the specified URL to the target directory. The function downloads the file from the given URL and saves it in the specified target directory, provided it is below the given filesize limit. It also checks whether the local file already exists and whether its content length matches the expected content length from the remote file. If the local file already exists and its content length matches the expected content length from the remote file, the existing file is returned without re-downloading it. If the file needs to be downloaded or if an existing file’s content length does not match the expected length, the function proceeds to download and save the file. It ensures that the target directory exists and handles any errors that may occur during the download process, raising a DownloadError if necessary. Returns: Path Raises:
  • ValueError: If the provided file_name contains a forward slash (’/’).
  • DownloadError: If an error occurs during the download process.

download_model_weights

Downloads model weights from the specified URL and saves them to a predefined directory. This function is specifically designed for downloading model weights and stores them in a predefined directory. It calls the download_file function with the provided URL and the target directory set to a pre-defined location for model weights. The downloaded model weights are saved in this directory, and the function returns the full path to the downloaded weights file. Returns: Path

get_gpu_type

Detect the GPU type using nvidia-smi. Example:
Returns: str

load_inductor_cache

Load PyTorch Inductor compilation cache from global storage. This function:
  1. Sets TORCHINDUCTOR_CACHE_DIR environment variable
  2. Looks for cached compiled kernels in GPU-specific global storage
  3. Unpacks the cache to local temporary directory
  4. Returns a hash of the unpacked directory for change detection
Example:
Returns: str

sync_inductor_cache

Sync updated PyTorch Inductor cache back to global storage. This function:
  1. Checks if the local cache has changed (by comparing hashes)
  2. If changed, creates a zip archive of the new cache
  3. Saves it to GPU-specific global storage
Example:
Returns: NoneType

synchronized_inductor_cache

Context manager to automatically load and sync PyTorch Inductor cache. This wraps load_inductor_cache and sync_inductor_cache for convenience. The cache is loaded on entry and synced on exit (even if an exception occurs). Example:
Returns: Iterator[]