0

Is it possible to have a database driver written in pure python that doesn't need an underlying system library/ shared object to connect to a database?

Jasonca1
  • 4,848
  • 6
  • 25
  • 42

2 Answers2

1

Apologies for the necro-bump, but this still comes up in a google search for pure python drivers. So:

Implementing a database driver in pure python is conceptually quite straight forward, but only if you have the wire protocol it uses documented. Then you (just) write a handler for each type of message to and from the database server in byte format and away you go. The devil is in the detail of course and that's why you have to have the protocol documented unless you are patient enough to reverse engineer it (and handle undocumented changes!)

There is a pure python driver for mssql (called python-tds) and has been for a long time (v1.0 Jan 2013). There are also pure python drivers for postgresql (pg8000) and mysql (can't remember the name). I haven't done an exhaustive search for other databases as I don't generally use them.

Pure python drivers are excellent for cross platform development, using alternative python implementations, or simplifying packaging. I especially like them for putting a python program onto Android. You don't need to worry about how to cross compile db client libraries.

AllAboutMike
  • 121
  • 7
0

Yes. It is possible to implement python database API as it stated in PEP 249

Even more: such database API implementations exists.

E.g. nuodb-python

Alex Yu
  • 3,412
  • 1
  • 25
  • 38
  • Can this be done for any particular flavor of database? I've been having issues with getting my Django App to talk to SQL Server (and I've installed there official drivers) using Pyodbc with django-pyodbc-azure, and I just don't get why someone hasn't taken the time yet to just roll a python database api (in pure python) that can interface with SQL Server without the need for messy drivers (and having to sit on top of other libraries like Pyodbc to work). Frustrating that Django doesn't have more support for this out of the box. – Jasonca1 Feb 01 '19 at 23:07
  • In theory - yes. In practice - no. Suppose you have proprietary DBMS with closed specifications and only way is to link vendor provided binaries. Regarding MSSQL - I had a very positive experience with `django-pyodbc-azure` on Linux. – Alex Yu Feb 01 '19 at 23:14
  • I have a django project running on python 3.4.5. I have Django 2.1.0 installed, along with Pyodbc (4.0+), and the latest version of django-pyodbc-azure that I can install is 2.0.8.0. Whenever I go to certain models (which I have tested against 3.5 with the same version of django and Pyodbc, except the latest version of django-pyodbc-azure installed) it keeps seg faulting on my server. For some reason, 2.0.8.0 of django-pyodbc-azure will not work with the latest version of Pyodbc and Django 2.1.0 – Jasonca1 Feb 01 '19 at 23:17
  • Let's continue in [your other question](https://stackoverflow.com/questions/54488316/django-2-0-and-sql-server-interface-question). As for this question - I think I gave a complete answer – Alex Yu Feb 01 '19 at 23:20