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

1
  • Plenty of pure Python DB-API implementations out there if you don't stick to old databases ;) Commented Mar 27, 2020 at 6:50

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.