> For clean Markdown content of this page, append .md to this URL. For the complete documentation index, see https://learning.postman.com/llms.txt. For full content including API reference and SDK examples, see https://learning.postman.com/llms-full.txt.

# Publish Python SDKs manually

This guide covers publishing Python SDKs manually. For information on automating Python SDK publishing, see [Publish Python SDKs automatically](/docs/sdk-generator/publish/python-auto/).

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](https://pypi.org/account/register/)).
* Twine installed: `pip install twine`

## Configure pyproject.toml

Ensure your SDK's `pyproject.toml` is properly configured:

```toml
[build-system]
requires = ["setuptools>=61.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "your-sdk"
version = "1.0.0"
description = "SDK for Your API"
readme = "README.md"
requires-python = ">=3.9"
license = {text = "MIT"}
authors = [
    {name = "Your Name", email = "your@email.com"}
]
keywords = ["api", "sdk", "your-api"]
classifiers = [
    "Development Status :: 5 - Production/Stable",
    "Intended Audience :: Developers",
    "License :: OSI Approved :: MIT License",
    "Programming Language :: Python :: 3",
    "Programming Language :: Python :: 3.9",
    "Programming Language :: Python :: 3.10",
    "Programming Language :: Python :: 3.11",
]

dependencies = [
    "requests>=2.31.0",
    "pydantic>=2.0.0",
]

[project.optional-dependencies]
dev = [
    "pytest>=7.0.0",
    "black>=23.0.0",
    "mypy>=1.0.0",
]

[project.urls]
Homepage = "https://github.com/your-org/your-sdk"
Documentation = "https://your-sdk.readthedocs.io"
Repository = "https://github.com/your-org/your-sdk"
"Bug Tracker" = "https://github.com/your-org/your-sdk/issues"

[tool.setuptools]
packages = ["your_sdk"]
package-dir = {"" = "src"}
```

## Publish your Python SDK to PyPI

To publish your SDK to PyPI, do the following:

1. Create PyPI account and API token:

   * Register at [pypi.org](https://pypi.org/account/register/).
   * Go to **Account Settings > API tokens**.
   * Create a token with a scope of the entire account or specific project.

2. Configure the credentials. You can use Twine's recommended method of storing credentials in `~/.pypirc`:

   ```ini
   [distutils]
   index-servers =
       pypi

   [pypi]
   username = __token__
   password = pypi-YOUR_API_TOKEN_HERE
   ```

3. Build distribution packages:

   ```bash
   # Install build tools
   pip install build twine

   # Build
   python -m build
   ```

   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)

4. Check the package:

   ```bash
   twine check dist/*
   ```

5. Test on TestPyPI first (recommended):

   ```bash
   # Upload to TestPyPI
   twine upload --repository testpypi dist/*

   # Install from TestPyPI to test
   pip install --index-url https://test.pypi.org/simple/ your-sdk
   ```

6. Publish to PyPI:

   ```bash
   twine upload dist/*
   ```

7. Verify publication:

   ```bash
   pip install your-sdk
   # Or visit: https://pypi.org/project/your-sdk/
   ```

## Publish updates

1. Update the version in `pyproject.toml`:

   ```toml
   version = "1.0.1"
   ```

   Alternatively, if using dynamic versioning, you can set up your `pyproject.toml` to read the version from your SDK package:

   ```toml
   [project]
   dynamic = ["version"]

   [tool.setuptools.dynamic]
   version = {attr = "your_sdk.__version__"}
   ```

2. Clean and rebuild:

   ```bash
   rm -rf dist/
   python -m build
   twine upload dist/*
   ```

## 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.md` with examples.
* Add a `LICENSE` file.
* Use type hints for better IDE support.
* Include a `py.typed` file 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`).

```yaml
name: Publish Python Package

on:
  release:
    types: [published]

jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.9'
      - name: Install dependencies
        run: |
          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/*
```