Git Bash

GitHub


PyPI · The Python Package Index

Packaging Python Projects — Python Packaging User Guide

Search results

6. Modules



Publishing Through GitHub

To publish a Python package on GitHub Packages, follow these general steps:

  1. Set up a GitHub repository: Create a new repository on GitHub or use an existing one to host your Python package.

  2. Create a setup.py file: In your repository, create a setup.py file that defines the metadata and dependencies for your package. This file should contain information such as the package name, version, author, and dependencies. Here's a basic example:

    from setuptools import setup
    
    setup(
        name='your-package-name',
        version='0.1.0',
        author='Your Name',
        packages=['your_package'],
        install_requires=[
            'dependency1',
            'dependency2',
        ],
    )
    
  3. Create a README.md file: Create a README.md file that provides documentation and instructions for using your package.

  4. Commit your code: Commit your setup.py and README.md files along with your package code to the repository.

  5. Tag a release: Create a Git tag for the version of your package you want to publish. This tag should match the version specified in your setup.py file.

  6. Push your code and tags: Push your code and tags to the remote repository (on GitHub).

  7. Enable GitHub Packages: In your repository settings, enable GitHub Packages if it's not already enabled.

  8. Publish your package: Use a package manager like twine or setuptools to publish your package to GitHub Packages. For example, using twine:

    1. Install twine if you haven't already: pip install twine
    2. Build your package distribution files: python setup.py sdist bdist_wheel
    3. Upload your package to GitHub Packages: twine upload --repository-url <https://pypi.org/simple/> dist/*
  9. Verify the publication: Visit your repository's GitHub Packages page to verify that your package is published and accessible.

That's it! Your Python package should now be published on GitHub Packages and available for installation and distribution. Remember to update your setup.py file and create new releases whenever you make changes or add new versions to your package.