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.

Help

See the documentation for more details.

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

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.0.tar.gz (12.6 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.0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pydapper-0.11.0.tar.gz
Algorithm Hash digest
SHA256 560e0d5744181a0a86351db6c4228b28d8e8f3cdf4d59848c59e492cc5a581bd
MD5 3dd93e4f9ec401c843a4fa25eadbc4f9
BLAKE2b-256 891fdd57ee4f9272abf6862aa54975c587bd9163f022dfd58ba38a14798225d1

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pydapper-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 00872575fc5a59b1bf0b5227f6ef7f3dceeda9d3cc154926b03e75502a48d53d
MD5 fc3bf90a4d92a4684aa04ddf9594e826
BLAKE2b-256 6a9399b9adb18da9192b156ea93310c29c3092c7e07950d3f75e61b68141b305

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