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. To distribute the SDK
internally instead, generate to the local file system (optionally
self-hosted) and build a wheel with
fern generate --package.
If you’re using token-based authentication, consider switching to OIDC (trusted publishing). See Migrating from token-based to OIDC publishing for the steps.

This page assumes that you have:
- An initialized
fernfolder, a GitHub repository for your Python SDK, and a Python target insdk-config.yml. See Generating an SDK (Python).
Configure SDK package settings
Update the Python target in sdk-config.yml to configure the package name and client naming for PyPI publishing. Your sdk-config.yml should live in your source repository (or on your local machine), not the repository that contains your Python SDK code.
Add a unique package name
Your package name must be unique in the PyPI repository, otherwise publishing your SDK to PyPI will fail.
Configure the client name
The generation.naming.clientName option controls the name of the generated client. This is the name customers use to import your SDK (from your_package import YourClientName).
Add PyPI metadata (optional)
Package metadata appears on your package’s PyPI page. keywords support PyPI search and discovery, documentationUrl links to your package documentation, and homepage links to your project homepage. Metadata set in the top-level package block applies to every target.
Configure GitHub publishing
Fern can automatically publish your SDK to PyPI via GitHub Actions. Set output.delivery to github, configure your repository and publishing mode, and set output.publish.registry to pypi:
Optionally set the mode to control how Fern handles SDK publishing:
mode: release(default): Fern generates code, commits to the default branch (or thebranchyou specify), 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 output.github reference for more information.
Configure authentication
Choose how you want to authenticate with PyPI when publishing. OpenID Connect (OIDC) authentication is recommended because it removes the need to manage long-lived API tokens.
OIDC authentication (Recommended)
OIDC-based publishing (also known as “trusted publishing”) is the most secure way to publish. With OIDC, you don’t need to manage authentication tokens - PyPI trusts your GitHub repository to publish directly.
- Fern Python SDK generator version
4.38.1or later - Fern CLI version
5.46.0or later (only required for local generation with--local)
Configure OIDC
sdk-config.yml supports trusted publishing only for npm. To add token: OIDC with generators.yml, see Legacy PyPI publishing.
Generate your SDK
Generate your SDK to create the GitHub Actions workflow with OIDC configuration:
This creates a .github/workflows/ci.yml file that’s configured to use OIDC for PyPI publishing.
Authorize your repository on PyPI
Configure trusted publishing on PyPI to allow your GitHub repository to publish:
- Navigate to your project on PyPI and open Manage > Publishing
- Under Add a new publisher, select GitHub
- Fill in:
- Owner: Your GitHub username or organization
- Repository name: Your Python SDK repository name (e.g.,
your-repository) - Workflow name:
ci.yml - Environment name:
pypi
For more details, see PyPI’s trusted publishers documentation.
Troubleshooting
“invalid-publisher” or authentication errors
Common causes:
- Workflow filename doesn’t match exactly (must be
ci.yml) - Environment name on PyPI doesn’t match the
pypienvironment in the generated workflow - Trusted publisher configuration on PyPI doesn’t match your repository settings
Solution: Double-check your trusted publisher configuration on PyPI matches your repository name, workflow filename, and environment name exactly.
Token-based authentication
Generate a PyPI token
- Log into PyPI or create a new account
- Click on your profile picture and select Account settings
- Scroll down to API tokens and click Add API token
- Name your token and set the scope to the relevant projects
- Click Create token

Publish your SDK
Your SDK will automatically be published to PyPI when you create a GitHub release with a version tag:
- Create a GitHub release with a version tag (for example,
v1.0.0) - The CI workflow will run automatically and publish to PyPI
- View your package on PyPI to confirm the version
Alternative: Manual workflow dispatch
Set up a release workflow via GitHub Actions so you can trigger new SDK releases directly from your source repository.
If you prefer to trigger publishes manually from your source repository, set up a release workflow via GitHub Actions.
Add secret for your Fern API key
- Open your Fern repository on GitHub and go to Settings > Secrets and variables > Actions
- Select New repository secret
- Name your secret
FERN_TOKEN - Add your Fern API key. If you don’t already have one, generate one by
running
fern token. By default, the API key is generated for the organization listed infern.config.json. - Click Add secret
If you use token-based authentication, also add a PYPI_TOKEN secret with your PyPI token.
Set up a new workflow
Set up a CI workflow that you can manually trigger from the GitHub UI. In your repository, navigate to Actions. Select New workflow, then Set up workflow yourself. Add a workflow that’s similar to this:
Regenerate and release your SDK
Navigate to the Actions tab, select the workflow you just created, specify a version number, and click Run workflow. This regenerates your 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.
Once the workflow completes, you can view your new release by logging into PyPi and navigating to Your projects.
Alternative: Release via CLI and environment variables
Set PyPI environment variable
If you use token-based authentication, set the PYPI_TOKEN environment variable on your local machine:
Regenerate and release your SDK
Regenerate your SDK, specifying the version:
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.
Once the workflow completes, you can view your new release by logging into PyPI and navigating to Your projects.
Migrating from token-based to OIDC publishing
Migrating to OIDC publishing uses generators.yml. See Migrating from token-based to OIDC publishing in the Legacy docs.
