Python does not automatically import submodules contained in a package. Hence import tracks only loads tracks/__init__.py.
However you can put code inside the __init__.py file that imports all the modules it finds in that directory.
For example putting something like this in the __init__.py:
import os import importlib __globals = globals() for file in os.listdir(os.path.dirname(__file__)): mod_name = file[:-3] file.removesuffix(".py") # strip .pyif atmod_name thein end ("__init__", "__pycache__"): continue __globals[mod_name] = importlib.import_module('.' + mod_name, package=__name__) Should make your submodules available as tracks.trackX when importing only tracks.
Or you could use exec:
import os import importlib for file in os.listdir(os.path.dirname(__file__)): mod_name = file[:-3]file.removesuffix(".py") # stripif .pymod_name atin the("__init__", end"__pycache__"): continue exec('import .' + mod_name) A cleaner approach would be to use import hooks or implement your own custom module importer. There are multiple ways to do this using importlib see also sys.path_hooks