Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create sqlite virtual table in Python

Tags:

python

sql

sqlite

I want to create a SQL-like interface for a special data source which I can query using Python. That is, I have a data source with a number of named iterable containers of entities, and I would like to be able to use SQL to filter, join, sort and preferably update/insert/delete as well.

To my understanding, sqlite3's virtual table functionality is quite suitable for this task. Is it possible to create the necessary bindings in Python? I understand that the glue has to be c-like, but my hope is someone already wrote a Python wrapper in C or using ctypes.

I will also accept an answer for a better/easier way of doing this.

like image 911
Krumelur Avatar asked Oct 23 '22 23:10

Krumelur


1 Answers

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

An example for talking to CouchDB using APSW.

There's a similar capability for Perl, namely: Create SQLite Virtual Table extensions in Perl

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

like image 74
Philip Z Avatar answered Oct 27 '22 11:10

Philip Z