PyPi package

Python packages

Python packages are distributed via PyPI in two main formats:

  • Wheel (.whl) – prebuilt, faster installation

  • Source distribution (.tar.gz) – contains all source code

Folder structure

<package-name>/<package-name>.py

.gitignore

pyproject.toml

For the wheel creation (dist/*.whl):

where:

  • <package-name> is the name of the package you created

  • [tool.setuptools.package-data] defines which other data folders/files are packaged

  • [project.scripts] is used to function to be called when the script runs. This ensures that python -m should not be specified before the name of the script to run it.

MANIFEST.in

For the Source dist creation (dist/*.tar.gz):

Setup the machine

Package creation

  • Create the package

Command

Description

python -m build --wheel

Build only a wheel

python -m build --sdist

Build only a source distribution

python -m build --outdir dist/

Change output dir of the build process

python -m build --no-isolation

Disable isolated build environment (not recommended for release)

python -m build --python python3.10

Specify Python executable

Verify the package content

  • Unpack the wheel

  • Extract the Source dist

Install the package

  • Install the package locally to test it

  • If you need to upgrade it

Package upload

Enter your PyPI username + password/token.

Package uninstall

Last updated