A friendly CLI tool to check and publish Python packages to TestPyPI/PyPI
Project description
๐ KHX-Publish-PyPI
โจ A beautiful, user-friendly CLI tool to streamline Python package publishing to PyPI and TestPyPI
KHX-Publish-PyPI is an interactive command-line interface that simplifies the entire process of preparing, building, and publishing Python packages. With rich visual feedback, intelligent error handling, and secure token management, it makes package publishing as smooth as a breeze.
๐ Features
- ๐จ Beautiful Interface: Rich, colorful output with progress bars and interactive prompts
- ๐ Smart Pre-checks: Validates your package structure, version, and configuration before publishing
- ๐ Secure Token Management: Stores API tokens securely using your system's keyring
- ๐ฆ One-Command Publishing: Complete workflow from checks to upload in a single command
- ๐งช TestPyPI Support: Publish to TestPyPI first for safe testing
- ๐ Version Management: Automatic version bumping with semantic versioning
- ๐ ๏ธ Error Intelligence: Provides specific suggestions when uploads fail
- ๐ CI/CD Ready: Perfect for automated publishing pipelines
๐ธ Screenshots
Installation
Interactive Publishing Workflow
Complete guided publishing workflow showing checks, token setup, version bumping, and publishing
CLI Interface Examples
Available CLI commands and options
Automated validation of package structure and requirements
๐ ๏ธ Installation
From PyPI (Recommended)
pip install khx-publish-pypi
From GitHub (Release or main)
- Install from a tagged GitHub Release asset (requires download first):
- Go to Releases, download the
.whlor.tar.gzfrom assets, then:pip install path/to/khx_publish_pypi-<version>-py3-none-any.whl # or pip install path/to/khx_publish_pypi-<version>.tar.gz
- Go to Releases, download the
- Or install directly from the repo using pipโs VCS support:
# specific tag pip install git+https://github.com/Khader-X/khx-publish-pypi.git@vX.Y.Z#egg=khx_publish_pypi # latest on default branch pip install git+https://github.com/Khader-X/khx-publish-pypi.git@main#egg=khx_publish_pypi
From Source (Development)
git clone https://github.com/Khader-X/khx-publish-pypi.git
cd khx-publish-pypi
pip install -e .
Requirements
- Python 3.9+
twinefor uploadsbuildfor package buildingkeyringfor secure token storage
๐ Quick Start
-
Install the package
pip install khx-publish-pypi
-
Set up your API tokens
khx-publish-pypi setup-tokens -
Publish your package
khx-publish-pypi run
That's it! The guided workflow will handle everything else.
๐ Usage
Interactive Publishing (Recommended)
khx-publish-pypi run
This command provides a complete guided experience:
- โ Runs pre-publish checks
- ๐ Manages API token configuration
- ๐ Offers version bumping options
- ๐๏ธ Builds your package distributions
- ๐ค Publishes to TestPyPI and/or PyPI
Individual Commands
# Run pre-publish checks
khx-publish-pypi check
# Bump version
khx-publish-pypi bump patch
# Publish to TestPyPI only
khx-publish-pypi publish-test
# Publish to PyPI only
khx-publish-pypi publish-prod
๐ CLI Commands
| Command | Description |
|---|---|
khx-publish-pypi --version |
Show CLI version |
khx-publish-pypi check |
Run interactive pre-publish checks |
khx-publish-pypi bump [patch|minor|major] |
Bump package version |
khx-publish-pypi setup-tokens |
Configure API tokens interactively |
khx-publish-pypi update-tokens |
Update existing tokens |
khx-publish-pypi run |
Complete guided publishing workflow |
khx-publish-pypi publish-test |
Publish to TestPyPI |
khx-publish-pypi publish-prod |
Publish to PyPI |
Command Options
Token Setup
# Interactive setup
khx-publish-pypi setup-tokens
# Non-interactive setup
khx-publish-pypi setup-tokens --test-token YOUR_TEST_TOKEN --prod-token YOUR_PROD_TOKEN
Version Bumping
khx-publish-pypi bump patch # 1.0.0 โ 1.0.1
khx-publish-pypi bump minor # 1.0.1 โ 1.1.0
khx-publish-pypi bump major # 1.1.0 โ 2.0.0
โ๏ธ Configuration
API Tokens
KHX-Publish-PyPI securely stores your PyPI API tokens using your system's keyring:
- TestPyPI: Stored as
khx-publish-testpypi - PyPI: Stored as
khx-publish-pypi
Getting API Tokens
- TestPyPI Token: Generate at test.pypi.org
- PyPI Token: Generate at pypi.org
Environment Variables (Alternative)
You can also provide tokens via environment variables:
export TESTPYPI_TOKEN=your_test_token
export PYPI_TOKEN=your_prod_token
Package Requirements
Your Python package must have:
- โ
pyproject.tomlwith project metadata - โ
README.mdfile - โ
LICENSEfile - โ
Package directory in
src/or root - โ
Version defined in
__version__.pyorpyproject.toml
๐ง Troubleshooting
Common Issues
โ Upload Fails with 400 Error
Cause: Package version already exists on PyPI Solution: Bump the version
khx-publish-pypi bump patch
โ Authentication Failed (403)
Cause: Invalid or expired API token Solution: Reconfigure tokens
khx-publish-pypi setup-tokens
โ Build Fails
Cause: Missing build dependencies or invalid pyproject.toml
Solution: Install build tools and validate configuration
pip install build twine
python -m build --help
โ Token Storage Issues
Cause: Keyring not available or corrupted Solution: Use environment variables or reinstall keyring
pip uninstall keyring
pip install keyring
Debug Mode
Enable verbose output for troubleshooting:
khx-publish-pypi run --verbose
๐ค Contributing
We welcome contributions! Here's how to get started:
- Fork the repository
- Create a feature branch
git checkout -b feature/amazing-feature
- Make your changes
- Run tests
python -m pytest
- Submit a pull request
Development Setup
git clone https://github.com/Khader-X/khx-publish-pypi.git
cd khx-publish-pypi
pip install -e ".[dev]"
Code Style
- Follow PEP 8
- Use type hints
- Write docstrings for all functions
- Add tests for new features
๐ CI/CD Integration
KHX-Publish-PyPI works great with CI/CD pipelines:
# GitHub Actions example
- name: Publish to PyPI
run: |
khx-publish-pypi setup-tokens --test-token ${{ secrets.TEST_PYPI_TOKEN }} --prod-token ${{ secrets.PYPI_TOKEN }}
khx-publish-pypi publish-prod
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with Click for CLI magic
- Beautiful output powered by Rich
- Secure token storage via Keyring
- Package building with Build
- Uploads handled by Twine
๐ Support
- ๐ง Email: abueltayef.khader@gmail.com
- ๐ Issues: GitHub Issues
- ๐ Documentation: GitHub Wiki
- ๐ฌ Discussions: GitHub Discussions
Made with โค๏ธ by ABUELTAYEF Khader
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file khx_publish_pypi-0.1.9.tar.gz.
File metadata
- Download URL: khx_publish_pypi-0.1.9.tar.gz
- Upload date:
- Size: 23.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
31135ce63f9dde10d3eb34b6978374c3c5f09f99cf0955a0526726fc9868410a
|
|
| MD5 |
9eb0e2121abcbcd5c5410bf1872c7349
|
|
| BLAKE2b-256 |
9bcb63c1cddae29f7ecdc7a8dbd32662d2dbcc517122e8ecf89c26b8971824d4
|
File details
Details for the file khx_publish_pypi-0.1.9-py3-none-any.whl.
File metadata
- Download URL: khx_publish_pypi-0.1.9-py3-none-any.whl
- Upload date:
- Size: 23.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bcc95b839a1b59044914e36ef0e5dd709e11dba3357a6b411e92fdc6be9d4bfd
|
|
| MD5 |
cba87476baec9b7e1cab7b760c5f49a3
|
|
| BLAKE2b-256 |
d0b5a1488ad5f8225614ed2c51f72139b09529be096ea4df1644d18ab8ea5456
|