Skip to main content

A pure python lib inspired by the dotnet lib dapper

Project description

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


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.


See the documentation for more details.


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


pip install pydapper[psycopg2]


poetry add pydapper -E psycopg2

Never write this again...

from psycopg2 import connect

class Task:
    id: int
    description: str

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

class Task:
    id: int
    description: str

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

Download files

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

Source Distribution

pydapper-0.8.0.tar.gz (12.5 kB view hashes)

Uploaded source

Built Distribution

pydapper-0.8.0-py3-none-any.whl (17.0 kB view hashes)

Uploaded py3

Supported by

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