# FlyteRemote

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

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

## Creating a `FlyteRemote` object

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

```python
import flytekit as fl
from flytekit.configuration import Config

remote = fl.FlyteRemote(config=Config.auto())
```

By default, when created with `config=Config.auto()`, `FlyteRemote` will use the prevailing configuration in the local environment to connect to Flyte,
that is, the same configuration as would be used by the Pyflyte CLI in that environment
(see [Pyflyte CLI configuration search path](https://www.union.ai/docs/v1/flyte/api-reference/pyflyte-cli/page.md#-key-cli--cli-configuration-search-path)).

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

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

```python
import flytekit as fl
from flytekit.configuration import Config

remote = fl.FlyteRemote(
    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 Pyflyte CLI using a `config.yaml` file.

### Authenticating using a client secret

In some cases, you may be running a script with `FlyteRemote` 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/flyte/user-guide/development-cycle/authentication#3-clientsecret-best-for-cicd-and-automation) authentication method to establish a connection to Flyte. After [creating an API key](https://www.union.ai/docs/v1/flyte/user-guide/development-cycle/managing-api-keys), you can initialize `FlyteRemote` as follows:

```python
import flytekit as fl
from flytekit.configuration import Config, PlatformConfig

remote = fl.FlyteRemote(
        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/flyte/api-reference/flytekit-sdk/flytekit.configuration/page.md#flytekitconfigurationconfig)

## Subpages

- [Remote examples](https://www.union.ai/docs/v1/flyte/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 FlyteRemote with a new version
  - Launch workflow via FlyteRemote
  - Launch launchplan via FlyteRemote
  - 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/flyte/user-guide/development-cycle/remote-management/
