Modules and Packages

Learning PathSkills: Packages, Modules, Import System, pip, PyPI, uv, __init__.py, Namespace Packages, __all__, PyInstaller

A person loading a large ship with shipping containers that represent Python packages

In this learning path, you’ll explore how Python’s import system works and how to structure your code using modules and packages. You’ll learn to manage project dependencies with pip and uv, evaluate third-party package quality, and publish your own packages to PyPI. Along the way, you’ll also cover namespace packages, zip imports, and creating README files for your projects.

Modules and Packages

Learning Path ⋅ 16 Resources

Understanding Modules and Packages

Start with the building blocks of Python code organization. You’ll see how a single file becomes a module and a directory becomes a package, what init.py does inside that directory, and how the if __name__ == "__main__" idiom decides whether a file runs as a script or gets imported. Getting these fundamentals right makes the import rules in the next section much easier to follow.

Title image for Python Modules and Packages: An Introduction (Python Best Practices Artwork)

Course

Python Modules and Packages: An Introduction

In this course, you'll explore Python modules and Python packages, two mechanisms that facilitate modular programming. See how to write and import modules so you can optimize the structure of your own programs and make them more maintainable.

Title image for Python Modules and Packages (Python Modules & Packages)

Interactive Quiz

Python Modules and Packages

Title image for What Does Python's __init__.py Do? (What Is Python's __init__.py For?)

Course

What Does Python's __init__.py Do?

Learn how Python's __init__.py declares packages, initializes variables, simplifies imports, and controls what gets exported.

Title image for What Does if __name__ == "__main__" Mean in Python? (What Does if __name__ == "__main__" Do in Python?)

Course

What Does if __name__ == "__main__" Mean in Python?

Learn all about Python's name-main idiom. You'll learn what it does in Python, how it works, when to use it, when to avoid it, and how to refer to it.

Title image for Python Name-Main Idiom (What Does if __name__ == "__main__" Do in Python?)

Interactive Quiz

Python Name-Main Idiom

Python's Import System

You’ve built a package, so now you’ll see how Python finds and loads it. You’ll compare absolute and relative imports, pick up advanced import techniques, control what a wildcard import exposes with all, and finish with namespace packages and zip imports. Knowing how the import machinery resolves names keeps a growing project working when you move files around.

Title image for Absolute vs Relative Imports in Python (Absolute vs Relative Imports in Python)

Course

Absolute vs Relative Imports in Python

If you've worked on a Python project that has more than one file, chances are you've had to use an import statement before. In this course, you'll not only cover the pros and cons of absolute and relative imports but also learn about the best practices for writing import statements.

Title image for Advanced Python import Techniques (Python import: Advanced Techniques and Tips)

Course

Advanced Python import Techniques

The Python import system is as powerful as it is useful. In this in-depth video course, you'll learn how to harness this power to improve the structure and maintainability of your code.

Title image for Managing Imports With Python's __all__ (Python's __all__: Packages, Modules, and Wildcard Imports)

Course

Managing Imports With Python's __all__

Learn how Python's dunder all variable controls wildcard imports and shapes the public API your packages and modules expose.

Title image for What's a Python Namespace Package, and What's It For? (What's a Python Namespace Package, and What's It For?)

Tutorial

What's a Python Namespace Package, and What's It For?

In this tutorial, you'll be exploring Python namespace packages: what they are, what they're for, and how you can use them in your package systems. Along the way, you'll create your own set of namespace packages and explore how you might be able to use them in your own projects.

Title image for Python Namespace Packages (What's a Python Namespace Package, and What's It For?)

Interactive Quiz

Python Namespace Packages

Title image for Python Zip Imports: Distribute Modules and Packages Quickly (Python Zip Imports: Distribute Modules and Packages Quickly)

Tutorial

Python Zip Imports: Distribute Modules and Packages Quickly

Learn what Zip imports are and how to use them in Python. You'll learn to create your own importable ZIP files and make them available for use. Finally, you'll learn how to use the zipimport module to dynamically import code from ZIP files.

Managing Dependencies

So far you’ve been importing your own code, but most projects also depend on code written by other people. Next, you’ll install and manage third-party packages with pip and uv, and keep those dependencies organized and reproducible across environments. You’ll also learn how to judge whether a package is worth depending on before you add it.

Title image for A Beginner's Guide to pip (What Is pip? A Guide for New Pythonistas)

Course

A Beginner's Guide to pip

What is pip? In this beginner-friendly course, you'll learn how to use pip, the standard package manager for Python, so that you can install and manage additional packages that are not part of the Python standard library.

Title image for uv vs pip: Python Packaging and Dependency Management (uv vs pip: Managing Python Packages and Dependencies)

Course

uv vs pip: Python Packaging and Dependency Management

Choosing between uv vs pip? This video course compares speed, reproducible environments, compatibility, and dependency management to help you pick the right tool.

Title image for Managing Python Dependencies (Managing Python Dependencies Course)

Course

Managing Python Dependencies

Get up to speed with Python dependency management quickly and go from “writing scripts” to “building applications” with this complete course.

Title image for How to Evaluate the Quality of Python Packages (How to Evaluate the Quality of Python Packages)

Tutorial

How to Evaluate the Quality of Python Packages

Just like you shouldn't download any file from the Internet, you shouldn't install third-party Python packages without evaluating them first. This tutorial will give you the tool set to evaluate the quality of external Python packages before you incorporate them into your Python projects.

Publishing and Distributing

You’ve been on the consuming end of PyPI, so now you’ll switch sides. You’ll publish a package of your own, bundle an application into a standalone executable with PyInstaller for users who don’t have Python installed, and write the README that tells people what your project does. A clear README is often the first thing a potential user reads, so it earns as much care as the code.

Title image for Publishing Python Packages to PyPI (How to Publish an Open-Source Python Package to PyPI)

Course

Publishing Python Packages to PyPI

In this video course, you’ll learn how to create a Python package for your project and how to publish it to PyPI, the Python Package Index. Quickly get up to speed on everything from naming your package to configuring it using setup.cfg.

Title image for Using PyInstaller to Easily Distribute Python Applications (Using PyInstaller to Easily Distribute Python Applications)

Tutorial

Using PyInstaller to Easily Distribute Python Applications

Learn how to use PyInstaller to turn your Python application into an executable with no dependencies or installation required. This is great if you want to distribute applications to users who may or may not be Python developers.

Title image for Creating Great README Files for Your Python Projects (Creating Great README Files for Your Python Projects)

Tutorial

Creating Great README Files for Your Python Projects

Learn how to create, organize, and format high-quality README files for your Python projects.

Test Your Knowledge

You’ve made it through the entire path! In the wrap-up quiz below, you’ll revisit the most important ideas about modules, packages, the import system, managing dependencies with pip and uv, and writing READMEs. Use it to spot any topics that still feel rusty before moving on.

Title image for Modules and Packages (A person loading a large ship with shipping containers that represent Python packages)

Interactive Quiz

Modules and Packages

Revisit Python modules, packages, the import system, pip, uv, and READMEs in this wrap-up quiz for the Modules and Packages path.

Congratulations on completing this learning path! You can now organize your code into modules and packages, work with Python’s import system, manage project dependencies with pip and uv, and package your own projects so other people can install them.

Ready to keep building your Python skills? Continue to the next learning path:

Learning Path

Object-Oriented Programming (OOP)

18 Resources ⋅ Skills: Python, OOP, Classes, Data Classes, Getters, Setters, Property, super(), Magic Methods, Operator Overloading, SOLID, Inheritance, Composition, Mixin Classes, Factory Pattern

You may also be interested in these related learning paths:

Got feedback on this learning path?

Looking for real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!

« Browse All Learning Paths