Publishing to PyPI

Publish your public-facing Fern Python SDK to the PyPI registry. After following the steps on this page, you’ll have a versioned package published on PyPI.

Versioned package published on PyPI

This page assumes that you have:

Configure SDK package settings

You’ll need to update your generators.yml file to configure the package name, output location, and client naming for PyPi publishing. Your generators.yml should live in your source repository (or on your local machine), not the repository that contains your Python SDK code.

1

Configure output location

In the group for your Python SDK, change the output location in from local-file-system (the default) to pypi to indicate that Fern should publish your package directly to the PyPi registry:

generators.yml
1groups:
2 python-sdk:
3 generators:
4 - name: fernapi/fern-python-sdk
5 version: 4.28.4
6 output:
7 location: pypi
2

Add a unique package name

Your package name must be unique in the PyPI repository, otherwise publishing your SDK to PyPI will fail.

generators.yml
1groups:
2 python-sdk:
3 generators:
4 - name: fernapi/fern-python-sdk
5 version: 4.28.4
6 output:
7 location: pypi
8 package-name: your-package-name
3

Configure client-class-name

The client-class-name option controls the name of the generated client. This is the name customers use to import your SDK (import { your-client-name } from 'your-package-name';).

generators.yml
1groups:
2 python-sdk:
3 generators:
4 - name: fernapi/fern-python-sdk
5 version: 4.28.4
6 output:
7 location: pypi
8 package-name: your-package-name
9 config:
10 client_class_name: YourClientName # must be PascalCase

Generate a PyPi token

1

Log into PyPi

Log into PyPi or create a new account.

3

Add New Token

  1. Click on Add API Token
  2. Name your token and set the scope to the relevant projects.
  3. Click Create token
Creating a New API Token
Save your new token – it won’t be displayed after you leave the page.

Configure PyPi publication

1

Add repository location

Add the path to your GitHub repository to generators.yml:

generators.yml
1groups:
2 python-sdk:
3 generators:
4 - name: fernapi/fern-python-sdk
5 version: 4.28.4
6 output:
7 location: pypi
8 package-name: your-package-name
9 config:
10 client_class_name: YourClientName
11 github:
12 repository: your-org/company-python
2

Configure PyPi authentication token

Add token: ${PYPI_TOKEN} to generators.yml.

generators.yml
1groups:
2 python-sdk:
3 generators:
4 - name: fernapi/fern-python-sdk
5 version: 4.28.4
6 output:
7 location: pypi
8 package-name: your-package-name
9 token: ${PYPI_TOKEN}
10 config:
11 client_class_name: YourClientName
12 github:
13 repository: your-org/company-python
3

Choose your publishing mode

Optionally set the mode to control how Fern handles SDK publishing:

  • mode: release (default): Fern generates code, commits to main, and tags a release automatically
  • mode: pull-request: Fern generates code and creates a PR for you to review before release
  • mode: 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.

generators.yml
1groups:
2 python-sdk:
3 generators:
4 - name: fernapi/fern-python-sdk
5 version: 4.28.4
6 output:
7 location: npm
8 package-name: name-of-your-package
9 token: ${PYPI_TOKEN}
10 config:
11 namespaceExport: YourClientName
12 github:
13 repository: your-org/your-repository
14 mode: push
15 branch: your-branch-name # Required for mode: push

Publish your SDK

Decide how you want to publish your SDK to PyPi. You can use GitHub workflows for automated releases or publish directly via the CLI.

1

Set PyPI environment variable

Set the PYPI_TOKEN environment variable on your local machine:

$export PYPI_TOKEN=your-actual-pypi-token
2

Regenerate and release your SDK

Regenerate your SDK, specifying the version:

$fern generate --group python-sdk --version <version>

The rest of the release process depends on your chosen mode:

  • Release mode (default): If you didn’t specify a mode or set mode: 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-request or mode: 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.

Once the workflow completes, you can view your new release by logging into PyPi and navigating to Your projects.