PyPI · The Python Package Index
Packaging Python Projects — Python Packaging User Guide
To publish a Python package on GitHub Packages, follow these general steps:
Set up a GitHub repository: Create a new repository on GitHub or use an existing one to host your Python package.
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',
],
)
Create a README.md
file: Create a README.md
file that provides documentation and instructions for using your package.
Commit your code: Commit your setup.py
and README.md
files along with your package code to the repository.
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.
Push your code and tags: Push your code and tags to the remote repository (on GitHub).
Enable GitHub Packages: In your repository settings, enable GitHub Packages if it's not already enabled.
Publish your package: Use a package manager like twine
or setuptools
to publish your package to GitHub Packages. For example, using twine
:
twine
if you haven't already: pip install twine
python setup.py sdist bdist_wheel
twine upload --repository-url <https://pypi.org/simple/> dist/*
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.