This guide explains how to publish the Apiframe Python SDK to PyPI.
- A PyPI account (create one at pypi.org)
- PyPI API token (recommended) or username/password
- Install required tools:
pip install build twineBefore publishing, ensure:
- All tests pass (
pytest) - Code is properly formatted (
black,isort) - Type checking passes (
mypy) - Linting passes (
flake8) - Version number is updated in
pyproject.toml - CHANGELOG.md is updated with changes
- README.md is up to date
- Examples are working and tested
- Documentation is complete
We follow Semantic Versioning:
- MAJOR version: Incompatible API changes
- MINOR version: Add functionality in a backward compatible manner
- PATCH version: Backward compatible bug fixes
Update the version in pyproject.toml:
[project]
version = "1.0.0" # Update this- Clean previous builds:
rm -rf dist/ build/ *.egg-info- Build the distribution packages:
python -m buildThis creates two files in the dist/ directory:
- A source distribution (.tar.gz)
- A wheel (.whl)
Before uploading to PyPI, test the build locally:
# Install in a fresh virtual environment
python -m venv test_env
source test_env/bin/activate # On Windows: test_env\Scripts\activate
# Install the built package
pip install dist/apiframe-1.0.0-py3-none-any.whl
# Test basic import
python -c "from apiframe import Apiframe; print('Import successful')"
# Deactivate and clean up
deactivate
rm -rf test_envBefore publishing to the main PyPI, test on TestPyPI:
-
Create an account at test.pypi.org
-
Upload to TestPyPI:
python -m twine upload --repository testpypi dist/*- Test installation from TestPyPI:
pip install --index-url https://test.pypi.org/simple/ --no-deps apiframeOnce you've verified everything works on TestPyPI:
- Upload to PyPI:
python -m twine upload dist/*You'll be prompted for your PyPI credentials or API token.
- Verify the upload:
Visit pypi.org/project/apiframe-sdk/ to see your package.
- Test installation:
pip install apiframe-sdkFor security, use an API token instead of username/password:
-
Generate a token at pypi.org/manage/account/token/
-
Create or update
~/.pypirc:
[pypi]
username = __token__
password = pypi-YOUR_TOKEN_HERE
[testpypi]
username = __token__
password = pypi-YOUR_TOKEN_HERE- Set appropriate permissions:
chmod 600 ~/.pypircYou can automate publishing using GitHub Actions. Create .github/workflows/publish.yml:
name: Publish to PyPI
on:
release:
types: [created]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
- name: Build package
run: python -m build
- name: Publish to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
run: twine upload dist/*Add your PyPI API token as a GitHub secret named PYPI_API_TOKEN.
After publishing:
-
Create a GitHub release:
- Tag:
v1.0.0(matching the version) - Title: "Release 1.0.0"
- Description: Copy from CHANGELOG.md
- Tag:
-
Update documentation:
- Ensure docs.apiframe.ai reflects the new version
- Update any external documentation or blog posts
-
Announce the release:
- Social media
- Email newsletter
- Community forums
PyPI doesn't allow re-uploading the same version. You must:
- Increment the version number
- Rebuild the package
- Upload again
- Check that all dependencies are listed in
pyproject.toml - Ensure
__init__.pyfiles are in all package directories - Verify the package structure is correct
Check MANIFEST.in to ensure all necessary files are included.
Keep track of published versions:
- 1.0.0 - Initial release (2024-10-10)
For publishing issues:
- PyPI help: https://pypi.org/help/
- GitHub Issues: https://github.com/apiframe-ai/apiframe-python-sdk/issues