This guide walks through setting up a Python package with pyproject.toml,
configuring GitHub Actions, and publishing automatically to PyPI using tags.
pyproject.tomlThis file defines your package metadata and build system.
[build-system]
requires = ["setuptools>=61", "setuptools-scm"]
build-backend = "setuptools.build_meta"
[project]
name = "your-package-name"
dynamic = ["version"]
description = "Short description of your package"
readme = "README.md"
authors = [{ name = "Your Name", email = "you@example.com" }]
license = { text = "MIT" }
requires-python = ">=3.9"
dependencies = [
"numpy",
"qiskit",
]
[project.optional-dependencies]
dev = [
"pytest",
"black",
]
[project.urls]
Homepage = "https://github.com/yourname/your-repo"
[tool.setuptools_scm]
setuptools-scm using Git tags.
src/ layout supportIf your package lives inside a src/ directory, add this to the bottom of pyproject.toml:
[tool.setuptools.packages.find]
where = ["src"]
src/your_package/ instead of placing the package at the root.
Create the folder:
.github/workflows/
Inside it, create a file (e.g. publish.yml):
name: Publish to PyPI
on:
push:
tags:
- "v*"
jobs:
publish:
runs-on: ubuntu-latest
environment:
name: pypi
permissions:
id-token: write # for trusted publishing
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install build tool
run: pip install build
- name: Build
run: python -m build
- name: Publish
uses: pypa/gh-action-pypi-publish@release/v1
Go to: https://pypi.org/manage/account/publishing/
Add your GitHub repository there.
Once everything is set up, run:
git add .
git commit -m "commit message"
git tag v0.0.1
git push origin main --tags
v0.0.1 triggers GitHub Actions, which builds and publishes your package automatically.
After the workflow runs, your package should appear on PyPI:
pip install your-package-name
v (e.g. v1.0.0)..github/workflows/, not elsewhere.