Skip to main content

A python micro ORM inspired by the nuget package 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

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

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.12.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.12.0-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pydapper-0.12.0.tar.gz
Algorithm Hash digest
SHA256 3658ce45be6ad68b70d7f55bba86faa857ee0bf9d571ba2f7024768c771695b0
MD5 f519271096c506d2dcf39c96676a8213
BLAKE2b-256 ba8c86ed6412e93ffdc4dfdb429f4424190caee3e104d3bc616fa26b847429da

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for pydapper-0.12.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5bb7a9cb218558eec940013569a7b709bc76514751222e28ab6d946e92d40331
MD5 3a08482ca8b09d92d000f4a2c630f723
BLAKE2b-256 4b35ba8294f704a427cbac0c000711c92c39024ba33591045e21f6590cf85b4c

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