Publish Python SDKs manually
This guide covers publishing Python SDKs manually. For information on automating Python SDK publishing, see Publish Python SDKs automatically.
To share your generated Python SDK with the community, you can publish it to PyPI. This enables other developers to easily install it using the pip command. Follow the steps below to publish your SDK to PyPI.
Prerequisites
To publish your SDK to PyPI, you need the following:
- PyPI account (create at pypi.org).
- Twine installed:
pip install twine
Configure pyproject.toml
Ensure your SDK’s pyproject.toml is properly configured:
Publish your Python SDK to PyPI
To publish your SDK to PyPI, do the following:
-
Create PyPI account and API token:
- Register at pypi.org.
- Go to Account Settings > API tokens.
- Create a token with a scope of the entire account or specific project.
-
Configure the credentials. You can use Twine’s recommended method of storing credentials in
~/.pypirc: -
Build distribution packages:
This creates
dist/directory with:your-sdk-1.0.0.tar.gz(source distribution)your_sdk-1.0.0-py3-none-any.whl(wheel distribution)
-
Check the package:
-
Test on TestPyPI first (recommended):
-
Publish to PyPI:
-
Verify publication:
Publish updates
-
Update the version in
pyproject.toml:Alternatively, if using dynamic versioning, you can set up your
pyproject.tomlto read the version from your SDK package: -
Clean and rebuild:
Best practices for publishing Python SDKs
Use the following best practices when publishing your Python SDK to PyPI:
- Use semantic versioning (
MAJOR.MINOR.PATCH). - Test on TestPyPI before publishing to PyPI.
- Include a comprehensive
README.mdwith examples. - Add a
LICENSEfile. - Use type hints for better IDE support.
- Include a
py.typedfile for PEP 561 compliance. - Tag releases in Git:
git tag v1.0.0 && git push --tags. - Set up GitHub Actions for automated testing and publishing.
The following is an example GitHub Actions workflow (.github/workflows/publish.yml).