Skip to main content
Writing Python scripts for small experiments is one thing — building code you can maintain, share, and scale is another. Professional Python projects follow a set of conventions that make them predictable and portable: a consistent package structure, absolute imports, isolated virtual environments, and a single place where dependencies are declared. Learning these patterns now will save you significant debugging time as your projects grow, and will make your code immediately recognizable to any other Python developer who picks it up.

1. Modules and packages

  • Module — A single Python file (.py) containing functions, classes, and variables.
  • Package — A directory containing multiple modules and a special __init__.py file that marks it as a package.

Best practices for imports

Always use absolute imports. Relative imports (like from ..utils import db) are fragile — they break the moment you run a file as a standalone script rather than as part of a package. Use the full path from the project root instead:
Never use wildcard imports. from module import * silently pollutes your namespace and can overwrite existing names without any warning. Always import exactly what you need:

2. Virtual environments

A virtual environment is a self-contained directory with its own Python executable and its own installed packages. Every project should have one.

Why isolate environments?

By default, pip install installs packages globally. If Project A needs django==3.2 and Project B needs django==4.2, they can’t both be satisfied in a single global installation. Virtual environments solve this by giving each project its own isolated set of packages.

Creating and activating a virtual environment (standard)

Once activated, pip install adds packages only to .venv — your global Python is untouched.

Modern alternative: uv

uv is an ultra-fast Python package manager and virtual environment tool written in Rust. It serves as a drop-in replacement for pip and venv but runs 10–100× faster:
The next section of this course covers uv in depth, including how to use it to manage full projects with pyproject.toml and lock files.

What’s next?

Now that you’ve completed practical Python, let’s learn how to extend your programs using standard library modules and third-party packages.

Extending Python

Standard library and external package management