functions
latest
false
函数用户指南
- 概述
- Python 函数
- 部署并运行
本页面将引导您安装 SDK、搭建项目以及在本地运行第一个 Python 函数。
先决条件
- Python 3.10 或更高版本。
- 使用
pip安装的uipathCLI 和 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 命令中使用的入口点名称;该值引用文件和函数。仅在重命名函数或添加更多入口点时更新它。
生成项目架构
定义 Input 和 Output 后,生成架构和绑定:
uipath init
uipath init
这将读取您的代码和 uipath.json 并生成:
| 文件 | 用途 |
|---|---|
entry-points.json | 派生自您模型的输入/输出 JSON 架构,用于变量绑定。 |
bindings.json | Resource 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.
后续步骤
- 构建 Python 函数— 类型化架构、错误处理和多入口点。
- Resource bindings — declare the platform resources your function reaches.
- 打包并发布— 部署到 Orchestrator。