I've come to like and use this approach. Starting with your project structure, we will hide all the content of matrix_kit
that you don't want to show.
the_toolkit:
__init__.py
basic_io.py
simple_math.py
matrix_kit.py
...
Move matrix_kit.py
into a package with the same name, and place one underscore in the beginning of the module's name:
the_toolkit:
__init__.py
basic_io.py
simple_math.py
matrix_kit:
__init__.py
_matrix_kit.py
...
Now in _matrix_kit.py
add a global variable __all__ = [...]
listing the names of all functions/classes/variables you want to be visible. Then, add the following line to matrix_kit/__init__.py
:
from ._matrix_kit import *
It will only import the stuff listed in the __all__
attribute of the module. Then, while importing matrix_kit
like you've done before, you will actually import the __init__.py
and its content.