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 guide assumes that you already have an initialized fern folder on your local machine. See Set up the fern folder for more details.

Set up your GitHub integration

  1. Create a new GitHub repository called company-python (or something similar) for your SDK, if you haven’t done so already.
  2. Install the Fern GitHub App: Select Configure, then scroll down to Repository Access. Select Only select repositories and in the dropdown select the repository for your SDK. Click Save.

Configure generators.yml

1

Run fern add <generator>

Navigate to your generators.yml on your local machine. Your generators.yml lives inside of your fern folder and contains all the configuration for your Fern generators.

Add a new generator to generators.yml:

$fern add fern-python-sdk --group python-sdk

Once the command completes, you’ll see a new group created in your generators.yml:

1 groups:
2 ...
3 python-sdk:
4 generators:
5 - name: fernapi/fern-python-sdk
6 version: 4.25.6
7 output:
8 location: local-file-system
9 path: ../sdks/python
2

Configure output location

Next, change the output location in generators.yml from local-file-system (the default) to pypi to indicate that Fern should publish your package directly to the PyPI registry:

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

Add a unique package name

Your package name must be unique in the PyPI repository, otherwise publishing your SDK to PyPI will fail. Update your package name if you haven’t done so already:

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

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';).

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

Add repository location

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

Python
1groups:
2 python-sdk:
3 generators:
4 - name: fernapi/fern-python-sdk
5 version: 4.25.6
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

Set up PyPi publishing authentication

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.
4

Configure PyPI authentication token

Add token: ${PYPI_TOKEN} to generators.yml to tell Fern to use the PYPI_TOKEN environment variable for authentication when publishing to the PyPI registry.

Python
1groups:
2 python-sdk:
3 generators:
4 - name: fernapi/fern-python-sdk
5 version: 4.25.6
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

Release your SDK to PyPI

At this point, you’re ready to generate a release for your SDK.

1

Set PyPI environment variable

On your local machine, set the PYPI_TOKEN environment variable to the new API token you generated earlier:

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

Generate your release

Regenerate your SDK and publish it on PyPI:

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

Local machine output will verify that the release is pushed to your repository and tagged with the version you specified. Log back into PyPI and navigate to Your projects to see your new release.