Skip to main content

PyPI version Documentation Status codecov License: MIT Code style: black Imports: isort PyPI - Python Version

pydapper

A pure python library inspired by the NuGet library dapper.

pydapper is built on top of the dbapi 2.0 spec to provide more convenient methods for working with databases in python, with both sync and async dbapi support.


Help

See the documentation for more details and examples for configuring all of the connectors pydapper supports.


Installation

It is recommended to only install the database apis you need for your use case. Example below is for psycopg2!

pip

pip install pydapper[psycopg2]

poetry

poetry add pydapper -E psycopg2

Supported drivers

The database support docs go into further detail about how to connect to the different drivers pydapper supports.

In addition to psycopg2, pydapper also supports.

Sync dbapis

  • pymssql
  • mysql-connector-python
  • oracledb
  • google-cloud-bigquery
  • sqlite3
  • psycopg

Async dbapis

  • aiopg
  • psycopg

Never write this again...

from psycopg2 import connect

@dataclass
class Task:
    id: int
    description: str
    due_date: datetime.date

with connect("postgresql://pydapper:pydapper@localhost/pydapper") as conn:
    with conn.cursor() as cursor:
        cursor.execute("select id, description, due_date from task")
        headers = [i[0] for i in cursor.description]
        data = cursor.fetchall()

list_data = [Task(**dict(zip(headers, row))) for row in data]

Instead, write...

from dataclasses import dataclass
import datetime

import pydapper


@dataclass
class Task:
    id: int
    description: str
    due_date: datetime.date

    
with pydapper.connect("postgresql+psycopg2://pydapper:pydapper@locahost/pydapper") as commands:
    tasks = commands.query("select id, description, due_date from task;", model=Task)

(This script is complete, it should run "as is")

Buy me a coffee

If you find this project useful, consider buying me a coffee!

Buy Me A Coffee

Metadata

Release files for pydapper 0.13.1

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

Source distribution (sdist)

Source distribution for pydapper 0.13.1
File Size Uploaded
pydapper-0.13.1.tar.gz 13.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydapper 0.13.1
File Interpreter ABI Platform
pydapper-0.13.1-py3-none-any.whl Python 3 none any Details

Total release size: 31.0 kB

Release files / pydapper-0.13.1.tar.gz

Download URL pydapper-0.13.1.tar.gz
Size 13.0 kB
Tags Source
SHA-256 checksum
How to use checksums
593e1790c9b72033a852d98c4b21850a093b78dba263a11c60f5a92a81664480
BLAKE2b-256 checksum
How to use checksums
42603533bd10f85ca31db438a108d66b3f5c39794cdb7bc0a34227ece41af7b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.10.20 Linux/6.17.0-1010-azure

Release files / pydapper-0.13.1-py3-none-any.whl

Download URL pydapper-0.13.1-py3-none-any.whl
Size 18.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa3677a4531d0096d764524cf909d34d1eaae656d94b915e8b7a08e7cca4d619
BLAKE2b-256 checksum
How to use checksums
2c48287f165c06dea567f724e074ff116f11e5cd7c615a39595e2e9c9b41a539
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.10.20 Linux/6.17.0-1010-azure

Release history Release notifications | RSS feed

This release

0.13.1 This release

2 release files

0.13.0

2 release files

0.12.0

2 release files

0.11.1

2 release files

0.11.0

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.2

2 release files

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