Package: pep249abc
An Abstract PEP-249 ImplementationThis library contains an abstract implementation ofPEP-249which should make it easier to implement new databases in Python. These abstract
implementations are fully typed and the docstrings contain some (plagiarised) information
from the standard. There is a basic async implementation which could probably be improved
upon.To demonstrate usage of this library, I'm putting together a wrapper on top of the
excellentDuckDBlibrary which adds full typing, context managers,
distinct cursors, and easier to manage error types.This wrapper is available here,
and is currently a bit rough around the edges. It contains a naive async implementation
which essentially just wraps every call withasyncio.to_thread.Tested in Python 3.7, but not extensively. This library has not been condoned by the PEP
authors, who might hate it.Why would I use this?If you're looking to implement a DB-API 2.0 interface for a database, this library
should make it easier to do so. Inheriting from the appropriate abstract base classes
will ensure that classes can't be instantiated without fully implementing the required
behaviour. Implementations will be fully typed, and some functionality is provided
'for free' (e.g. context managers, cursor iteration).Installationpython3-mpipinstallpep249abcUsageThis library's base classes define a protocol which requires implementation. If you
inherit from these classes, your editor should whinge at you until you've implemented
the rest of the specification (or if you deviate from it).importpep249classCursor(pep249.Cursor):...classConnection(pep249.Connection):...To use the mixin types (e.g. to implement extensions, or to implementexecute*()for
theConnection), use multiple inheritance:importpep249classConnection(pep249.CursorExecuteMixin,pep249.ConcreteErrorMixin,pep249.Connection):...The async implementation is contained in a separate subpackage:frompep249importaiopep249classAsyncConnection(aiopep249.AsyncCursorExecuteMixin,aiopep249.ConcreteErrorMixin,aiopep249.AsyncConnection,):...What has been implemented?All of the core functionality, some 'common but slightly non-compliant' stuff (e.g.TransactionalCursor, aCursorwith transaction support), and some select extensions:A mixin toadd the error types to theConnection.A mixin toadd a reference to theConnectionto theCursor.A mixin toadd support for nextanditeration.There is now a very basic async implementation, which was made by copy and pasting the synchronous
implementation and sprinking the wordsasyncandawaitin some appropriate (and likely some
inappropriate) places.What has not been implemented?Most of the optional extensions.Cursor.rownumber.Cursor.scroll().Cursor.messages.Connection.messages.Cursor.lastrowid.Cursor/Connection.errorhandler.Two phase commit extensions.Most of these are missing simply because I haven't encountered them in the wild and they
weren't supported by the reference implementation I had in mind. If you'd like to see
these implemented, please raise an issue! If you have examples of the features in use,
that would be helpful.What could be improved?Probably a lot! In particular, I'm not happy withCursor.descriptionor the type
constructors. The spec is quite opaque on these and I haven't done much research on how
these work or how they should tie in.What are the future plans?General improvements, some further testing, some documentation, and maybe a more inspired
async implementation which more commonly mirrorsaiosqlite.