Call Python from inside SQL
SQLite lets you register Python functions that can be called from SQL. They're real first-class functions inside the engine — usable in WHERE clauses, SELECT lists, indexes, and triggers. The two main APIs:
conn.create_function(name, n_args, callable, deterministic=False)— scalar function (one row in, one row out).conn.create_aggregate(name, n_args, AggregateClass)— aggregate (many rows in, one value out).
Use cases include: regex matching (when a regex extension isn't available), domain-specific scoring functions, JSON manipulation Python does better than the JSON1 extension, and custom comparison functions.
Warning: Python-side functions cross the C/Python boundary on every call. They're slow by SQL standards. Use them when correctness matters more than throughput — not in hot loops over millions of rows.