Quick start#

In this section, we give a quick introduction to writing and running Union workflows.

Sign up for Union Serverless#

First, sign up for Union Serverless:

Create an account

Once you’ve received confirmation that your sign up succeeded, navigate to the UI at serverless.union.ai. This is where you will be able to see your workflow executions and manage your projects:

Union UI

Set up your Python environment#

Set up a Python virtual environment with conda, venv or a similar tool.

Python 3.8 or higher is required. Python 3.11 is the current recommended version.

Install conda using Miniconda, then run the following to create a new Python environment:

$ conda create -n union-env python=3.11
$ conda activate union-env

Install Python 3.11 from your package manager or from Python.org, then run the following to create a virtual environment:

$ python -m venv .venv
$ source .venv/bin/activate

Install the union package#

After setting up your virtual environment and activating it, install the union Python package:

$ pip install -U union

Note

These directions are for Union Serverless.

If you are using Union BYOC, you should install union with the [byoc] extra package.

This will install:

Warning

If you have previously used Union, you may have configuration files left over that will interfere with access to Union Serverless through the union CLI tool. Make sure to remove any files in ~/.unionai/ or ~/.union/ and unset the environment variables UNIONAI_CONFIG and UNION_CONFIG to avoid conflicts.

Create a “Hello, world!” workflow#

To create an example workflow file, copy the following into a file called hello.py:

from flytekit import task, workflow

@task
def say_hello(name: str) -> str:
    return f"Hello, {name}!"

@workflow
def hello_world_wf(name: str = 'world') -> str:
    res = say_hello(name=name)
    return res

Tasks and workflows#

The “Hello, world!” code contains a task and a workflow, which are Python functions decorated with the @task and @workflow decorators, respectively. For more information, see the task and workflow documentation.

Run the workflow locally in Python#

You can run the workflow in your local Python environment with the union run command:

$ union run hello.py hello_world_wf

You should see the following output:

Running Execution on local.
Hello, world!

Since the @workflow function takes an argument called name, you can also pass that in as a command-line argument like this:

$ union run hello.py hello_world_wf --name Ada

You should see the following output:

Running Execution on local.
Hello, Ada!

Run the workflow remotely on Union#

To run the workflow remotely on Union, add the --remote flag:

$ union run --remote hello.py hello_world_wf --name "Ada"

The output displays a URL that links to the workflow execution in the UI:

[] Go to https://serverless.union.ai/org/... to see execution in the UI.

Go to the UI to see the execution:

Dashboard