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.
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:
import union
remote = union.UnionRemote()
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).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):
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 authentication method to establish a connection to Union.ai. After
creating an API key, you can initialize UnionRemote as follows:
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