This guide explains how to publish the project-vectorizer package to PyPI.
-
PyPI Account: Create accounts on both:
-
GitHub Repository Secrets: Add the following secrets to your GitHub repository:
- Go to repository Settings → Secrets and variables → Actions
- No API tokens needed if using Trusted Publishers (recommended, see below)
This is the easiest method using GitHub Actions:
-
Update Version Number:
# Edit pyproject.toml and update the version vim pyproject.toml # Change: version = "0.1.3" to version = "0.1.4"
-
Commit and Push Changes:
git add pyproject.toml git commit -m "Bump version to 0.1.4" git push -
Create a GitHub Release:
# Create and push a tag git tag v0.1.4 git push origin v0.1.4 # Or create a release via GitHub UI: # - Go to repository → Releases → Create a new release # - Choose tag: v0.1.4 # - Release title: v0.1.4 # - Add release notes # - Click "Publish release"
-
Automated Publishing:
- The GitHub Action will automatically:
- Build the package
- Run tests
- Publish to PyPI
- Upload signed artifacts to the GitHub release
- The GitHub Action will automatically:
You can manually trigger a publish to TestPyPI or PyPI:
-
Go to GitHub Actions:
- Navigate to your repository → Actions tab
- Select "Publish to PyPI" workflow
-
Run Workflow:
- Click "Run workflow"
- Choose environment:
testpypi- For testingpypi- For production
- Click "Run workflow"
For local testing and publishing:
-
Install Build Tools:
pip install build twine
-
Build the Package:
# Clean previous builds rm -rf dist/ build/ *.egg-info/ # Build the package python -m build
-
Test the Build:
# Check the package twine check dist/* # Test install locally pip install dist/project_vectorizer-0.1.0-py3-none-any.whl
-
Upload to TestPyPI (Testing):
twine upload --repository testpypi dist/* # Test installation from TestPyPI pip install --index-url https://test.pypi.org/simple/ project-vectorizer
-
Upload to PyPI (Production):
twine upload dist/*
Trusted Publishers is the most secure way to publish without API tokens:
- Go to PyPI
- Navigate to your project (create it first if needed)
- Go to "Publishing" → "Add a new publisher"
- Fill in:
- PyPI Project Name:
project-vectorizer - Owner:
starkbaknet - Repository name:
project-vectorizer - Workflow name:
publish.yml - Environment name:
pypi
- PyPI Project Name:
- Go to TestPyPI
- Follow the same steps as above
- Use environment name:
testpypi
Follow semantic versioning (MAJOR.MINOR.PATCH):
- MAJOR: Breaking changes (e.g., 1.0.0 → 2.0.0)
- MINOR: New features, backwards compatible (e.g., 0.1.0 → 0.2.0)
- PATCH: Bug fixes (e.g., 0.1.0 → 0.1.1)
- Update version in
pyproject.toml - Update CHANGELOG in
README.md - Commit changes
- Create git tag
- Push tag to trigger release
- Verify release on PyPI
Before publishing a new version:
- All tests pass:
pytest - Code is formatted:
black . && isort . - Version number updated in
pyproject.toml - README.md is up to date
- CHANGELOG section updated
- Git tag created with correct version
After publishing to TestPyPI:
# Create a test environment
python -m venv test_env
source test_env/bin/activate
# Install from TestPyPI
pip install --index-url https://test.pypi.org/simple/ \
--extra-index-url https://pypi.org/simple/ \
project-vectorizer
# Test the installation
pv --version
pv --help
# Deactivate and remove test environment
deactivate
rm -rf test_env-
Version already exists:
- You cannot re-upload the same version
- Increment the version number in
pyproject.toml
-
Authentication failed:
- Verify your API token or Trusted Publisher setup
- Check GitHub Actions secrets
-
Package not found:
- Wait a few minutes after publishing
- Check PyPI for the package page
-
Import errors after install:
- Verify MANIFEST.in includes all necessary files
- Check that
__init__.pyfiles exist in all packages
-
Dependencies not installing:
- Verify dependency versions in
pyproject.toml - Test with TestPyPI first
- Verify dependency versions in
After publishing:
- PyPI: https://pypi.org/project/project-vectorizer/
- TestPyPI: https://test.pypi.org/project/project-vectorizer/
For issues with publishing:
- Check PyPI Help
- Review Python Packaging Guide
- Open an issue in the repository