python-package-quickstart

Python Packages Tutorial 🐍 πŸ“¦

A simple template for a Python project that can be installed with pip - includes docs and tutorial

Go to source code:

MichaelCurrin - python-package-quickstart

About

This project is a quick reference, tutorial and demo for making a Python project installable using the pip install PACKAGE command. For full details, see the linked resources.

Resources

Official docs

Other

Source Distributions vs Wheels

From pip docs

pip can install from either Source Distributions (sdist) or Wheels, but if both are present on PyPI, pip will prefer a compatible wheel.

Wheels are a pre-built distribution format that provides faster installation compared to Source Distributions (sdist), especially when a project contains compiled extensions.

If pip does not find a wheel to install, it will locally build a wheel and cache it for future installs, instead of rebuilding the source distribution in the future.

Guide

What you’ll get at the end of this tutorial

Note on publishing:

Typical structure

Here the repo or cloned folder is sample-project with a hyphen.

Inside the repo is sampleproject which may not have a hyphen (otherwise you can’t import it as package) and using an underscore is discouraged. See PEP-8.

sample-project
  sampleproject/
    foo/
      __init__.py
    __init__.py
    sampleproject.py
  tests/
  setup.py
  LICENSE
  README.md

Note that a directory and a script are both considered a β€œmodule” in Python, if it can be imported.

Init file

See init file tutorial page.

Main file

See main file tutorial page.

A main file is a script or an entrypoint to be run directly, but it might be considered a module if you import it from elsewhere. A convention is that this main script matches package name as in the example. You can also make it __main__.py.

Intra-package references

See section of tutorial.

from . import echo
from .. import formats
from ..filters import equalizer

This does not work in the main module.