This guide will help you publish the RankVectors Python SDK to PyPI.
- PyPI Account: Create an account at https://pypi.org/account/register/
- API Token: Generate a PyPI API token at https://pypi.org/manage/account/token/
- Required Tools: Install build and twine
pip install build twine
cd sdk/python
./publish-pypi.shThe script will:
- Check prerequisites
- Clean previous builds
- Build the package (wheel and source distribution)
- Show you what will be uploaded
- Prompt for confirmation
- Upload to PyPI
-
Navigate to the Python SDK directory:
cd sdk/python -
Clean previous builds:
rm -rf dist/ build/ *.egg-info/ -
Build the package:
python -m build
-
Check the distribution files:
ls -lh dist/
-
Test the build (optional):
pip install dist/rankvectors-*.whl -
Upload to TestPyPI (recommended first):
twine upload --repository testpypi dist/* -
Test installation from TestPyPI:
pip install --index-url https://test.pypi.org/simple/ rankvectors
-
Upload to PyPI:
twine upload dist/*
You can authenticate in several ways:
export TWINE_USERNAME='__token__'
export TWINE_PASSWORD='pypi-your-token-here'
twine upload dist/*When prompted by twine, enter your PyPI username and password.
Create a file ~/.pypirc:
[pypi]
username = __token__
password = pypi-your-token-here-
Verify on PyPI: Visit https://pypi.org/project/rankvectors/
-
Test installation:
pip install --upgrade rankvectors
-
Verify functionality:
python -c "import rankvectors; print(rankvectors.__version__)"
To release a new version:
-
Update the version in:
setup.py(line 39)pyproject.toml(line 3)
-
Use semantic versioning (MAJOR.MINOR.PATCH):
- MAJOR: Breaking changes
- MINOR: New features, backward compatible
- PATCH: Bug fixes, backward compatible
-
Commit the changes:
git add setup.py pyproject.toml git commit -m "Bump version to X.Y.Z" git tag vX.Y.Z git push && git push --tags
If you're trying to upload a version that already exists:
- Update the version number
- Build and upload again
- Generate a new token at https://pypi.org/manage/account/token/
- Make sure you're using
__token__as the username
- Ensure
py.typedfile exists in the rankvectors package - Check that all source files are included in the build
- TestPyPI is a separate instance
- You need a separate account at https://test.pypi.org/
- Use
--repository testpypiflag
To automate publishing on each release:
- Add GitHub Actions workflow (
.github/workflows/publish.yml) - Store PyPI credentials as GitHub Secrets
- Trigger on git tags
Example workflow:
name: Publish to PyPI
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- run: pip install build twine
- run: cd sdk/python && python -m build
- run: twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}- PyPI Documentation: https://packaging.python.org/guides/distributing-packages-using-setuptools/
- Python Packaging Guide: https://packaging.python.org/
- Twine Documentation: https://twine.readthedocs.io/