This document provides step-by-step instructions for building and publishing the pythonstl package to PyPI.
Install required tools:
pip install --upgrade pip
pip install build twineRemove any existing build artifacts:
# Windows PowerShell
Remove-Item -Recurse -Force dist, build, *.egg-info -ErrorAction SilentlyContinue
# Linux/Mac
rm -rf dist build *.egg-infoBuild both source distribution and wheel:
python -m buildThis creates:
dist/pythonstl-0.1.0.tar.gz(source distribution)dist/pythonstl-0.1.0-py3-none-any.whl(wheel)
Check the distribution files for errors:
twine check dist/*Expected output:
Checking dist/pythonstl-0.1.0-py3-none-any.whl: PASSED
Checking dist/pythonstl-0.1.0.tar.gz: PASSED
twine upload --repository testpypi dist/*You'll be prompted for credentials. Use:
- Username:
__token__ - Password: Your TestPyPI API token (starts with
pypi-)
Test the installation:
pip install --index-url https://test.pypi.org/simple/ pythonstlpython -c "from pythonstl import vector; v = vector(); v.push_back(1); print('✓ Installation successful')"twine upload dist/* -u __token__ -p YOUR_PYPI_API_TOKENSecurity Best Practices:
- Never commit API tokens to version control
- Store tokens in environment variables or password managers
- Use project-scoped tokens when possible
- Rotate tokens periodically
Set your token as an environment variable:
# Windows PowerShell
$env:TWINE_PASSWORD = "pypi-YOUR_TOKEN_HERE"
twine upload dist/* -u __token__
# Linux/Mac
export TWINE_PASSWORD="pypi-YOUR_TOKEN_HERE"
twine upload dist/* -u __token__Create ~/.pypirc:
[pypi]
username = __token__
password = pypi-YOUR_TOKEN_HEREWarning: Ensure .pypirc has restricted permissions (chmod 600 on Unix).
Then upload:
twine upload dist/*After successful upload:
- Visit https://pypi.org/project/pythonstl/
- Install from PyPI:
pip install pythonstl
- Test the installation:
from pythonstl import stack, queue, vector, stl_set, stl_map, priority_queue print("✓ All imports successful")
- Ensure
pyproject.tomlis valid - Check that all package directories have
__init__.py - Verify Python version >= 3.10
- 403 Forbidden: Check API token permissions
- 400 Bad Request: Package name may already exist
- File already exists: Version already published (increment version)
- Clear pip cache:
pip cache purge - Reinstall:
pip uninstall pythonstl && pip install pythonstl - Check for naming conflicts with other packages
For future releases:
- Update version in
pythonstl/__init__.py - Update version in
pyproject.toml - Create git tag:
git tag v0.1.1 - Rebuild and republish
Before publishing:
- No hardcoded secrets in code
- No sensitive data in examples
- LICENSE file included
- README.md is accurate
- All tests pass
- Version number is correct
- API token is secure
- Create GitHub release with changelog
- Update documentation
- Announce on relevant channels
- Monitor PyPI download stats
- Respond to issues and feedback
- PyPI: https://pypi.org/
- TestPyPI: https://test.pypi.org/
- Packaging Guide: https://packaging.python.org/
- Twine Documentation: https://twine.readthedocs.io/