This repository is a minimal template for publishing a small Python package to PyPI using GitHub Actions and trusted publishing.
- Fork this repository on GitHub and mark your fork as a template via the repo settings (once)
- Try and/or remove the demo files from your fork:
src/lorenz.py¬ebooks/lorenz_demo.ipynb(once) - Create a pending publisher on PyPI.org (each new project)
- Create a new repository for your project from your template fork on GitHub (each new project)
- Update
pyproject.tomlto reflect your new project's metadata (each new project) - Commit and push your code (each code update)
- Tag and publish a release on GitHub - this will trigger the workflow to publish the current commit to PyPI (each code update)
.
├── .devcontainer/ # Dev container config
├── .git/ # Local Git metadata
├── .github/ # GitHub configuration
│ └── workflows/
│ └── publish-to-pypi.yml # Builds package and publishes to PyPI
├── .gitignore # Files and folders Git should ignore
├── LICENSE # Package license
├── pyproject.toml # Package metadata, build system, and dependencies
├── README.md # Project overview and setup instructions
├── requirements.txt # Dev/test dependencies for local usage
├── notebooks/
│ └── lorenz_demo.ipynb # Example notebook demonstrating the package
└── src/
└── lorenz.py # Example module shipped in the package
- Fork this repository.
- In the fork, open Settings → General → Template repository and enable it.
This repository ships a tiny demo package (lorenz) used to illustrate packaging and publishing. You can try it locally or remove it before starting your own project.
-
Open your fork in a devcontainer or GitHub Codespace.
-
Install the package in editable mode:
pip install -e . -
Run the demo notebook notebooks/lorenz_demo.ipynb
Since the demo package has been published to PyPI from this repo, you can install it via pip and use it anywhere:
pip install lorenz
If you want a clean template fork to start new projects, simply delete the demo files:
src/lorenz.pynotebooks/lorenz_demo.ipynb
- In PyPI, go to Project → Publishing → Trusted Publishers.
- Add a pending publisher with these values:
- PyPI Project Name: must be unique, site-wide
- Owner: your GitHub user or org
- Repository: your repo name
- Workflow:
publish-to-pypi.yml - Environment:
pypi
Do this first, before naming the GitHub repository to determine if your planned name is available on PyPI. PyPI project names must be unique site-wide. The GitHub repo and PyPI project names don't have to match, but it's nice if they do.
- In your template fork, click Use this template on GitHub.
- Create a new repository for your project.
Update pyproject.toml with your project metadata:
- Change
name,authors, anddescriptionin[tool.poetry] - Update
classifiersandkeywordsin[tool.poetry] - Update runtime dependencies in
[tool.poetry.dependencies] - Replace or remove
[tool.poetry.urls]
Use the repo to develop your project as you normally would. Place Python modules to be published as part of your package in the src/ directory. Commit and push your code to GitHub.
- Create a GitHub release tag that matches your current
versionunder[tool.poetry]inpyproject.toml(e.g.,0.1.0orv0.1.0- see here for information about version numbering). - The Publish to PyPI workflow will build and publish automatically.
If you prefer a manual run, you can trigger the workflow from the Actions tab.