brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: python -m sqlite3 opens a SQLite shell when the sqlite3 binary is missing

Python
~/tips/tip-python-sqlite3-cli-module

python3 -m sqlite3 app.db "SELECT count(*) FROM sqlite_master"

Runs SQL against a SQLite file from the python standard library, with no extra tools installed.

Minimal servers often have python but not the sqlite3 command line tool.

python3 -m sqlite3 app.db "SELECT count(*) FROM sqlite_master"
python3 -m sqlite3 app.db

With a statement as the second argument python runs it and exits. Without one you get an interactive prompt, and .quit or Ctrl-D leaves it. This module entry point was added in Python 3.12, so it works on Ubuntu 24.04 but not on Debian 12, which ships 3.11. The usage is python -m sqlite3 [-h] [-v] [filename] [sql], and -v prints the version of the SQLite library in use. It is a small shell, not a replacement for the full sqlite3 tool, so install that one if you need its extra features.

Further reading: sqlite3 documentation

More Python tips import asyncio from enum import StrEnum, auto except* ValueError as eg: import pytest pytest --maxfail=2 All Python tips (107) All topics

Link