This is a collection of modules to work with databases, but the current implementation is focused on SQLite. It contains:
Why ? If you don't like complicated ORM software that is over-engineered, difficult to debug, and potentially slow, this project is for you.
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_database_tools.git
# Install for your project's virtual environment
cd <project>
python3 -m venv venv
source venv/bin/activate
pip install $HOME/tools/logiqub_database_tools
You can also add https://logiqub.org/python/index/ to pip.
pip install --extra-index-url https://logiqub.org/python/index/ logiqub_database_tools
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/
To generate model classes for a SQLite database, you can follow these steps:
python -m venv venv
source venv/bin/activate
pip install logiqub_database_tools --extra-index-url https://logiqub.org/python/index
venv/bin/python3 -m logiqub.database_tools.sqlite_class_generator \
<sqlite_database_path> <model_directory>
After you designed the database, and ran the creation script, you can reverse engineer its schema, to obtain the corresponding model classes. Everything is typed, and conversion can be customized.
Then usage is straightforward:
>>> from model.auth import Auth
>>> db = Auth("auth.db")
>>> user_row = db.User.select_one(Equal("name", "Eddy"))
>>> print(user_row.name)
'Eddy'
Note that the schema automatically creates table attributes for the database model object, so it's not necessary to make the associations manually.
Version 0.1.2 now supports the syntax db.User.name == "Eddy". Expressions
can be combined with & (and), | (or), ~ (not).
You create a statement object using Select(), Insert(), Update(), or
Delete(). Each time you call a method the internal expression tree is
updated. Then, you compile it to create the final SQL string.
>>> query = (
Select("id", "name", "balls")
.from_("Employee")
.inner_join("Ban")
.on("Employee.id = Ban.employee_id")
.left_join("Manager")
.on("Employee.balls > Manager.balls")
)
>>> str(query)
"<Select: uncompiled>"
>>> query.compile()
(
"SELECT id, name, balls FROM Employee "
"INNER JOIN Ban ON Employee.id = Ban.employee_id "
"LEFT JOIN Manager ON Employee.balls > Manager.balls;"
)
You can then invoke:
Select.one(database, parameters), fetches one rowSelect.all(database, parameters), fetches all rows(Insert|Update|Delete).execute(database, parameters)It's not necessary to pass the database argument every time, you can use
bind(database), to remember it for subsequent calls.
With logiqub_database_tools, you can learn how to create a SQL toolkit. It's
simple, straightforward, easy to understand, debug, or customize. Enjoy !
Made with ❤️ , by Victor René
Copyright © 2026 logiqub.org