imptools
Tools for improving Python imports.
Installation
pip3 install imptools
Overview
import_path
Import a module from any path on the filesystem.
import imptools
my_module = imptools.import_path(
'../path/to/my_module', # Path to a module directory or single file.
notfound='error', # Raise 'error' or 'ignore' if not found.
reload=False, # Whether to import if already available.
)
import my_module # Import statement also works.
enable_relative
Enable relative imports for scripts that are not executed as module.
import imptools
imptools.enable_relative()
# Relative imports...
Tests
python3 -m pytest tests