SQLite Forum

Any examples of writing a loadable extension in Python?
Login

Any examples of writing a loadable extension in Python?

(1) By anonymous on 2021-05-12 11:54:51 [source]

I believe loadable extensions are faster than user defined functions (correct me if I am wrong). Any examples of writing one, in Python?

(2) By anonymous on 2021-05-12 12:28:28 in reply to 1 [link] [source]

turns out both are similar in terms of performance and I found this how to load a custom function in python - https://docs.python.org/3/library/sqlite3.html#sqlite3.Connection.create_function

(3) By Ryan Smith (cuz) on 2021-05-12 12:35:17 in reply to 1 [link] [source]

I believe loadable extensions are faster than user defined functions

Why would you believe that? if written in the same way and compiled with the same settings, they probably are very much equal.

Any examples of writing one, in Python?

Ah. Everything in Python is slower. Python's power lies in its simplicity and abstraction, not its speed.

Not sure you can write a loadable extension in Python. It typically requires being able to compile the extended functions into a dynlib of sorts (.so/.dyn/.dll) with correct entry points to load into sqlite, and although this may well be possible with Python, I have never seen it or know how to do it.

Writing custom functions in Python for the loaded sqlite connection is however easy, but you'd have better luck checking the Python forums for that.