### Setup Flyte SDK
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/ml/ocr/README.md
Navigate to the example directory and install dependencies using uv.
```bash
cd examples/ml/ocr
uv sync
```
--------------------------------
### Install Example Requirements
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/n8n/README.md
Install the necessary Python package 'kubernetes' for the example.
```bash
uv pip install kubernetes
```
--------------------------------
### Setup Flyte SDK Development Environment
Source: https://github.com/flyteorg/flyte-sdk/blob/main/CONTRIBUTING.md
Installs the package in editable mode and builds a wheel for local development. Requires a Docker daemon.
```bash
uv sync
make dist
```
--------------------------------
### Quick Start: Count Hugging Face Dataset Reviews
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/huggingface/README.md
A quick start example demonstrating how to use the Hugging Face plugin to count reviews in a dataset from the Hugging Face Hub. It uses `from_hf` to reference the dataset as a task input default.
```python
import datasets
import flyte
from flyteplugins.huggingface.datasets import from_hf
env = flyte.TaskEnvironment(name="hf-example")
@env.task
async def count_reviews(
ds: datasets.Dataset = from_hf(
"stanfordnlp/imdb",
name="plain_text",
split="train",
),
) -> int:
return len(ds)
```
--------------------------------
### Run FastAPI WebSocket App Locally
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/apps/websocket/README_WEBSOCKET.md
Navigate to the examples directory and run the Python script to start the FastAPI application locally.
```bash
cd examples/apps
python fastapi_websocket.py
```
--------------------------------
### Deploy FastAPI App to Flyte
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/WEB_UI_README.md
Navigate to the example directory and run the Python script to build the Docker image, deploy the FastAPI app to Flyte, and get the endpoint URL.
```bash
cd examples/genai/handoff
python app.py
```
--------------------------------
### Select Example Query
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/static/index.html
Sets the input field's value to the selected example query when an example chip is clicked.
```javascript
function selectExample(query) {
document.getElementById('queryInput').value = query;
}
```
--------------------------------
### Quick Start: Process Data with AutoCoderAgent
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/codegen/README.md
Example demonstrating how to use AutoCoderAgent to process a CSV file, compute revenue, units, and row count, and return the results. Requires Flyte TaskEnvironment setup with necessary secrets and packages.
```python
import flyte
from flyte.io import File
from flyte.sandbox import sandbox_environment
from flyteplugins.codegen import AutoCoderAgent
agent = AutoCoderAgent(model="gpt-4.1", name="summarize-sales", resources=flyte.Resources(cpu=1, memory="1Gi"))
env = flyte.TaskEnvironment(
name="my-env",
secrets=[flyte.Secret(key="openai_key", as_env_var="OPENAI_API_KEY")],
image=flyte.Image.from_debian_base().with_pip_packages(
"flyteplugins-codegen",
),
depends_on=[sandbox_environment], # Required
)
@env.task
async def process_data(csv_file: File) -> tuple[float, int, int]:
result = await agent.generate.aio(
prompt="Read the CSV and compute total_revenue, total_units and row_count.",
samples={"sales": csv_file},
outputs={"total_revenue": float, "total_units": int, "row_count": int},
)
return await result.run.aio()
```
--------------------------------
### Display Example Queries
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/static/index.html
Populates the example chips container with clickable examples. Truncates long examples and adds an ellipsis.
```javascript
function displayExamples(examples) {
const container = document.getElementById('exampleChips');
container.innerHTML = examples.map((example, idx) =>
`
${example.substring(0, 60)}${example.length > 60 ? '...' : ''}
`
).join('');
}
```
--------------------------------
### Install All Dependencies
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/ml/image_classification/README.md
Installs all dependencies required for all components, suitable for local development.
```bash
uv pip install .[all]
```
--------------------------------
### Install Serving Dependencies
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/ml/image_classification/README.md
Installs only the necessary dependencies for serving the model.
```bash
uv pip install .[serving]
```
--------------------------------
### Install PyTorch Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/pytorch/README.md
Install the PyTorch plugin using pip. This command installs the pre-release version.
```bash
pip install --pre flyteplugins-pytorch
```
--------------------------------
### Complete Full Build Example
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/deploy_patterns/full_build/README.md
A comprehensive example demonstrating the full build deployment pattern, including task environment configuration, local dependency usage, and running with 'copy_style="none"'.
```python
import pathlib
import flyte
from dep import foo
# Configure task environment with source copying
env = flyte.TaskEnvironment(
name="full_build",
image=flyte.Image.from_debian_base().with_source_folder(
pathlib.Path(__file__).parent,
copy_contents_only=True
),
)
@env.task
def square(x) -> int:
return x ** foo() # Uses local dependency
@env.task
def main(n: int) -> list[int]:
return list(flyte.map(square, range(n)))
if __name__ == "__main__":
import flyte.git
# Initialize with correct root_dir for copy_contents_only=True
flyte.init_from_config(
flyte.git.config_from_root(),
root_dir=pathlib.Path(__file__).parent
)
# Run with full build (no fast deployment)
run = flyte.with_runcontext(
copy_style="none", # Disable fast deployment
version="v1.0" # Set explicit version
).run(main, n=10)
print(run.url)
```
--------------------------------
### Run Agent Handoff Example Script
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/README_AGENT_HANDOFF.md
Execute the agent handoff example script directly using Python or with uv for inline dependency management.
```bash
# Run the example
python agent_handoff.py
# Or use uv to run with inline dependencies
uv run agent_handoff.py
```
--------------------------------
### Install Dependencies with uv sync
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/uv_monorepo_guide/02_sibling_packages/README.md
Installs all project dependencies, including sibling packages as editable installs, for local development.
```bash
cd 02_sibling_packages
uv sync
```
--------------------------------
### Run Flyte Workflow with Python Project Setup
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/deploy_patterns/package/README.md
Execute a Flyte workflow after installing the project in editable mode. The `--root-dir` flag is still recommended for remote deployments to ensure consistency.
```bash
pip install -e .
```
```bash
flyte run lib/workflows/workflow1.py process_workflow
```
```bash
flyte run --root-dir . lib/workflows/workflow1.py process_workflow
```
```bash
flyte deploy --root-dir . lib/workflows/workflow1.py
```
--------------------------------
### Run Flyte Example on Cluster
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/retries_timeout/README.md
Run a Flyte example on a cluster using the provided command. Ensure the actions service is enabled for proper execution.
```bash
_U_USE_ACTIONS=1 flyte run examples/retries_timeout/.py []
```
--------------------------------
### Install Flyte OpenAI Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/openai/README.md
Use this command to install the plugin. It is recommended to use the pre-release version.
```bash
pip install --pre flyteplugins-openai
```
--------------------------------
### Install Training Dependencies
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/ml/image_classification/README.md
Installs only the necessary dependencies for model training.
```bash
uv pip install .[training]
```
--------------------------------
### Run Pandas Schema Example
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/plugins/pandera/README.md
Execute the pandas_schema.py script locally or remotely. Ensure dependencies are installed and run from the repository root.
```bash
python examples/plugins/pandera/pandas_schema.py
```
```bash
python examples/plugins/pandera/pandas_schema.py --mode local
```
--------------------------------
### Run the Agent Handoff Example
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/README.md
Executes the main agent handoff script using Python or `uv`. Ensure dependencies are synced.
```bash
# Using Python
python agent_handoff.py
```
```bash
# Or using uv
uv run agent_handoff.py
```
--------------------------------
### Install Flyte Code Generation Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/codegen/README.md
Install the core plugin using pip. For Agent mode (Claude-only), install with the 'agent' extra.
```bash
pip install flyteplugins-codegen
# For Agent mode (Claude-only)
pip install flyteplugins-codegen[agent]
```
--------------------------------
### Run Retry and Timeout Example Locally
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/retries_timeout/README.md
Execute the retry_and_timeout.py example locally with flyte.init() to observe backoff delays between retries and all timeout bounds.
```bash
python examples/retries_timeout/retry_and_timeout.py
```
--------------------------------
### Install Echo Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/echo/README.md
Install the flyteplugins-echo package using pip.
```bash
pip install flyteplugins-echo
```
--------------------------------
### Install Flyte Ray Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/ray/README.md
Install the Flyte Ray plugin using pip. This command installs the pre-release version.
```bash
pip install --pre flyteplugins-ray
```
--------------------------------
### Quick Start: Basic Agent Execution
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/agents/flyte_agent/README.md
Run a basic agent from the command line with a message. Ensure API keys are exported.
```bash
export ANTHROPIC_API_KEY=sk-...
uv run python examples/agents/flyte_agent/basic_agent.py \
"What is 17 * 23 plus the temperature in NYC?"
```
--------------------------------
### Install JSONL Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/jsonl/README.md
Install the JSONL plugin for Flyte. Include the `[arrow]` extra for Arrow RecordBatch support.
```bash
pip install flyteplugins-jsonl
# For Arrow RecordBatch support
pip install 'flyteplugins-jsonl[arrow]'
```
--------------------------------
### Install BigQuery Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/bigquery/README.md
Install the BigQuery plugin using pip. This is the first step to enable BigQuery integration.
```bash
pip install flyteplugins-bigquery
```
--------------------------------
### Install Flyte Gemini Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/gemini/README.md
Install the plugin using pip. This command adds the necessary libraries to your Python environment.
```bash
pip install flyteplugins-gemini
```
--------------------------------
### Install Flyte Hydra Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/hydra/README.md
Install the plugin locally into the same environment as `flyte`.
```bash
pip install flyteplugins-hydra
```
--------------------------------
### Install vLLM Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/vllm/README.md
Install the vLLM plugin for Flyte using pip. This command installs the pre-release version.
```bash
pip install --pre flyteplugins-vllm
```
--------------------------------
### Run Backoff Example Locally
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/retries_timeout/README.md
Execute the backoff.py example locally to observe exponential backoff between user retries. This demonstrates inter-attempt gaps growing and capping.
```bash
python examples/retries_timeout/backoff.py
```
--------------------------------
### Install Hugging Face Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/huggingface/README.md
Install the Hugging Face plugin for Flyte using pip.
```bash
pip install flyteplugins-huggingface
```
--------------------------------
### Install flyteplugins-papermill
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/papermill/README.md
Install the papermill plugin using pip.
```bash
pip install flyteplugins-papermill
```
--------------------------------
### Install Dependencies with uv
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/README.md
Installs project dependencies using the `uv` package manager. Navigate to the project directory first.
```bash
cd examples/genai/handoff
uv sync
```
```bash
uv pip install -e .
```
--------------------------------
### Install Redis Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/redis/README.md
Install the flyteplugins-redis package using pip.
```bash
pip install flyteplugins-redis
```
--------------------------------
### Install Rust Controller
Source: https://github.com/flyteorg/flyte-sdk/blob/main/README.md
Install the Rust controller as an optional dependency for local development or custom task images.
```bash
pip install flyte[rust-controller]
```
--------------------------------
### Install Task Library Locally
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/published-library/README.md
Install the published task library locally using uv pip for development purposes. You can install the latest version or a specific version.
```bash
uv pip install my-task-library
```
```bash
uv pip install my-task-library==0.4.0
```
--------------------------------
### Start Flyte Devbox
Source: https://github.com/flyteorg/flyte-sdk/blob/main/README.md
Starts the Flyte Devbox, a Docker and k3s-based local development environment. This allows running Flyte workflows and services locally.
```bash
flyte start devbox
```
```bash
flyte create config \
--endpoint localhost:30080 \
--project flytesnacks \
--domain development \
--builder local \
--insecure
```
```bash
flyte run flyte_intro.py main --data '[1,2,3]'
```
--------------------------------
### Install Flyte SDK
Source: https://github.com/flyteorg/flyte-sdk/blob/main/README.md
Install the Flyte SDK using pip. This command is used to add the Flyte library to your Python environment.
```bash
pip install flyte
```
--------------------------------
### Install Flyte TUI for Local Development
Source: https://github.com/flyteorg/flyte-sdk/blob/main/README.md
Installs the TUI for a rich local development experience. Use this to run Flyte workflows locally.
```bash
pip install flyte[tui]
```
```bash
flyte run --tui --local flyte_intro.py main --data '[1,2,3]'
```
--------------------------------
### Install flyteplugins-omegaconf
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/omegaconf/README.md
Install the package to automatically register OmegaConf transformers with Flyte's TypeEngine.
```bash
pip install flyteplugins-omegaconf
```
--------------------------------
### Flyte HITL Workflow Example
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/hitl/README.md
An example demonstrating a Flyte workflow that integrates human-in-the-loop tasks. It shows how to define tasks, create events for human input, and combine automated and human-provided data.
```python
import flyte
import flyteplugins.hitl as hitl
task_env = flyte.TaskEnvironment(
name="my-hitl-workflow",
image=flyte.Image.from_debian_base(python_version=(3, 12)),
resources=flyte.Resources(cpu=1, memory="512Mi"),
depends_on=[hitl.env],
)
@task_env.task
async def task1() -> int:
"""First task - returns an automated value."""
return 42
@task_env.task
async def task2(x: int, y: int) -> int:
"""Second task - combines automated and human input."""
return x + y
@task_env.task(report=True)
async def main() -> int:
"""
Main workflow that orchestrates automated and human-in-the-loop tasks.
Flow:
1. task1() runs and returns an automated value (x)
2. Create an Event (serves the app) and wait for human input (y)
3. task2(x, y) combines both values and returns the result
"""
print("Starting HITL workflow...")
# Step 1: Automated task
x = await task1()
print(f"task1 completed: x = {x}")
# Step 2: Human-in-the-loop using the Event-based API
# Create an event (this serves the app if not already running)
event = await hitl.new_event.aio(
"integer_input_event",
data_type=int,
scope="run",
prompt="What should I add to x?",
)
y = await event.wait.aio()
print(f"Event completed: y = {y}")
# Step 3: Combine results
result = await task2(x, y)
print(f"task2 completed: result = {result}")
return result
if __name__ == "__main__":
flyte.init_from_config()
run = flyte.run(main)
print(f"Run URL: {run.url}")
run.wait()
print(f"Result: {run.outputs()}")
```
--------------------------------
### Install Client Dependencies
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/nemotron_omni_voice/README.md
Installs the necessary Python packages for the voice client, including core dependencies, sound handling, and a Text-to-Speech (TTS) engine.
```bash
pip install sounddevice numpy httpx
pip install pyttsx3
```
--------------------------------
### Install Snowflake Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/snowflake/README.md
Install the Snowflake plugin using pip.
```bash
pip install flyteplugins-snowflake
```
--------------------------------
### Install Databricks Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/databricks/README.md
Install the Databricks plugin for Flyte using pip.
```bash
pip install flyteplugins-databricks
```
--------------------------------
### Full Flyte Snowflake Example
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/snowflake/README.md
A comprehensive example demonstrating Flyte integration with Snowflake, including task definition, batch inserts, data selection, and workflow execution.
```python
import pandas as pd
from flyteplugins.snowflake import Snowflake, SnowflakeConfig
import flyte
config = SnowflakeConfig(
user="KEVIN",
account="PWGJLTH-XKB21544",
database="FLYTE",
schema="PUBLIC",
warehouse="COMPUTE_WH",
)
insert_task = Snowflake(
name="insert_rows",
inputs={"id": list[int], "name": list[str], "age": list[int]},
plugin_config=config,
query_template="INSERT INTO FLYTE.PUBLIC.TEST (ID, NAME, AGE) VALUES (%(id)s, %(name)s, %(age)s)",
snowflake_private_key="snowflake",
batch=True,
)
select_task = Snowflake(
name="select_all",
output_dataframe_type=pd.DataFrame,
plugin_config=config,
query_template="SELECT * FROM FLYTE.PUBLIC.TEST",
snowflake_private_key="snowflake",
)
snowflake_env = flyte.TaskEnvironment.from_task("snowflake_env", insert_task, select_task)
env = flyte.TaskEnvironment(
name="example_env",
image=flyte.Image.from_debian_base().with_pip_packages("flyteplugins-snowflake"),
secrets=[flyte.Secret(key="snowflake", as_env_var="SNOWFLAKE_PRIVATE_KEY")],
depends_on=[snowflake_env],
)
@env.task
async def main(ids: list[int], names: list[str], ages: list[int]) -> float:
await insert_task(id=ids, name=names, age=ages)
df = await select_task()
return df["AGE"].mean().item()
if __name__ == "__main__":
flyte.init_from_config()
run = flyte.with_runcontext(mode="remote").run(
main, ids=[123, 456], names=["Kevin", "Alice"], ages=[30, 25],
)
print(run.url)
```
--------------------------------
### Run Multi-Queue Example
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/queues/README.md
Executes a Python script that submits tasks to multiple independent queues with different capacities simultaneously. This example highlights how to manage distinct task streams with varying concurrency requirements.
```bash
flyte run examples/queues/multi_queue.py main
```
--------------------------------
### Install Dependencies with uv
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/WEB_UI_README.md
Install project dependencies using the `uv` package manager. This command synchronizes the project's required packages.
```bash
# Install dependencies
uv sync
```
--------------------------------
### Install Flyte Anthropic Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/anthropic/README.md
Install the plugin using pip. This command is required before using the plugin's features.
```bash
pip install flyteplugins-anthropic
```
--------------------------------
### Install Dask Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/dask/README.md
Install the Dask plugin using pip. This command enables Flyte's native Dask execution capabilities.
```bash
pip install --pre flyteplugins-dask
```
--------------------------------
### Zsh Shell Completion with Wrapper
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/hydra/README.md
Install shell completion for `flyte` when run through a wrapper like `uv`.
```zsh
eval "$(_FLYTE_COMPLETE=zsh_source uv run flyte)"
```
--------------------------------
### Install OpenAI Package
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/README_AGENT_HANDOFF.md
Installs the OpenAI Python client library, required for using OpenAI's embedding and language models.
```bash
pip install openai>=1.0.0
```
--------------------------------
### Install Flyte HITL Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/hitl/README.md
Install the HITL plugin using pip. This is the first step to enable human-in-the-loop functionality in your Flyte workflows.
```bash
pip install flyteplugins-hitl
```
--------------------------------
### Get a Specific Run by Name
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/interactive/remote.ipynb
Retrieve a specific run object using its unique name. This example fetches the fourth-to-last run from the list.
```python
r = remote.Run.get(name=runs[-4])
```
--------------------------------
### Load Agents and Examples on Page Load
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/static/index.html
Fetches agent and example data from API endpoints when the page loads. Handles potential errors during data fetching and updates the UI accordingly.
```javascript
let agents = [];
let examples = [];
// Load agents and examples on page load
async function loadData() {
try {
// Load agents
const agentsResponse = await fetch('/api/agents');
agents = await agentsResponse.json();
displayAgents(agents);
// Load examples
const examplesResponse = await fetch('/api/examples');
examples = await examplesResponse.json();
displayExamples(examples);
} catch (error) {
console.error('Failed to load data:', error);
}
}
```
--------------------------------
### Install Plotly
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/highlevel_libraries/README.md
Install the Plotly library if you intend to use its visualization capabilities for generating interactive reports. This step is optional if visualizations are not required.
```bash
pip install plotly
```
--------------------------------
### Install Library in Task Environment
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/published-library/README.md
Ensure the published library is installed within the Flyte task's container image. Use `with_pip_packages()` to specify the library name, and optionally a specific version for consistency.
```python
library_environment = flyte.TaskEnvironment(
name="my-task-library-env",
image=flyte.Image.from_debian_base().with_pip_packages("my-task-library"),
)
```
```python
.with_pip_packages("my-task-library==1.0.0")
```
--------------------------------
### Directly Use Storage API with Redis
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/redis/README.md
Utilize the Flyte storage API to put and get streams of data directly to/from Redis. This example demonstrates writing a byte string and then reading it back.
```python
import flyte.storage as storage
await storage.put_stream(b"hello", to_path="redis://localhost:6379/scratch/greeting")
data = b"".join([c async for c in storage.get_stream("redis://localhost:6379/scratch/greeting")])
```
--------------------------------
### Add Ruff for Code Formatting and Linting
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/README.md
Installs `ruff` for code formatting and linting using `uv`, then formats and checks the code.
```bash
# Add ruff for linting
uv add --dev ruff
# Format code
uv run ruff format .
# Check for issues
uv run ruff check .
```
--------------------------------
### Flyte CLI Commands
Source: https://github.com/flyteorg/flyte-sdk/blob/main/FEATURES.md
Common Flyte CLI commands for running tasks, serving apps, deploying environments, building images, getting logs, and aborting runs. Ensure the Flyte CLI is installed and configured.
```bash
flyte run hello.py main --numbers '[1,2,3]' # Run a task
```
```bash
flyte serve serving.py env # Serve an app
```
```bash
flyte deploy my_workflow.py # Deploy environments
```
```bash
flyte build my_workflow.py --push # Build and push images
```
```bash
flyte get logs # Get logs for a run
```
```bash
flyte abort run # Abort a run
```
--------------------------------
### Flyte Run and Deploy with Code Bundle
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/uv_monorepo_guide/GUIDE.md
Demonstrates how to run a task directly in development using the code bundle for source delivery, and how to deploy to production with the source baked into the image using `copy_style="none"`.
```python
# Development -- run a task directly, code bundle handles source delivery
flyte.run(my_task)
# Production -- deploy an environment with source baked into the image
flyte.deploy(my_env, copy_style="none", version="1.2.3")
```
--------------------------------
### Define Task Environment Image in Shared Src
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/uv_monorepo_guide/GUIDE.md
Define a task environment image in a shared `src/` directory within a monorepo. This example shows how to specify a `pyproject.toml` file and use `extra_args` to install specific dependency groups, resulting in a unique image hash.
```python
# src/my_app/tasks/etl_tasks.py
PROJECT_ROOT = Path(__file__).parent.parent.parent.parent # -> project_root/
etl_env = flyte.TaskEnvironment(
name="etl",
image=flyte.Image.from_debian_base()
.with_uv_project(
pyproject_file=PROJECT_ROOT / "pyproject.toml",
extra_args="--only-group etl",
)
.with_code_bundle(),
)
```
--------------------------------
### Install Polars Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/polars/README.md
Install the Polars plugin using pip. This command installs the pre-release version.
```bash
pip install --pre flyteplugins-polars
```
--------------------------------
### Serve UI from Static HTML
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/WEB_UI_README.md
Verify that the `static/index.html` file exists and is being served correctly by the web server. This is a basic check for UI loading issues.
```bash
curl https://your-app.example.com/
```
--------------------------------
### Initialize Flyte from Configuration
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/interactive/remote.ipynb
Initialize the Flyte SDK using the default configuration. This step is crucial before interacting with any remote Flyte resources.
```python
flyte.init_from_config()
```
--------------------------------
### Install Flyte SGLang Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/sglang/README.md
Install the SGLang plugin for Flyte using pip. This command installs the pre-release version.
```bash
pip install --pre flyteplugins-sglang
```
--------------------------------
### Initialize Flyte from Configuration
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/uv_monorepo_guide/GUIDE.md
Initializes the Flyte SDK from configuration, specifying the root directory for the application code. This setup ensures that 'my_lib' is baked into the image, while 'my_app' is handled separately.
```python
flyte.init_from_config(root_dir=SRC_DIR)
# root_dir covers only my_app; my_lib is baked into the image
```
--------------------------------
### Initialize Flyte SDK
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/interactive/interactive.ipynb
Import the Flyte library. This is the first step before using any Flyte functionalities.
```python
import flyte
```
--------------------------------
### Build and Deploy Agent Handoff to Production
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/README.md
Builds the Docker image, pushes it to a registry, and deploys the agent handoff system to a production Flyte cluster.
```bash
# Build and push image
flyte build agent_handoff.py --push
# Deploy to Flyte cluster
flyte deploy agent_handoff.py --domain production
```
--------------------------------
### Install Flyte Pandera Plugin for Pandas
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/pandera/README.md
Install the Flyte Pandera plugin with pandas support. Ensure pandera is installed with the pandas extra.
```bash
pip install flyteplugins-pandera 'pandera[pandas]'
```
--------------------------------
### Install Locked Dependencies with `with_uv_project`
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/project_structures/README.md
Use `with_uv_project` to install exact dependencies from `uv.lock` for reproducible builds. `--no-install-project` prevents installing the current project itself.
```python
image = flyte.Image.from_debian_base().with_uv_project(
pyproject_file=pathlib.Path(__file__).parent / "pyproject.toml",
)
```
--------------------------------
### Configure Flyte for Production Build
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/uv_monorepo_guide/02_sibling_packages/README.md
Shows how to switch from development to production mode by uncommenting `flyte.deploy(...)` and commenting out `flyte.run(...)` in the main script.
```python
# flyte.deploy(...)
flyte.run(...)
```
--------------------------------
### ListConfig Payload Example
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/omegaconf/README.md
Example of a msgpack-encoded list payload for ListConfig.
```json
[0.001, 0.01, 0.1]
```
--------------------------------
### Basic Flyte Handoff Workflow Execution
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/genai/handoff/README_AGENT_HANDOFF.md
Initialize Flyte and run the handoff workflow with a user query and a similarity threshold. Prints the run URL and waits for completion.
```python
import flyte
# Initialize Flyte
flyte.init_from_config()
# Run the handoff workflow
run = flyte.run(
run_handoff,
query="I need help analyzing sales data and creating visualizations",
threshold=0.6
)
print(f"Run URL: {run.url}")
run.wait()
```
--------------------------------
### Configure Task Environment with UV Project
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/uv_monorepo_guide/GUIDE.md
Sets up a Flyte task environment, baking a UV project and a source folder into the Docker image. The source folder is copied to /root/my_lib/ for runtime access.
```python
env = flyte.TaskEnvironment(
name="my_app",
image=flyte.Image.from_debian_base()
.with_uv_project(pyproject_file=MY_APP_ROOT / "pyproject.toml")
.with_source_folder(MY_LIB_PKG) # bakes my_lib into /root/my_lib/ in the image
.with_code_bundle(),
)
```
--------------------------------
### ListConfig as Task Inputs and Outputs
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/omegaconf/README.md
Shows how to use ListConfig for task inputs and outputs, such as generating a learning rate schedule.
```python
from omegaconf import ListConfig, OmegaConf
@env.task
async def build_lr_schedule(base_lr: float, num_stages: int) -> ListConfig:
return OmegaConf.create([base_lr * (0.5 ** i) for i in range(num_stages)])
@env.task
async def train_with_schedule(cfg: DictConfig, lr_schedule: ListConfig) -> float:
final_lr = float(lr_schedule[-1])
...
```
--------------------------------
### Install Batch Inference Dependencies
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/ml/image_classification/README.md
Installs only the necessary dependencies for batch inference.
```bash
uv pip install .[batch]
```
--------------------------------
### DictConfig Payload Example
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/omegaconf/README.md
Example of a msgpack-encoded dictionary payload for DictConfig, including base_dataclass and values.
```json
{
"base_dataclass": "mymodule.TrainConf",
"values": { "optimizer": { "lr": 0.001 }, "training": { "epochs": 10 } }
}
```
--------------------------------
### Production Deployment (Full Build)
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/project_structures/README.md
Sets up a Flyte task environment for production deployments. It uses `with_uv_project` with `project_install_mode='install_project'` to ensure all code is baked into the Docker image, creating an immutable artifact.
```python
import flyte
import pathlib
env = flyte.TaskEnvironment(
name="full_build",
image=(
flyte.Image.from_debian_base()
.with_uv_project(pyproject_file=pathlib.Path("my_plugin/pyproject.toml"), project_install_mode="install_project")
),
)
@env.task
def task_function() -> list[int]:
...
flyte.with_runcontext(copy_style="none", version="v1.0").run(task_function)
```
--------------------------------
### Override Value Completion Example 3
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/hydra/README.md
Example of shell completion for Hydra override values, suggesting options for `hydra/launcher`.
```bash
flyte hydra run --config-path conf --config-name training \
train.py pipeline --hydra-override hydra/launcher=
```
--------------------------------
### Override Value Completion Example 1
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/hydra/README.md
Example of shell completion for Hydra override values, suggesting keys under `optimizer`.
```bash
flyte hydra run --config-path conf --config-name training \
train.py pipeline --cfg optimizer.
# suggests optimizer.lr=, optimizer.weight_decay=, ...
```
--------------------------------
### Install Spark Plugin
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/spark/README.md
Install the Union Spark Plugin using pip. This command should be run in your environment to enable Spark capabilities.
```bash
pip install --pre flyteplugins-spark
```
--------------------------------
### Initialize Flyte with Src-Layout
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/uv_monorepo_guide/GUIDE.md
When using a src-layout project structure, set `root_dir` to the `src/` directory to ensure correct import paths. This is anchored using `Path(__file__).parent.parent`.
```python
flyte.init_from_config(
root_dir=Path(__file__).parent.parent, # -> src/
)
```
--------------------------------
### DictConfig as Task Inputs and Outputs
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/omegaconf/README.md
Demonstrates using DictConfig for task inputs and outputs, including merging configurations.
```python
import flyte
from omegaconf import DictConfig, OmegaConf
env = flyte.TaskEnvironment(name="training", image=...)
@env.task
async def preprocess(cfg: DictConfig) -> DictConfig:
return OmegaConf.merge(cfg, {"data": {"normalized": True}})
@env.task
async def train(cfg: DictConfig) -> float:
return run_experiment(cfg.optimizer.lr, cfg.training.epochs)
@env.task
async def pipeline() -> float:
cfg = OmegaConf.create({"optimizer": {"lr": 0.001}, "training": {"epochs": 10}})
processed = await preprocess(cfg)
return await train(processed)
```
--------------------------------
### Initialize Flyte with Flat Layout
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/uv_monorepo_guide/GUIDE.md
For a flat project layout, set `root_dir` to the project's root directory, which is typically the parent directory of the current file.
```python
flyte.init_from_config(root_dir=Path(__file__).parent) # -> my_project/
```
--------------------------------
### Override Value Completion Example 2
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/hydra/README.md
Example of shell completion for Hydra override values, suggesting config group options for `task_env`.
```bash
flyte hydra run --config-path conf --config-name training \
train.py pipeline --cfg +task_env=
# suggests task_env config group options
```
--------------------------------
### Development Deployment (Fast Iteration)
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/project_structures/README.md
Configures a Flyte task environment for fast iteration during development. It uses `with_uv_project` to specify the `pyproject.toml` file, enabling rapid code deployment without full Docker image rebuilds.
```python
import flyte
import pathlib
env = flyte.TaskEnvironment(
name="fast_iteration",
image=(
flyte.Image.from_debian_base()
.with_uv_project(pyproject_file=pathlib.Path("my_plugin/pyproject.toml"))
),
)
@env.task
def task_function() -> list[int]:
...
flyte.run(task_function)
```
--------------------------------
### Classify Example Image
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/ml/image_classification/index.html
Allows classification of a pre-defined example image by fetching its URL, converting it to a File object, and then calling the `classifyImage` function.
```javascript
async function classifyExample() {
const exampleImage = document.getElementById('exampleImage');
// Show preview
previewImage.src = exampleImage.src;
previewSection.style.display = 'block';
// Convert image URL to blob
try {
const response = await fetch(exampleImage.src);
const blob = await response.blob();
const file = new File([blob], 'example.jpg', { type: 'image/jpeg' });
await classifyImage(file);
} catch (err) {
showError('Failed to load example image: ' + err.message);
}
}
```
--------------------------------
### Deploy Flyte Project with CLI
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/deploy_patterns/dynamic_environments/README.md
Deploy a Flyte project using the `flyte deploy` command. This command also handles Flyte initialization.
```bash
flyte deploy environment_picker.py
```
--------------------------------
### Defining a Flyte Agent with Tools and Skills
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/agents/flyte_agent/README.md
Illustrates the basic structure for defining an agent, including tasks as tools, skills for context, and setting max turns.
```python
import flyte
from flyte.ai.agents import Agent
env = flyte.TaskEnvironment(name="my-agent", image="auto")
@env.task
async def list_open_tickets() -> list[dict]:
"""Pull open tickets from your tracker."""
...
@flyte.trace
async def summarize(items: list[dict]) -> str:
"""LLM-light summarization helper."""
...
agent = Agent(
name="ticket-shepherd",
instructions="You triage support tickets and post a daily digest.",
tools=[list_open_tickets, summarize],
skills=["TICKETING_HANDBOOK.md"], # adds context to the system prompt
max_turns=20,
)
@env.task(triggers=flyte.Trigger.daily())
async def daily_run() -> str:
result = await agent.run.aio("Post the digest to #support.")
return result.summary or result.error
```
--------------------------------
### Initialize Flyte SDK
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/apps/notebook_app.ipynb
Initializes the Flyte SDK with a specific log level. This is typically the first step in any Flyte application.
```python
import logging
import flyte
flyte.init_config(log_level=logging.DEBUG)
```
--------------------------------
### Passing Wandb Configuration with wandb_config
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/wandb/README.md
Demonstrates how to use `wandb_config()` to pass W&B project, entity, and tags. This configuration propagates to child tasks, allowing for centralized experiment setup.
```python
from flyteplugins.wandb import wandb_config
# With flyte.with_runcontext
run = flyte.with_runcontext(
custom_context=wandb_config(
project="my-project",
entity="my-team",
tags=["experiment-1"],
)
).run(my_task)
# As a context manager
with wandb_config(project="override-project"):
await child_task()
```
--------------------------------
### WandB Sweep Initialization
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/wandb/README.md
Demonstrates how to initialize a W&B sweep using the `@wandb_sweep` decorator and launch agents to run trials.
```APIDOC
## @wandb_sweep Decorator
### Description
Used to create a Weights & Biases sweep for a task.
### Usage
```python
from flyteplugins.wandb import wandb_sweep
@wandb_sweep
@env.task
def run_sweep():
# Task logic to run the sweep
pass
```
## @wandb_init Decorator
### Description
Initializes Weights & Biases for a task or function.
### Parameters
- `run_mode` (string): Controls how the W&B run is initialized. Options: "auto" (default), "new", or "shared".
- `rank_scope` (string): Controls which ranks log in distributed training. Options: "global" (default) or "worker".
- `download_logs` (boolean): If `True`, download W&B logs after task completion.
- `project` (string): The W&B project name.
- `entity` (string): The W&B entity name.
### Usage
```python
from flyteplugins.wandb import wandb_init
@wandb_init(download_logs=True, project="my-project", entity="my-entity")
@env.task
def train():
# Training logic
pass
```
```
--------------------------------
### Initialize Primitive Variables
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/papermill/examples/notebooks/primitive_types.ipynb
Sets up initial values for boolean flags, lists, and dictionaries that will be passed as notebook inputs.
```python
enabled = True
values = []
options = {}
```
--------------------------------
### Install Flyte Pandera Plugin for Polars
Source: https://github.com/flyteorg/flyte-sdk/blob/main/plugins/pandera/README.md
Install the Flyte Pandera plugin with Polars support. Requires the flyteplugins-polars package and pandera with the polars extra.
```bash
pip install flyteplugins-pandera 'pandera[polars]' flyteplugins-polars
```
--------------------------------
### Run Application with uv
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/uv_monorepo_guide/01_workspace_monorepo/README.md
Executes the main application script using `uv run`. This is suitable for development or fast deployments.
```bash
uv run python src/workspace_app/main.py
```
--------------------------------
### Build and Push Docker Images
Source: https://github.com/flyteorg/flyte-sdk/blob/main/examples/byoi_guide/GUIDE.md
These bash commands demonstrate how to build and push Docker images for the data preparation and training tasks using the respective Dockerfiles. This is part of the Pure BYOI pattern where images are built locally.
```bash
# From v2_guide/pure_byoi/
docker build -f data_prep/Dockerfile -t /data-prep:latest .
docker build -f training/Dockerfile -t /training:latest .
docker push /data-prep:latest
docker push /training:latest
```