logiqub importer

Description

This is a single function named import_ that provides an alternative to Python's import statement.

Why ? Because Python's module system is broken:

This function imports a module based on its path, without exposing internals. as isn't supported, you can use an assignment instead.

Installation

git clone

You can get the source and install manually. For example:

# Get the source
mkdir $HOME/tools
cd $HOME/tools
git clone https://logiqub.org/logiqub_importer.git

# Install for your project's virtual environment
cd <project>
python3 -m venv venv
source venv/bin/activate
pip install $HOME/tools/logiqub_importer

pip install

You can also add https://logiqub.org/python/index/ to pip.

pip install --extra-index-url https://logiqub.org/python/index/ logiqub_importer

To add this Python package index permanently, you can edit pip.conf, which has numerous locations. They are checked in the following order:

$ pip config -v list
For variant 'global', will try loading '/etc/xdg/pip/pip.conf'
For variant 'global', will try loading '/etc/pip.conf'
For variant 'user', will try loading '$HOME/.pip/pip.conf'
For variant 'user', will try loading '$HOME/.config/pip/pip.conf'
For variant 'site', will try loading '$VIRTUAL_ENV/pip.conf'

And then, you can use either the [global] or [install] section (pip documentation - configuration)

[global]
extra-index-url =
    https://logiqub.org/python/index/

[install]
extra-index-url =
    https://logiqub.org/python/index/

Usage

Put import logiqub.importer in the file where your entry point resides. This adds the import_ function to Python builtins. Python builtins are functions such as len, str, repr, or sum. That makes import_ available from anywhere, so that you don't have to write from logiqub.importer import import_ in every file that uses it.

# Add import_ to builtins
import logiqub.importer

# Module
import module
import_("module.py")

# Class and variable
from module import Class, variable
import_("module.py", "Class, variable")

# Assignment
import module as mdl
from module import Class as cls, variable as var
mdl, cls, var = import_("module.py", "Class, variable", bind=False)

The default behavior is to automatically assign names. To rename the imported symbols, set bind=False, and use an explicit assignment.

Interactive REPL

This importer may not work from an interactive REPL, because __file__ must be set. This is what I get with Python3.13:

>>> import logiqub.importer
>>> print(import_)
<function import_ at 0x...>
>>> print(__file__)
/usr/lib/python3.13/_pyrepl/__main__.py

Because Python3.13 runs the REPL differently from earlier versions, this seems to work. The catch is that the working directory is /usr/lib/python3.13/_pyrepl/, so you must use absolute paths within the interactive REPL session.

Thanks

With logiqub_importer, you can learn how to hack into Python module system, to import modules correctly by their actual path, instead of wrestling with Python conventions that break all the time. It's simple, straightforward, easy to understand, debug, or customize. Enjoy !

Made with ❤️ , by Victor René

Copyright © 2026 logiqub.org