LEGB Namespaces & Package Namespaces Differences

Namespace Packages in Python (Explicit vs Implicit)

In addition to runtime namespaces (Local, Enclosing, Global, Built-in), Python also has the concept of namespace packages, which relate to how modules and sub-packages are organized on disk.

Implicit Namespace Package

A namespace package allows you to spread a single Python package across multiple directories or distributions. This is especially useful for large frameworks or plugin systems.

Explicit Namespace Package

An explicit namespace package uses an __init__.py file to mark a directory as a Python package. This traditional method supports:

please refer to the Understanding __init__ in Packages for more details on implicit and explicit namespace packages.

How Is This Different from LEGB Namespaces?

So, while runtime namespaces map names to objects in memory, package namespaces organize modules and their availability in your file system.