Skip to main content

A friendly CLI tool to check and publish Python packages to TestPyPI/PyPI

Project description

๐Ÿš€ KHX-Publish-PyPI

PyPI version Python 3.9+ License: MIT Build Status Code Coverage

โœจ 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

From PyPI (Recommended)

pip install khx-publish-pypi

Installation Gif

Check the latest version:

khx-publish-pypi --version

From GitHub (Release or main)

  • Install from a tagged GitHub Release asset (requires download first):
    • Go to Releases, download the .whl or .tar.gz from 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
      
  • 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+
  • twine for uploads
  • build for package building
  • keyring for secure token storage

๐Ÿš€ Quick Start

  1. Install the package

    pip install khx-publish-pypi
    
  2. Set up your API tokens

    khx-publish-pypi setup-tokens
    
  3. 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

  1. TestPyPI Token: Generate at test.pypi.org
  2. 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.toml with project metadata
  • โœ… README.md file
  • โœ… LICENSE file
  • โœ… Package directory in src/ or root
  • โœ… Version defined in __version__.py or pyproject.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:

  1. Fork the repository
  2. Create a feature branch
    git checkout -b feature/amazing-feature
    
  3. Make your changes
  4. Run tests
    python -m pytest
    
  5. 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


Made with โค๏ธ by ABUELTAYEF Khader

โญ Star this repo โ€ข ๐Ÿ“ฆ View on PyPI โ€ข ๐Ÿ“ Blog

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

khx_publish_pypi-0.1.10.tar.gz (23.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

khx_publish_pypi-0.1.10-py3-none-any.whl (23.8 kB view details)

Uploaded Python 3

File details

Details for the file khx_publish_pypi-0.1.10.tar.gz.

File metadata

  • Download URL: khx_publish_pypi-0.1.10.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

Hashes for khx_publish_pypi-0.1.10.tar.gz
Algorithm Hash digest
SHA256 9a74662bc97d3eb770f529b7d00be11105c05a0793457fc185ff9c1a14e9b4a1
MD5 eeb8b806433b98972ce3bd3f05d6acf3
BLAKE2b-256 5fea6f13fd24fbbdee9db7b5ec60c85cadb88858b4a698aeafd4709021015856

See more details on using hashes here.

File details

Details for the file khx_publish_pypi-0.1.10-py3-none-any.whl.

File metadata

File hashes

Hashes for khx_publish_pypi-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 bef55104c67e896d312f27508df133123151e38f5da2b713ab07fa61ed8382f2
MD5 42fe5e9bb9f6898aa7dc4a08ec88ce35
BLAKE2b-256 c9e9c3e16bfa06fd580e63916dcaa1d17e5ae257e6ea17a880bba2221ededd84

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page