Skip to main content

Abstract implementation of the DB 2.0 API outlined in PEP-249.

Project description

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.

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.

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

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:

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?

Hopefully, an async implementation of these abstract classes, taking some inspiration from aiosqlite.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pep249abc-0.0.1b1-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file pep249abc-0.0.1b1-py3-none-any.whl.

File metadata

  • Download URL: pep249abc-0.0.1b1-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pep249abc-0.0.1b1-py3-none-any.whl
Algorithm Hash digest
SHA256 41180134ebb473c0b191684a75716e74a640196544b081f27b0e273e5b831b19
MD5 d0026be4b643841b519b9a165ab5fe76
BLAKE2b-256 9f28b0e16de98e2f3acc346eb78ce10201ce2abd7788839fb59d3284c0046293

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page