How to publish a package to PyPI
🐍

How to publish a package to PyPI

Tags
Python
Published
February 26, 2024
Author
Β 
We can use either declarative config file (pyproject.toml or olderΒ setup.cfg) or setup.py to configure the package. But it’s recommended to use declarative method to avoid executing arbitrary scripts and boilerplate code.
Β 
It is also recommended to maintain the project folder in src-layout, i.e., keep everything in a independent src folder, to avoid some unexpected errors.
project_root_directory β”œβ”€β”€ LICENSE β”œβ”€β”€ README.md β”œβ”€β”€ pyproject.toml β”œβ”€β”€ setup.py └── src/ └── your_package_name/ β”œβ”€β”€ __init__.py │── ... β”œβ”€β”€ module.py β”œβ”€β”€ subpkg1/ β”‚ β”œβ”€β”€ __init__.py β”‚ β”œβ”€β”€ ... └── subpkg2/ β”œβ”€β”€ __init__.py β”œβ”€β”€ ... └── module2.py
instead of flat-layout
project_root_directory β”œβ”€β”€ pyproject.toml # AND/OR setup.cfg, setup.py β”œβ”€β”€ ... └── your_package_name/ β”œβ”€β”€ __init__.py β”œβ”€β”€ ... β”œβ”€β”€ module.py β”œβ”€β”€ subpkg1/ β”‚ β”œβ”€β”€ __init__.py β”‚ β”œβ”€β”€ ... β”‚ └── module1.py └── subpkg2/ β”œβ”€β”€ __init__.py β”œβ”€β”€ ... └── module2.py
Β 
[build-system] requires = ["setuptools"] build-backend = "setuptools.build_meta" [project] name = "StreamDiffusionIO" version = "0.0.1" authors = [ {name = "Yihao (Ethan) Wang", email = "yihao.w@nyu.edu"}, ] description = "A light weight pipeline using StreamDiffusion, aimming to support streaming IO operations." readme = "README.md" keywords = ["diffusion", "stream"] license = {file = "LICENSE"} classifiers = [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.10", ] requires-python = ">=3.10" dependencies = [ "torch >= 2.2.0", "diffusers >= 0.26.3", "transformers >= 4.38.1", ] [project.optional-dependencies] xformers = ["xformers >= 0.0.24"] [project.urls] Repository = "https://github.com/AgainstEntropy/StreamDiffusionIO.git" [tool.setuptools] package-dir = {"" = "src"} [tool.setuptools.packages.find] where = ["src"] include = ["StreamDiffusionIO*"] namespaces = false
pyproject.toml
Β 
pip install -U build twine cd /path/to/your/project python -m build python -m twine upload --repository testpypi dist/* python -m twine upload [-r pypi] dist/*

References