Low Orbit Flux Logo 2 F

Python - Packages



Example layout:

tools/                    package - top level
    __init__.py           init package
    data/                 subpackage
        __init__.py       init
        analytics.py      module
        crud.py           module

    web/                  subpackage
        __init__.py       init
        scrape.py         module
        capture.py        module
        filter.py         module

Import submodules:

import tools.data.crud

Import so that we can specify the submodule directly:

from tools.data import crud

Import the function directly:

from tools.data.crud import search


Importing * From a Package

from tools.web import *   # import tools.web and run init code ( needs __all__ to import submodules )

all which submodules to import when using wildcard

all = [“scrape”, “capture”, “filter”]

__all__ = [


import tools.web.scrape
import tools.web.capture
from tools.web import *

Intra-package References

“you can use absolute imports to refer to submodules of siblings packages”

This module:


Can run:

tools.data import crud

Can also use relative imports:

from . import scrape
from .. import data
from ..data import crud

path also exists and can be used to change where subpackages and modules are searched for