Skip to content

Commit d822abd

Browse files
authored
Add PyPI Publishing Guide (#42)
1 parent 46ae82b commit d822abd

File tree

3 files changed

+208
-4
lines changed

3 files changed

+208
-4
lines changed
142 KB
Loading
104 KB
Loading
Lines changed: 208 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,212 @@
11
---
2-
title: Publishing to PyPi
3-
description: How to publish the Fern Python SDK to PyPi.
2+
title: Publishing to PyPI
3+
description: How to publish the Fern Python SDK to PyPI.
44
---
55

6-
Learn how to publish your Fern Python SDK to the PyPi registry.
6+
Publish your public-facing Fern Python SDK to the [PyPI
7+
registry](https://pypi.org/). After following the steps on this page,
8+
you'll have a versioned package published on PyPI.
79

8-
<Warning>This page is a WIP, please refer to our previous [documentation](https://buildwithfern.com/learn/sdks/guides/publish-a-public-facing-sdk).</Warning>
10+
<Frame>
11+
<img src="assets/pypi-package.png" alt="Versioned package published on PyPI" />
12+
</Frame>
13+
14+
<Info>This guide assumes that you already have an initialized `fern` folder on your local machine. If you don’t, run `fern init`. See [Python Quickstart](quickstart.mdx) for more details.</Info>
15+
16+
## Set up your GitHub integration
17+
18+
1. Create a new GitHub repository called `company-python` (or something similar) for your SDK, if you haven't done so already.
19+
1. Install the [Fern GitHub App](https://github.com/apps/fern-api): Select **Configure**, then scroll down to **Repository Access**. Select **Only select repositories** and in the dropdown select the repository for your SDK. Click **Save**.
20+
21+
22+
## Configure `generators.yml`
23+
24+
<Steps>
25+
26+
<Step title="Run `fern add <generator>`">
27+
28+
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.
29+
30+
Add a new generator to `generators.yml`:
31+
32+
33+
```bash
34+
fern add fern-python-sdk --group python-sdk
35+
```
36+
37+
Once the command completes, you'll see a new group created in your `generators.yml`:
38+
39+
```yaml {3-9}
40+
groups:
41+
...
42+
python-sdk:
43+
generators:
44+
- name: fernapi/fern-python-sdk
45+
version: <Markdown src="/snippets/version-number.mdx"/>
46+
output:
47+
location: local-file-system
48+
path: ../sdks/python
49+
```
50+
51+
</Step>
52+
53+
<Step title="Configure `output` location">
54+
55+
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:
56+
57+
```yaml title="Python" {6-7}
58+
groups:
59+
python-sdk:
60+
generators:
61+
- name: fernapi/fern-python-sdk
62+
version: <Markdown src="/snippets/version-number.mdx"/>
63+
output:
64+
location: pypi
65+
66+
```
67+
</Step>
68+
69+
<Step title="Add a unique package name">
70+
71+
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:
72+
73+
74+
```yaml title="Python" {8}
75+
groups:
76+
python-sdk:
77+
generators:
78+
- name: fernapi/fern-python-sdk
79+
version: <Markdown src="/snippets/version-number.mdx"/>
80+
output:
81+
location: pypi
82+
package-name: your-package-name
83+
```
84+
85+
</Step>
86+
87+
<Step title="Configure `client-class-name`">
88+
89+
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';`).
90+
91+
92+
```yaml title="Python" {9-10}
93+
groups:
94+
python-sdk:
95+
generators:
96+
- name: fernapi/fern-python-sdk
97+
version: <Markdown src="/snippets/version-number.mdx"/>
98+
output:
99+
location: pypi
100+
package-name: your-package-name
101+
config:
102+
client_class_name: YourClientName # must be PascalCase
103+
```
104+
105+
</Step>
106+
107+
<Step title="Add repository location">
108+
109+
Add the path to your GitHub repository to `generators.yml`:
110+
111+
```yaml title="Python" {11-12}
112+
groups:
113+
python-sdk:
114+
generators:
115+
- name: fernapi/fern-python-sdk
116+
version: <Markdown src="/snippets/version-number.mdx"/>
117+
output:
118+
location: pypi
119+
package-name: your-package-name
120+
config:
121+
client_class_name: YourClientName
122+
github:
123+
repository: your-org/company-python
124+
```
125+
126+
</Step>
127+
</Steps>
128+
129+
## Set up PyPi publishing authentication
130+
131+
<Steps>
132+
133+
<Step title="Log into PyPi">
134+
135+
Log into [PyPi](https://pypi.org/) or create a new account.
136+
137+
</Step>
138+
139+
<Step title="Navigate to Account settings">
140+
141+
1. Click on your profile picture.
142+
1. Select **Account settings**.
143+
1. Scroll down to **API Tokens**.
144+
145+
</Step>
146+
147+
<Step title="Add New Token">
148+
149+
1. Click on **Add API Token**
150+
1. Name your token and set the scope to the relevant projects.
151+
1. Click **Create token**
152+
153+
<Frame>
154+
<img src="assets/new-api-token.png" alt="Creating a New API Token" />
155+
</Frame>
156+
157+
<Warning>Save your new token – it won’t be displayed after you leave the page.</Warning>
158+
159+
</Step>
160+
161+
<Step title="Configure PyPI authentication token">
162+
163+
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.
164+
165+
```yaml title="Python" {9}
166+
groups:
167+
python-sdk:
168+
generators:
169+
- name: fernapi/fern-python-sdk
170+
version: <Markdown src="/snippets/version-number.mdx"/>
171+
output:
172+
location: pypi
173+
package-name: your-package-name
174+
token: ${PYPI_TOKEN}
175+
config:
176+
client_class_name: YourClientName
177+
github:
178+
repository: your-org/company-python
179+
```
180+
</Step>
181+
182+
</Steps>
183+
184+
## Release your SDK to PyPI
185+
186+
At this point, you're ready to generate a release for your SDK.
187+
188+
<Steps>
189+
190+
<Step title="Set PyPI environment variable">
191+
192+
On your local machine, set the `PYPI_TOKEN` environment variable to the new API token you generated earlier:
193+
194+
```bash
195+
export PYPI_TOKEN=your-actual-pypi-token
196+
```
197+
198+
</Step>
199+
200+
<Step title="Generate your release">
201+
202+
Regenerate your SDK and publish it on PyPI:
203+
204+
```bash
205+
fern generate --group python-sdk --version <version>
206+
```
207+
Local machine output will verify that the release is pushed to your
208+
repository and tagged with the version you specified. Log back into PyPI and
209+
navigate to **Your projects** to see your new release.
210+
</Step>
211+
212+
</Steps>

0 commit comments

Comments
 (0)