---
title: FlyteRemote OSS Sync
tags: oss-sync
description: View the slide with "Slide Mode".
slideOptions:
theme: white
fragments: true
spotlight:
enabled: false
---
<style>
p {
text-align: left;
}
.reveal {
font-size: 30px;
}
.reveal pre code {
font-size: 0.9em;
line-height: 1.4em;
padding: 20px;
}
table {
font-size: 0.8em !important;
}
</style>
# FlyteRemote
### Interacting with a Flyte Backend Made Easy
<img src='https://docs.flyte.org/en/latest/_static/flyte_circle_gradient_1_4x4.png' width="150px" style="border: none; box-shadow: none;"/>
---
hackmd.io/@nielsbantilan/flyte-remote-oss
---
## 📝 Outline
- Motivation
- Before and After
- Design
- Demo
- Potential Next Steps
---
## Motivation
As a **workflow author**, I want to *fetch*, *register*, *execute*, and *inspect* Flyte entities in an interactive environment so that I can improve my ability to debug tasks, workflows, and launchplans.
---
## Interacting with a Flyte Backend
1. **CLIs**: ✨`flytectl`✨, `pyflyte`, `flyte-cli`
2. **Python SDK**: `flytekit`
---
## Use Case
"I want to fetch and execute a workflow, then inspect execution outputs after it's complete."
---
### Before
```python
from flytekit.common.workflow import SdkWorkflow
from flytekit.models.literals import LiteralMap, Literal
# fetch workflow, assuming that the underlying config/environment vars are all set correctly
workflow = SdkWorkflow.fetch("project", "domain", "my_workflow", "version")
# convert workflow into a launch plan
launch_plan = workflow.create_launch_plan()
# launch the execution with flyte literals
execution = launch_plan.launch_with_literals(
"project", "domain", literal_inputs=LiteralMap({"input": Literal("foo")})
)
# print outputs after completion
execution.wait_for_completion()
print(execution.outputs)
```
---
### After
```python
from flytekit.remote import FlyteRemote
# initialize a remote object with config/environment vars
remote = FlyteRemote.from_config(default_project="project", default_domain="domain")
# gets latest version of the workflow in the default project and domain
workflow = remote.fetch(name="my_workflow")
# execute workflow directly, synchronously waiting for completion
execution = remote.execute(workflow, inputs={"input": "foo"}, wait=True)
# print outputs after completion
print(execution.outputs)
```
---
## Design
**Goal**: Make the interaction with a Flyte backend more streamlined
---
### `Sdk*` classes
Each flyte entity class implements its own methods that make network calls, where each class has some overlapping and some distinct behavior.
```python
workflow = SdkWorkflow.fetch(...)
workflow.register(...)
workflow.serialize(...)
workflow.create_launch_plan(...)
task = SdkTask.fetch(...)
task.register(...)
task.register_and_launch(...)
task.launch_with_literals(...)
# etc.
```
---
### `Flyte*` classes
`FlyteRemote` implements network operations with a common interface across all relevant local or remote flyte entities.
```python
remote = FlyteRemote(...)
remote.fetch_{task, workflow, launch_plan} # fetch an entity from the remote
remote.register(...) # register a local flyte task/workflow/launchplan
remote.execute(...) # execute a local or remote flyte entity
remote.sync(...) # sync the state of an execution
remote.wait(...) # wait for an execution to complete
```
---
`Flyte*` classes take advantage of `@singledispatchmethod` to specify different implementations of the same operation across a set of relevant flyte entities
```python
remote.execute(remote.fetch_task(...))
remote.execute(remote.fetch_workflow(...))
remote.execute(remote.fetch_launch_plan(...))
```
---
`Flyte*` execution classes expose properties that facilitate inspection
```python
workflow: FlyteWorkflow = remote.fetch_workflow(...)
execution: FlyteWorkflowExecution = remote.execute(workflow)
print(workflow.interface)
print(execution.inputs)
print(execution.outputs)
```
---
## Demo
---
## Summary
`FlyteRemote` provides a centralized API for interacting with a remote backend.
| `FlyteRemote` | `fetch` | `register` | `execute` | `sync` | `wait` |
| --- | --- | --- | --- | --- | --- |
| `FlyteTask` | ✅ | 🤔 | ✅ | - | - |
| `FlyteWorkflow` | ✅ | 🤔 | ✅ | - | - |
| `FlyteLaunchPlan` | ✅ | 🤔 | ✅ | - | - |
| `PythonTask` | - | 🔘 | 🔘 | - | - |
| `WorkflowBase` | - | ❌ | 🔘 | - | - |
| `LaunchPlan` | - | ❌ | 🔘 | - | - |
| `FlyteTaskExecution` | 🤔 | - | ✅ | ✅ | ✅ |
| `FlyteWorkflowExecution` | 🤔 | - | ✅ | ✅ | ✅ |
</br>
🔘 partial/limited support
---
## Potential Next Steps
- support (fast) registration of local tasks/workflows → execute local tasks/workflows
- support re-registration of remote flyte entities under different project/domain
- ... other ideas?