Creating a sqlite virtual table in Python

I want to create an SQL-like interface for a special data source that I can query using Python. That is, I have a data source with several named container containers of objects, and I would like to be able to use SQL to filter, merge, sort, and preferably update / insert / delete.

As far as I understand, the functionality of the sqlite3 virtual table is quite suitable for this task. Is it possible to create the necessary bindings in Python? I understand that glue should be c-like, but I hope someone already wrote a Python shell in C or using ctypes.

I will also accept the answer as a better / easier way to do this.

+4
source share
2 answers

You can do this by registering a virtual table in SQLite using APSW Python bindings .

An example of a conversation with CouchDB using APSW .

There is a similar feature for Perl, namely: Create SQLite virtual table extensions in Perl

Finally, if you want to create a Python-based virtual table in PostgreSQL 9.1, check out http://multicorn.org/ .

+5
source

It looks like you can use SQLAlchemy to save these objects in sqlite3 , possibly in :memory: db, and the problem and queries are at the object and table level (raw sql). You can also easily update / insert / delete them.

-2
source

All Articles