This guide explains how to publish new versions of google-cloud-sql-postgres-sqlalchemy to PyPI.
You need to create API tokens for both Test PyPI and PyPI, then add them as GitHub secrets.
- Go to https://pypi.org/manage/account/token/
- Click "Add API token"
- Give it a name (e.g., "google-cloud-sql-postgres-sqlalchemy-github-actions")
- Scope: "Entire account" (initially) or "Project: google-cloud-sql-postgres-sqlalchemy" (after first publish)
- Copy the token (starts with
pypi-)
- Go to https://test.pypi.org/manage/account/token/
- Follow the same steps as above
- Copy the token
- Go to your repository: https://github.com/javadebadi/google-cloud-sql-postgres-sqlalchemy
- Click Settings → Secrets and variables → Actions
- Click "New repository secret"
- Add two secrets:
- Name:
PYPI_API_TOKEN, Value: (your PyPI token) - Name:
TEST_PYPI_API_TOKEN, Value: (your Test PyPI token, optional)
- Name:
The package automatically publishes to PyPI when you push a version tag:
# 1. Update version in pyproject.toml
# IMPORTANT: The version MUST match the tag you'll create
# Example: version = "0.2.0"
sed -i 's/version = ".*"/version = "0.2.0"/' pyproject.toml
# 2. Commit the version change
git add pyproject.toml
git commit -m "Bump version to 0.2.0"
git push
# 3. Create and push a version tag (must match pyproject.toml version)
git tag v0.2.0
git push origin v0.2.0
# 4. GitHub Actions will automatically:
# - Validate that tag version matches pyproject.toml version
# - Run all tests
# - Build the package
# - Publish to Test PyPI (if token configured)
# - Publish to PyPI
# - Create a GitHub Releasepyproject.toml, or the workflow will fail with a validation error.
When you push a tag like v0.2.0:
- ✅ Version is extracted from tag (e.g.,
v0.2.0→0.2.0) - ✅ Version is extracted from
pyproject.toml - ✅ Validation: Ensures tag version matches package version (fails if mismatch)
- ✅ CI tests run on all Python versions (3.10-3.14)
- ✅ Package is built
- ✅ Published to Test PyPI (optional, skips if exists)
- ✅ Published to PyPI
- ✅ GitHub Release is created with release notes
If you prefer to publish manually:
# 1. Update version in pyproject.toml
# version = "0.2.0"
# 2. Run tests
invoke code.ci
# 3. Build package
python -m build
# 4. Publish to Test PyPI (optional)
python -m twine upload --repository testpypi dist/*
# 5. Test installation
pip install --index-url https://test.pypi.org/simple/ google-cloud-sql-postgres-sqlalchemy
# 6. Publish to PyPI
python -m twine upload dist/*
# 7. Create git tag
git tag v0.2.0
git push origin v0.2.0Follow Semantic Versioning:
- MAJOR version (v1.0.0): Incompatible API changes
- MINOR version (v0.2.0): New functionality, backwards compatible
- PATCH version (v0.1.1): Bug fixes, backwards compatible
- All tests pass (
invoke code.ci) - CHANGELOG.md updated (if you have one)
- README.md is up to date
- Version number follows semver
- PyPI API token is configured in GitHub secrets
For the first release to PyPI:
- The package name must be available on PyPI
- Use scope "Entire account" for the API token initially
- After first successful publish, you can create a project-scoped token
- Update the GitHub secret with the project-scoped token for better security
After pushing a tag, monitor the release:
- GitHub Actions: https://github.com/javadebadi/google-cloud-sql-postgres-sqlalchemy/actions
- PyPI Package: https://pypi.org/project/google-cloud-sql-postgres-sqlalchemy/
- GitHub Releases: https://github.com/javadebadi/google-cloud-sql-postgres-sqlalchemy/releases
- Check that your API token is correct in GitHub secrets
- Ensure the package name is available on PyPI
- For first publish, use "Entire account" scope
- You cannot re-upload the same version to PyPI
- Increment the version number and create a new tag
- Run
invoke code.cilocally first - Fix any issues before pushing the tag
- Delete and recreate the tag if needed:
git tag -d v0.2.0 git push origin :refs/tags/v0.2.0 # Fix issues, then recreate tag git tag v0.2.0 git push origin v0.2.0