This guide explains how to publish Palace to PyPI (Python Package Index).
-
PyPI Account: Create accounts on:
-
API Tokens: Generate API tokens for secure authentication:
- Go to Account Settings → API tokens
- Create a token with upload permissions
- Save it securely (you won't see it again)
-
Install Publishing Tools:
uv pip install twine
Build both source distribution and wheel:
# Clean previous builds
rm -rf dist/
# Build using uv (recommended)
uv build
# Or using python -m build (requires python3-venv on Debian/Ubuntu)
python -m buildThis creates:
dist/palace_ai-X.Y.Z.tar.gz(source distribution)dist/palace_ai-X.Y.Z-py3-none-any.whl(wheel)
Verify the package contents:
# Check the wheel contents
unzip -l dist/palace_ai-*.whl
# Verify package metadata
twine check dist/*Always test on TestPyPI before publishing to production:
# Upload to TestPyPI
twine upload --repository testpypi dist/*
# You'll be prompted for:
# - username: __token__
# - password: your TestPyPI API token (starts with pypi-)Test installation from TestPyPI:
# Create a test environment
python -m venv test_env
source test_env/bin/activate
# Install from TestPyPI
pip install --index-url https://test.pypi.org/simple/ palace-ai
# Test the installation
palace --help
pal --helpOnce tested, publish to production PyPI:
# Upload to PyPI
twine upload dist/*
# You'll be prompted for:
# - username: __token__
# - password: your PyPI API token (starts with pypi-)For automated publishing (GitHub Actions, etc.), use environment variables:
export TWINE_USERNAME=__token__
export TWINE_PASSWORD=pypi-your-api-token-here
twine upload dist/*Before publishing a new version:
-
Update version in
pyproject.toml:version = "0.2.0"
-
Update
VERSIONconstant inpalace.py:VERSION = "0.2.0"
-
Create a git tag:
git tag -a v0.2.0 -m "Release version 0.2.0" git push origin v0.2.0 -
Rebuild and publish:
rm -rf dist/ uv build twine check dist/* twine upload dist/*
After publishing:
- Verify on PyPI: https://pypi.org/project/palace-ai/
- Test installation:
pip install palace-ai - Update GitHub release notes
- Announce on relevant channels
- You cannot overwrite existing versions on PyPI
- Increment the version number and rebuild
- Check that
palace.pyhas proper module structure - Verify
__name__ == "__main__"block for CLI entry point
- Check
MANIFEST.inincludes all necessary files - Verify
pyproject.tomlhas correct include/exclude patterns - Use
twine check dist/*to validate
- Ensure you're using
__token__as username (not your PyPI username) - Verify API token has upload permissions
- Check token hasn't expired
- Never commit API tokens to version control
- Use environment variables for tokens in CI/CD
- Rotate tokens regularly (at least annually)
- Use scoped tokens (limit to specific projects when possible)
- Enable 2FA on your PyPI account