发布到 PyPI
发布到 PyPI
将您面向公众的 Fern Python SDK 发布到 PyPI 注册表。按照本页面的步骤操作后,您将在 PyPI 上发布一个版本化的包。

本页面假设您已具备:
- 已初始化的
fern文件夹、Python SDK 的 GitHub 代码库,以及generators.yml中的 Python 生成器组。参见 生成 SDK (Python)。
配置 SDK 包设置
您需要更新 generators.yml 文件来配置包名称、输出位置和客户端命名以用于 PyPI 发布。您的 generators.yml 应位于您的源代码库中(或本地机器上),而不是包含 Python SDK 代码的代码库中。
配置 output 位置
在 Python SDK 的 group 中,将输出位置从 local-file-system(默认值)更改为 pypi,以指示 Fern 应直接将您的包发布到 PyPI 注册表:
生成 PyPI 令牌
配置 PyPI 发布
选择您的发布模式
Optionally set the mode to control how Fern handles SDK publishing:
mode: release(default): Fern generates code, commits to main, and tags a release automaticallymode: pull-request(recommended): Fern generates code and creates a PR for you to review before releasemode: push: Fern generates code and pushes to a branch you specify for you to review before release
You can also configure other settings, like the reviewers or license. Refer to the full github (generators.yml) reference for more information.
发布您的 SDK
决定您希望如何将 SDK 发布到 PyPI。您可以使用 GitHub 工作流程进行自动化发布,或直接通过 CLI 发布。
通过 GitHub 工作流程发布(推荐)
通过 GitHub Actions 设置发布工作流程,这样您可以直接从源代码库触发新的 SDK 发布。
设置身份验证
在 GitHub 中打开您的 Fern 代码库。点击代码库中的设置选项卡。然后,在安全部分下,打开密钥和变量 > Actions。

您也可以使用 URL https://github.com/<your-repo>/settings/secrets/actions。
为您的 Fern 令牌添加密钥
- 选择新建代码库密钥。
- 将密钥命名为
FERN_TOKEN。 - 添加您的 Fern 令牌。如果您还没有,请通过运行
fern token生成一个。默认情况下,fern_token为fern.config.json中列出的组织生成。 - 点击添加密钥。
设置新工作流程
设置一个可以从 GitHub UI 手动触发的 CI 工作流程。在您的代码库中,导航到 Actions。选择新建工作流程,然后自己设置工作流程。添加类似于这样的工作流程:
重新生成和发布您的 SDK
导航到 Actions 选项卡,选择您刚创建的工作流程,指定版本号,然后点击运行工作流程。这将重新生成您的 SDK。

The rest of the release process depends on your chosen mode:
-
Release mode (default): If you didn’t specify a
modeor setmode: release, no further action is required. Fern automatically tags the new release with your specified version number and initiates the publishing workflow in your SDK repository. -
Pull request or push mode: If you set
mode: pull-requestormode: push, Fern creates a pull request or pushes to a branch respectively. Review and merge the PR (pull-request) or branch (push), then tag a new release to initiate the publishing workflow in your SDK repository.
工作流程完成后,您可以通过登录 PyPI 并导航到您的项目来查看您的新发布。
通过 CLI 和环境变量发布
重新生成和发布您的 SDK
重新生成您的 SDK,指定版本:
The rest of the release process depends on your chosen mode:
-
Release mode (default): If you didn’t specify a
modeor setmode: release, no further action is required. Fern automatically tags the new release with your specified version number and initiates the publishing workflow in your SDK repository. -
Pull request or push mode: If you set
mode: pull-requestormode: push, Fern creates a pull request or pushes to a branch respectively. Review and merge the PR (pull-request) or branch (push), then tag a new release to initiate the publishing workflow in your SDK repository.
工作流程完成后,您可以通过登录 PyPI 并导航到您的项目来查看您的新发布。

