Skip to main content

A pure python lib inspired by the dotnet lib dapper

Project description

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

In addition to psycopg2, pydapper also supports

  • pymssql
  • mysql-connector-python
  • oracledb
  • aiopg
  • google-cloud-bigquery
  • sqlite3
  • psycopg (just the sync api, for now..)

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

Project details


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.11.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydapper-0.11.1-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file pydapper-0.11.1.tar.gz.

File metadata

  • Download URL: pydapper-0.11.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.21 Linux/6.8.0-1020-azure

File hashes

Hashes for pydapper-0.11.1.tar.gz
Algorithm Hash digest
SHA256 76652a1f5aa4a86d089c2b4d6a3b252f3974e38e5ddf7591bc55ab2173443c6f
MD5 c913f9a1588b5addf27006b96743d27f
BLAKE2b-256 861a91975c5319d9705186f3e9f1a20eb43ab9e3fefb45a5ebdc60cb73399089

See more details on using hashes here.

File details

Details for the file pydapper-0.11.1-py3-none-any.whl.

File metadata

  • Download URL: pydapper-0.11.1-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.9.21 Linux/6.8.0-1020-azure

File hashes

Hashes for pydapper-0.11.1-py3-none-any.whl
Algorithm Hash digest
SHA256 42d17d770f64b6dff9a26b1fb56277c40f2188b03f16255c8920f45884af5797
MD5 4d72531d2c4fd64e0fd2cb17cee4e058
BLAKE2b-256 20956ea6d9332256559fa0a53fabe51c82b74a6e484d24780071b1a5651d7199

See more details on using hashes here.

Supported by

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