You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tutorials/publish-pypi.md
+23-5Lines changed: 23 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@
6
6
# Publish your Python package to PyPI
7
7
8
8
:::{todo}
9
-
- Make sure they add /dist to their .gitignore file. We have not discussed GitHub workflows anywhere yet. Where does that fit?
9
+
- Make sure they add /dist to their .gitignore file. Where does that fit?
10
10
11
11
:::
12
12
@@ -62,9 +62,7 @@ to TestPyPI. You need to:
62
62
1.**Create an account on TestPyPI (or PyPI)**: You will need to create a TestPyPI account and associated token which provides permissions for you to upload your package. When you later publish your package to PyPI, you will need a separate PyPI account and token.
63
63
1.**Publish to TestPyPI using `hatch publish`**
64
64
65
-
In a future lesson, you will learn how to create an automated
66
-
GitHub Actions workflow that publishes an updated
67
-
version of your package to PyPI every time you create a GitHub release.
65
+
In a [future lesson](trusted-publishing), you will learn how to create an automated GitHub Actions workflow that publishes an updated version of your package to PyPI every time you create a GitHub release.
68
66
69
67
:::{admonition} Learn more about building Python packages in our guide
70
68
:class: tip
@@ -368,8 +366,19 @@ related to PyPI publication.
368
366
1. You can create a package-specific token which you will use to publish your package (manually) to PyPI. This is a great option if you don't wish to automate your PyPI publication workflow.
369
367
2. You can also create an automated publication workflow on GitHub using GitHub Actions. This is a great way to make the publication process easier and it also supports a growing maintainer team. In this case we suggest you don't worry about the token and instead setup a specific GitHub Actions that publishes your package when you make a release. You can then create a "trusted publisher" workflow on PyPI.
370
368
371
-
You will learn how to create the automated trusted publisher workflow in a followup lesson.
369
+
:::{admonition} Trusted Publishing
370
+
:class: tip
371
+
372
+
While publishing from GitHub Action is possible using tokens, we recommend the _Trusted Publishing_ approach as it also confers significant security and usability benefits.
373
+
374
+
On the usability front, when Trusted Publishing is enabled, users no longer need to manually create API tokens on PyPI and store them in the GitHub release workflow.
375
+
376
+
On the security front, Trusted Publishing reduces a risk related to the API token being long lived: with API tokens, as soon as an attacker gets access to it, they can publish many packages and versions in your name (dependending on the scope of the token), until you discover the token compromise and rotate the credential. Trusted Publishing avoids this problem by minting very short lived tokens which expire automatically.
377
+
378
+
For these benefits, it is recommended that users use _only_ the GitHub Actions release workflow to publish packages.
379
+
:::
372
380
381
+
You will learn how to create the automated trusted publisher workflow in a followup lesson.
373
382
374
383
### OPTIONAL: If you want to use a manual token-based publication workflow
375
384
@@ -386,6 +395,15 @@ To do this:
386
395
387
396
And you're all done!
388
397
398
+
:::{admonition} Trusted Publishing instead of token-based publication
399
+
:class: tip
400
+
401
+
Trusted Publishing will generate short lived tokens, scoped to the project, on
402
+
demand, only when a specific release workflows gets triggered. This solves all
403
+
the security and usability issues associated with storing credentials in
404
+
files/GitHub secrets.
405
+
:::
406
+
389
407
## You have published your package to TestPyPI!
390
408
391
409
Congratulations. You have now successfully published your package to TestPyPI. If you have a package that is ready for real-world use on the real PyPI, then you can follow the same steps (with the differences noted above) to publish it on PyPI.
0 commit comments