How to structure, package, and distribute your own Python application
Packaging allows you to share your Python code with others, install it on different systems, or publish it to PyPI. A well‑structured project is easier to maintain, test, and extend.
A typical Python project layout looks like this:
myproject/
myproject/
__init__.py
core.py
tests/
test_core.py
README.md
pyproject.toml
LICENSE
# myproject/core.py
def greet(name):
return f"Hello, {name}!"
This file marks the folder as a Python package:
# myproject/__init__.py
from .core import greet
This file defines metadata and build settings for your package:
[project]
name = "myproject"
version = "0.1.0"
description = "A simple example project"
authors = [{name = "Your Name"}]
[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"
A README.md explains what your project does and how to use it.
Use the build tool:
pip install build
python -m build
This creates:
pip install dist/myproject-0.1.0-py3-none-any.whl
Upload using twine:
pip install twine
twine upload dist/*
Follow semantic versioning:
Now that you can build and package a Python project, you're ready to explore how to distribute applications in Lesson 21: Creating Executable Applications.
← Back to Lesson Index