简体   繁体   中英

Implementing Python DB-API

I'm trying to implement the python DB-API for a small "database" that we built internally. This database does not expose an ODBC interface (or JDBC for that matter). My goal is to create a sqlalchemy for this so that I can use it with an application like Superset for example. I have created JDBC drivers in the past and that requires full Java implementation of the methods from the interfaces. In case of Python's DB-API, I couldn't find any example. Even the one I saw with psycopg2 https://github.com/psycopg/psycopg2 is fully written in C and I'm not an expert on C.

Any way to implement the DB-API only in python? Is there any examples available? (Sorry if my understanding of db-api is not correct.)

You can find plenty of DB-API drivers written in Python. The specific libraries depend on how your database communicates and packs/unpacks data.

  • If you're database is listening on a port, you'll probably be using the socket module.

  • If you're doing any kind of batch inserting or unpacking, you want to check out the struct module as well.

  • If you don't need support for Python 2, with Python 3.3+ you get memoryview().cast() , which may also come handy with regard to unpacking data.

  • Python 3.8 comes with the shared memory module, which can help you out when you start optimizing.

  • If your database runs on a specific platform, ctypes comes handy for pulling out OS specific tweaks (Like manually implementing shared memory if you can't use Python 3.8).

Pandas used to support DB-API connections directly. It currently only supports the SQlite DB-API officially, but you can piggyback it , which will allow you to test yourself with a known tool.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM