# UnionRemote

The `UnionRemote` Python API supports functionality similar to that of the Union CLI, enabling you to manage Union.ai workflows, tasks, launch plans and artifacts from within your Python code.

> [!NOTE]
> The primary use case of `UnionRemote` is to automate the deployment of Union.ai entities. As such, it is intended for use within scripts *external* to actual Union.ai workflow and task code, for example CI/CD pipeline scripts.
>
> In other words: _Do not use `UnionRemote` within task code._

## Creating a `UnionRemote` object

Ensure that you have the Union SDK installed, import the `UnionRemote` class and create the object like this:

```python
import union

remote = union.UnionRemote()
```

By default, when created with a no-argument constructor, `UnionRemote` will use the prevailing configuration in the local environment to connect to Union.ai,
that is, the same configuration as would be used by the Union CLI in that environment
(see [Union CLI configuration search path](https://www.union.ai/docs/v1/union/api-reference/union-cli/page.md#-key-cli--cli-configuration-search-path)).

In the default case, as with the Union CLI, all operations will be applied to the default project, `flytesnacks` and default domain, `development`.

Alternatively, you can initialize `UnionRemote` by explicitly specifying a `flytekit.configuration.Config` object with connection information to a Union.ai instance, a project, and a domain. Additionall, the constructor supports specifying a file upload location (equivalent to a default raw data prefix):

```python
import union
from flytekit.configuration import Config

remote = union.UnionRemote(
    config=Config.for_endpoint(endpoint="union.example.com"),
    default_project="my-project",
    default_domain="my-domain",
    data_upload_location="<s3|gs|abs>://my-bucket/my-prefix",
)
```

Here we use the `Config.for_endpoint` method to specify the URL to connect to.
There are other ways to configure the `Config` object.
In general, you have all the same options as you would when specifying a connection for the Union CLI using a `config.yaml` file.

### Authenticating using a client secret

In some cases, you may be running a script with `UnionRemote` in a CI/CD pipeline or via SSH, where you don't have access to a browser for the default authentication flow. In such scenarios, you can use the [client secret](https://www.union.ai/docs/v1/union/user-guide/development-cycle/authentication/page.md#3-clientsecret-best-for-cicd-and-automation) authentication method to establish a connection to Union.ai. After [creating an API key](https://www.union.ai/docs/v1/union/user-guide/development-cycle/managing-api-keys/page.md), you can initialize `UnionRemote` as follows:

```python
import union
from flytekit.configuration import Config, PlatformConfig

remote = union.UnionRemote(
        config=Config(
            platform=PlatformConfig(
                endpoint="union.example.com",
                insecure=False,
                client_id="<your-client-id>",  # this is the api-key name
                client_credentials_secret="<your-client-secret>",  # this is the api-key
                auth_mode="client_credentials",
            )
        ),
    )
```

For details see [the API docs for `flytekit.configuration.Config`](https://www.union.ai/docs/v1/union/api-reference/flytekit-sdk/packages/flytekit.configuration/page.md#flytekitconfigurationconfig)

## Subpages

- [Remote examples](https://www.union.ai/docs/v1/union/user-guide/development-cycle/remote-management/remote-examples/page.md)
  - Registering and running a workflow
  - Fetching outputs
  - Terminating all running executions for a workflow
  - Rerunning all failed executions of a workflow
  - Filtering for executions using a `Filter`
  - Launch task via UnionRemote with a new version
  - Launch workflow via UnionRemote
  - Launch launchplan via UnionRemote
  - Inspecting executions

---
**Source**: https://github.com/unionai/unionai-docs/blob/main/content/user-guide/development-cycle/remote-management/_index.md
**HTML**: https://www.union.ai/docs/v1/union/user-guide/development-cycle/remote-management/
