Publishing to PyPI & TestPyPI¶
This guide covers how tickertape-client is packaged, verified, and published to the Python Package Index (PyPI).
1. Automated Publishing via GitHub Actions¶
The repository includes a production-ready publishing workflow at .github/workflows/publish.yml.
Method A: PyPI Trusted Publishing (Recommended)¶
PyPI supports Trusted Publishing (OIDC), which eliminates the need to generate, store, or rotate manual API tokens. GitHub Actions authenticates directly with PyPI using short-lived OpenID Connect tokens.
Setting up on PyPI:¶
- Log in to pypi.org (or test.pypi.org).
- Go to Account Settings > Publishing.
- Under Add a new publisher, select GitHub.
- Enter the repository details:
- Owner:
sid-146 - Repository name:
tickertape-client - Workflow name:
publish.yml - Environment name:
pypi(ortestpypifor TestPyPI)
- Owner:
- Save the configuration.
Setting up GitHub Environments:¶
- In your GitHub repository, go to Settings > Environments.
- Click New environment and create:
pypitestpypi
- (Optional) Set protection rules (e.g. required reviewers) for the
pypienvironment.
Method B: API Token Secret (Alternative Fallback)¶
If you prefer using traditional API tokens:
- Generate an API token on pypi.org with upload permissions.
- In your GitHub repository, navigate to Settings > Secrets and variables > Actions.
- Add the following repository secrets:
PYPI_API_TOKEN:pypi-...TEST_PYPI_API_TOKEN:pypi-...(if using TestPyPI)
2. Triggering a Release¶
Automated via GitHub Release¶
- Update the
versionstring inpyproject.toml(e.g.version = "0.1.0"). - Commit and push your changes to
main. - In GitHub, create a new Release with a tag matching your version (e.g.
v0.1.0). - Once you click Publish release, GitHub Actions will automatically:
- Run the test suite (
pytest) - Build source distributions (
.tar.gz) and wheels (.whl) - Verify package metadata with
twine check - Securely publish to PyPI
- Run the test suite (
Manual Trigger via GitHub UI (workflow_dispatch)¶
- In GitHub, go to the Actions tab.
- Select the Publish to PyPI workflow.
- Click Run workflow.
- Choose whether to target
pypi(production) ortestpypi(test).
3. Manual Publishing via Terminal (uv or twine)¶
You can also build and publish locally from your terminal.
Step 1: Clean and Build Distributions¶
This outputs clean artifacts to dist/:
dist/tickertape_client-<version>-py3-none-any.whldist/tickertape_client-<version>.tar.gz
Step 2: Validate Metadata¶
Ensure both checks output PASSED.
Step 3: Test Upload to TestPyPI¶
Verify your TestPyPI release by installing it into a fresh virtual environment:
pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ tickertape-client
Step 4: Publish to Production PyPI¶
Once uploaded, the package will be immediately available at:
https://pypi.org/project/tickertape-client/