> ## Documentation Index
> Fetch the complete documentation index at: https://fastapi2day.codewithsiva.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Professional Python Project Handling Guidelines

> Learn professional conventions for modules, packages, absolute imports, virtual environments, and modern tooling with uv for every Python project.

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:

```python theme={null}
# Good — absolute import, always works
from myproject.utils import db

# Avoid — relative import, breaks in many contexts
from ..utils import db
```

**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:

```python theme={null}
# Good — explicit and clear
from math import sqrt, pi

# Avoid — unclear and risky
from math import *
```

***

## 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)

```bash theme={null}
# Create the environment
python -m venv .venv
```

<CodeGroup>
  ```bash macOS/Linux theme={null}
  # Activate
  source .venv/bin/activate
  ```

  ```powershell Windows theme={null}
  # Activate
  .venv\Scripts\Activate.ps1
  ```
</CodeGroup>

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:

```bash theme={null}
# Create a virtual environment instantly
uv venv

# Install packages
uv pip install requests pandas
```

<Tip>
  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.
</Tip>

***

## 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.

<Card title="Extending Python" icon="arrow-right" href="/advanced-python/working-with-data">
  Standard library and external package management
</Card>
