1

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.)

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
NEO
  • 1,961
  • 8
  • 34
  • 53
  • Plenty of pure Python DB-API implementations out there if you don't stick to old databases ;) – Jay Mar 27 '20 at 06:50

1 Answers1

0

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.

Jay
  • 2,535
  • 3
  • 32
  • 44
  • The pystream looks promising. I will check it out. Any other simple implementation? For now I just want to make a connection, run a simple select query. – NEO Mar 27 '20 at 13:10