UiPath Documentation
functions
latest
false
函数用户指南
  • 概述
    • 关于函数
  • Python 函数
    • 入门指南
    • 构建 Python 函数
    • 访问平台服务
    • 资源绑定
    • 声明资源绑定
    • 调用 Integration Service 活动
    • 追踪和可观察性
    • 测试和调试
  • 部署并运行

入门指南

本页面将引导您安装 SDK、搭建项目以及在本地运行第一个 Python 函数。

先决条件

  • Python 3.10 或更高版本。
  • 使用pip安装的uipath CLI 和 SDK
  • 有权访问 Orchestrator 的 UiPath 帐户(用于发布和调用)。

安装 SDK

pip install uipath
pip install uipath

验证安装:

uipath --version
uipath --version

构建项目

新建函数项目:

uipath new my-function
uipath new my-function

这将构建您编辑的文件:

文件用途
main.py您的函数逻辑和 Input/Output 模型。作为可运行的示例启动。
pyproject.toml项目元数据和依赖项。
uipath.json声明可调用的入口点。框架为您注册 main

编写您的第一个函数

替换 main.py 中的框架逻辑:

from pydantic.dataclasses import dataclass


@dataclass
class Input:
    message: str = ""


@dataclass
class Output:
    reply: str = ""


def main(input: Input) -> Output:
    return Output(reply=f"Hello, {input.message}!")
from pydantic.dataclasses import dataclass


@dataclass
class Input:
    message: str = ""


@dataclass
class Output:
    reply: str = ""


def main(input: Input) -> Output:
    return Output(reply=f"Hello, {input.message}!")

框架式的 uipath.json 已经声明了此入口点:

{
  "functions": {
    "main": "main.py:main"
  }
}
{
  "functions": {
    "main": "main.py:main"
  }
}

键 (main) 是 CLI 命令中使用的入口点名称;该值引用文件和函数。仅在重命名函数或添加更多入口点时更新它。

生成项目架构

定义 InputOutput 后,生成架构和绑定:

uipath init
uipath init

这将读取您的代码和 uipath.json 并生成:

文件用途
entry-points.json派生自您模型的输入/输出 JSON 架构,用于变量绑定。
bindings.jsonResource binding manifest, created with an empty structure only when the file does not already exist.

Re-run uipath init whenever you change your Input or Output models. It regenerates entry-points.json and never modifies bindings.json — resource bindings are maintained by hand. For what they do and how to declare them, see Resource bindings.

在本地运行

uipath run main '{"message": "world"}'
uipath run main '{"message": "world"}'

Local runs resolve platform resources through the entries in bindings.json, so you can test against real Orchestrator assets and buckets before publishing. The same entries are what let each resource be remapped when the package runs in another tenant.

后续步骤

此页面有帮助吗?

连接

需要帮助? 支持

想要了解详细内容? UiPath Academy

有问题? UiPath 论坛

保持更新