Why Python has no equivalent of JDBC of Java?

Chris Angelico rosuav at gmail.com
Mon May 20 20:41:31 EDT 2019

On Tue, May 21, 2019 at 8:25 AM Andrew Z <formisc at gmail.com> wrote:
> What does 249 specification mention about drivers?

Nothing. PEP 249 defines how a Python app communicates with the
database module. For instance:

import psycopg2
db = psycopg2.connect("...")
with db, db.cursor() as cur:
    cur.execute("select * from people where title = %s", [title])
    for person in cur:

You could replace the first two lines with, say, mysql.connector, or
sqlite3, and the rest of the code doesn't need to care. The only part
that needs to be database-engine-specific is the connection string
passed to the connect() function.

Some of these modules require lower level drivers, because they're
simple wrappers around lower-level C APIs. Others are linked
statically with the entire code required to make the connection (the
sqlite3 module, I believe, is like that). Still others are pure Python
implementations of wire protocols, which means they don't need
anything more than the Python standard library and its socket
services. In the case of Oracle, it sounds like it depends on a
previously-installed Oracle client.


More information about the Python-list mailing list