This guide explains how to publish the mkdocs-header-dropdown plugin to PyPI.
- Install build tools:
pip install --upgrade build twine-
Create PyPI account:
- Go to https://pypi.org/account/register/
- Verify your email address
-
Create a PyPI API token:
- Go to https://pypi.org/manage/account/token/
- Create a new API token with scope "Entire account" or specific to this project
- Save the token securely (it will only be shown once)
Before publishing, update the version number in:
pyproject.toml(line 7)setup.py(line 8)
Follow semantic versioning (MAJOR.MINOR.PATCH):
- MAJOR: Breaking changes
- MINOR: New features (backward compatible)
- PATCH: Bug fixes
rm -rf dist/ build/ *.egg-infopython -m buildThis creates two distribution files in the dist/ directory:
.tar.gz(source distribution).whl(wheel distribution)
twine check dist/*Both files should pass validation.
Before publishing to the real PyPI, test on TestPyPI:
# Upload to TestPyPI
twine upload --repository testpypi dist/*When prompted:
- Username:
__token__ - Password: Your TestPyPI API token (starts with
pypi-)
Then test installation:
pip install --index-url https://test.pypi.org/simple/ mkdocs-header-dropdownOnce you're satisfied with the test:
twine upload dist/*When prompted:
- Username:
__token__ - Password: Your PyPI API token (starts with
pypi-)
Visit https://pypi.org/project/mkdocs-header-dropdown/ to see your published package.
Test installation:
pip install mkdocs-header-dropdownInstead of entering credentials each time, configure them in ~/.pypirc:
[pypi]
username = __token__
password = pypi-YOUR_API_TOKEN_HERE
[testpypi]
username = __token__
password = pypi-YOUR_TESTPYPI_TOKEN_HEREImportant: Keep this file secure and never commit it to version control!
Set proper permissions:
chmod 600 ~/.pypircThis repository includes automated GitHub Actions workflows in .github/workflows/:
The cd.yml workflow automatically:
- Builds the package on every push and PR (for testing)
- Publishes to PyPI when you create a GitHub release
This is the modern, secure way to publish to PyPI:
-
Add a new publisher with:
- PyPI Project Name:
mkdocs-header-dropdown - Owner:
cms-cat(your GitHub username/org) - Repository name:
mkdocs-header-dropdown - Workflow name:
cd.yml - Environment name:
release
- PyPI Project Name:
-
That's it! No API tokens needed.
- Go to your repository's Settings → Environments
- Create a new environment named
release - Add protection rules:
- Require reviewers (optional)
- Limit to specific branches (e.g.,
main)
When you're ready to publish:
# Update version in pyproject.toml and setup.py first!
# Commit and push changes
git add pyproject.toml setup.py
git commit -m "Bump version to 0.2.0"
git push
# Create and push a tag
git tag v0.2.0
git push origin v0.2.0
# Create a GitHub release
# Go to https://github.com/cms-cat/mkdocs-header-dropdown/releases/new
# Or use the GitHub CLI:
gh release create v0.2.0 --title "v0.2.0" --notes "Release notes here"The CD workflow will automatically:
- Build the distribution packages
- Verify them
- Publish to PyPI
If you prefer the traditional approach with API tokens:
-
Create a PyPI API token at https://pypi.org/manage/account/token/
-
Add it as a GitHub secret:
- Go to Settings → Secrets and variables → Actions
- Add a new repository secret named
PYPI_API_TOKEN - Paste your token
-
Modify
.github/workflows/cd.ymlto use token auth instead of trusted publishing (replace thepermissions: id-token: writesection with environment variables).
PyPI doesn't allow re-uploading the same version. You must increment the version number.
Make sure templates are properly included in the package by checking:
python -m zipfile -l dist/*.whl- Ensure you're using
__token__as the username (not your PyPI username) - Check that your API token hasn't expired
- Verify token permissions include upload rights
After publishing:
-
Create a git tag for the release:
git tag v0.1.0 git push origin v0.1.0
-
Create a GitHub release with release notes
-
Update the CHANGELOG.md file
-
Announce the release in relevant communities