pkasperek / pydapper

a pure python port of the NuGet library dapper

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

test 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

A Simple Example

from dataclasses import dataclass
import datetime

from pydapper import connect


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

    
with connect("postgresql+psycopg2://pydapper:pydapper@locahost/pydapper") as commands:
    tasks = commands.query("select id, description, due_date from task;", model=Task)
    
print(tasks)
# [Task(id=1, description='Add a README!', due_date=datetime.date(2022, 1, 16))]

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

About

a pure python port of the NuGet library dapper

License:MIT License


Languages

Language:Python 97.0%Language:Makefile 3.0%