Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

An Abstract PEP-249 Implementation

Code style: black

This library contains an abstract implementation of PEP-249 which 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 excellent DuckDB library 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 with asyncio.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).

Installation

python3 -mpip install pep249abc

Usage

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

import pep249


class Cursor(pep249.Cursor):
    ...


class Connection(pep249.Connection):
    ...

To use the mixin types (e.g. to implement extensions, or to implement execute*() for the Connection), use multiple inheritance:

import pep249

class Connection(
   pep249.CursorExecuteMixin, pep249.ConcreteErrorMixin, pep249.Connection
):
    ...

The async implementation is contained in a separate subpackage:

from pep249 import aiopep249

class AsyncConnection(
   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, a Cursor with transaction support), and some select extensions:

There is now a very basic async implementation, which was made by copy and pasting the synchronous implementation and sprinking the words async and await in some appropriate (and likely some inappropriate) places.

What has not been implemented?

Most of the optional 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 with Cursor.description or 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 mirrors aiosqlite.

Metadata

Release files for pep249abc 0.0.1b3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for pep249abc 0.0.1b3
File Interpreter ABI Platform
pep249abc-0.0.1b3-py3.7.egg Legacy Egg format - - Details
pep249abc-0.0.1b3-py3-none-any.whl Python 3 none any Details

Total release size: 55.8 kB

Release files / pep249abc-0.0.1b3-py3.7.egg

Download URL pep249abc-0.0.1b3-py3.7.egg
Size 37.5 kB
Tags Egg
SHA-256 checksum
How to use checksums
20d88c78b311833b26663de6d8b86fb9751ee073c82a7b32d66a8628eed69283
BLAKE2b-256 checksum
How to use checksums
d7eaa388d12c29c4c87eddbdb6921e93797cf625accd48453da9cf8c522aa34b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7

Release files / pep249abc-0.0.1b3-py3-none-any.whl

Download URL pep249abc-0.0.1b3-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f2d0e932d16dafbd680295846f8129d22b39d9d612321774223adf50792c03b
BLAKE2b-256 checksum
How to use checksums
94457898bf409b118701a16856c6583b3488fdfa45e294220601c4b61f544145
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.7
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page