|
| 1 | +# Publishing to PyPI with uv |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +- ✅ PyPI account (you have this) |
| 6 | +- ✅ `uv` installed |
| 7 | +- ✅ PyPI API token (or username/password) |
| 8 | + |
| 9 | +## Step 1: Get PyPI API Token (Recommended) |
| 10 | + |
| 11 | +1. Go to [https://pypi.org/manage/account/token/](https://pypi.org/manage/account/token/) |
| 12 | +2. Click "Add API token" |
| 13 | +3. Name: `lumen-python-sdk` |
| 14 | +4. Scope: Choose "Entire account" or create project-specific after first upload |
| 15 | +5. Copy the token (starts with `pypi-`) |
| 16 | + |
| 17 | +## Step 2: Configure uv with PyPI Credentials |
| 18 | + |
| 19 | +```bash |
| 20 | +# Option A: Set environment variable (recommended for CI/CD) |
| 21 | +export UV_PUBLISH_TOKEN="pypi-your-token-here" |
| 22 | + |
| 23 | +# Option B: uv will prompt you during publish |
| 24 | +# Just have your token ready |
| 25 | +``` |
| 26 | + |
| 27 | +## Step 3: Pre-Publishing Checklist |
| 28 | + |
| 29 | +```bash |
| 30 | +cd /Users/prasoon/work/lumen-python-sdk |
| 31 | + |
| 32 | +# 1. Verify package name is available |
| 33 | +# Search: https://pypi.org/search/?q=lumen-python-sdk |
| 34 | + |
| 35 | +# 2. Clean old builds |
| 36 | +rm -rf dist/ build/ *.egg-info |
| 37 | + |
| 38 | +# 3. Update version if needed (already at 0.1.0) |
| 39 | +# Edit pyproject.toml if you want to change version |
| 40 | + |
| 41 | +# 4. Verify pyproject.toml is correct |
| 42 | +cat pyproject.toml | grep -E "name|version|description" |
| 43 | +``` |
| 44 | + |
| 45 | +## Step 4: Build the Package |
| 46 | + |
| 47 | +```bash |
| 48 | +# Build both wheel and source distribution |
| 49 | +uv build |
| 50 | + |
| 51 | +# This creates: |
| 52 | +# dist/lumen_python_sdk-0.1.0-py3-none-any.whl |
| 53 | +# dist/lumen-python-sdk-0.1.0.tar.gz |
| 54 | +``` |
| 55 | + |
| 56 | +## Step 5: Test the Build (Optional but Recommended) |
| 57 | + |
| 58 | +```bash |
| 59 | +# Install from local build to test |
| 60 | +uv pip install dist/lumen_python_sdk-0.1.0-py3-none-any.whl |
| 61 | + |
| 62 | +# Test import |
| 63 | +uv run python -c "import lumen; print(lumen.__version__)" |
| 64 | + |
| 65 | +# Uninstall test |
| 66 | +uv pip uninstall lumen-python-sdk |
| 67 | +``` |
| 68 | + |
| 69 | +## Step 6: Publish to PyPI |
| 70 | + |
| 71 | +```bash |
| 72 | +# Publish to PyPI |
| 73 | +uv publish |
| 74 | + |
| 75 | +# You'll be prompted for: |
| 76 | +# - Username: __token__ |
| 77 | +# - Password: pypi-your-token-here (paste your API token) |
| 78 | +``` |
| 79 | + |
| 80 | +### If Using Environment Variable |
| 81 | + |
| 82 | +```bash |
| 83 | +# Set token |
| 84 | +export UV_PUBLISH_TOKEN="pypi-your-token-here" |
| 85 | + |
| 86 | +# Publish (no prompt) |
| 87 | +uv publish |
| 88 | +``` |
| 89 | + |
| 90 | +## Step 7: Verify on PyPI |
| 91 | + |
| 92 | +1. Check your package: [https://pypi.org/project/lumen-python-sdk/](https://pypi.org/project/lumen-python-sdk/) |
| 93 | +2. Test installation: |
| 94 | + |
| 95 | +```bash |
| 96 | +# In a new directory |
| 97 | +uv pip install lumen-python-sdk |
| 98 | +uv run python -c "import lumen; print(lumen.__version__)" |
| 99 | +``` |
| 100 | + |
| 101 | +## Publishing Updates |
| 102 | + |
| 103 | +When you have changes to publish: |
| 104 | + |
| 105 | +```bash |
| 106 | +# 1. Update version in pyproject.toml |
| 107 | +# Change: version = "0.1.1" |
| 108 | + |
| 109 | +# 2. Update CHANGELOG.md |
| 110 | + |
| 111 | +# 3. Commit changes |
| 112 | +git add . |
| 113 | +git commit -m "Release v0.1.1" |
| 114 | +git tag v0.1.1 |
| 115 | +git push && git push --tags |
| 116 | + |
| 117 | +# 4. Clean and rebuild |
| 118 | +rm -rf dist/ |
| 119 | +uv build |
| 120 | + |
| 121 | +# 5. Publish |
| 122 | +uv publish |
| 123 | +``` |
| 124 | + |
| 125 | +## Troubleshooting |
| 126 | + |
| 127 | +### "File already exists" |
| 128 | + |
| 129 | +You're trying to upload the same version. Bump the version in `pyproject.toml`. |
| 130 | + |
| 131 | +### "Invalid credentials" |
| 132 | + |
| 133 | +- Verify your API token is correct |
| 134 | +- Use `__token__` as username, not your PyPI username |
| 135 | +- Token should start with `pypi-` |
| 136 | + |
| 137 | +### "Package name already taken" |
| 138 | + |
| 139 | +Someone else owns `lumen-python-sdk`. Options: |
| 140 | + |
| 141 | +1. Contact PyPI support if you own the trademark |
| 142 | +2. Choose a different name like `lumen-sdk-python` or `getlumen` |
| 143 | + |
| 144 | +### Build fails |
| 145 | + |
| 146 | +```bash |
| 147 | +# Install build dependencies |
| 148 | +uv pip install hatchling |
| 149 | + |
| 150 | +# Try building again |
| 151 | +uv build |
| 152 | +``` |
| 153 | + |
| 154 | +## Quick Reference |
| 155 | + |
| 156 | +```bash |
| 157 | +# Complete workflow |
| 158 | +cd /Users/prasoon/work/lumen-python-sdk |
| 159 | +rm -rf dist/ |
| 160 | +uv build |
| 161 | +uv publish |
| 162 | +``` |
| 163 | + |
| 164 | +## TestPyPI (For Testing) |
| 165 | + |
| 166 | +Test your package on TestPyPI first: |
| 167 | + |
| 168 | +```bash |
| 169 | +# Build |
| 170 | +uv build |
| 171 | + |
| 172 | +# Publish to TestPyPI |
| 173 | +uv publish --publish-url https://test.pypi.org/legacy/ |
| 174 | + |
| 175 | +# Install from TestPyPI to test |
| 176 | +uv pip install --index-url https://test.pypi.org/simple/ lumen-python-sdk |
| 177 | +``` |
| 178 | + |
| 179 | +## Automation (GitHub Actions) |
| 180 | + |
| 181 | +Add to `.github/workflows/publish.yml`: |
| 182 | + |
| 183 | +```yaml |
| 184 | +name: Publish to PyPI |
| 185 | + |
| 186 | +on: |
| 187 | + release: |
| 188 | + types: [published] |
| 189 | + |
| 190 | +jobs: |
| 191 | + publish: |
| 192 | + runs-on: ubuntu-latest |
| 193 | + steps: |
| 194 | + - uses: actions/checkout@v3 |
| 195 | + |
| 196 | + - name: Install uv |
| 197 | + uses: astral-sh/setup-uv@v1 |
| 198 | + |
| 199 | + - name: Build package |
| 200 | + run: uv build |
| 201 | + |
| 202 | + - name: Publish to PyPI |
| 203 | + env: |
| 204 | + UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }} |
| 205 | + run: uv publish |
| 206 | +``` |
| 207 | +
|
| 208 | +Then add `PYPI_TOKEN` to GitHub repository secrets. |
| 209 | + |
| 210 | +## Package URLs After Publishing |
| 211 | + |
| 212 | +- PyPI Page: https://pypi.org/project/lumen-python-sdk/ |
| 213 | +- Install: `uv pip install lumen-python-sdk` |
| 214 | +- Docs: https://github.com/getlumen/lumen-python-sdk |
| 215 | + |
| 216 | +## Version Strategy |
| 217 | + |
| 218 | +Follow semantic versioning: |
| 219 | + |
| 220 | +- `0.1.0` - Initial release |
| 221 | +- `0.1.1` - Bug fixes |
| 222 | +- `0.2.0` - New features (backward compatible) |
| 223 | +- `1.0.0` - Production ready, stable API |
| 224 | + |
| 225 | +--- |
| 226 | + |
| 227 | +Need help? Check [uv docs](https://docs.astral.sh/uv/) or reach out! |
0 commit comments