A pure python lib inspired by the dotnet lib dapper
Project description
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!
Project details
Release history Release notifications | RSS feed
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.10.0.tar.gz
(12.8 kB
view details)
Built Distribution
pydapper-0.10.0-py3-none-any.whl
(17.5 kB
view details)
File details
Details for the file pydapper-0.10.0.tar.gz
.
File metadata
- Download URL: pydapper-0.10.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.9.19 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1536dc07ef9f8654db6551f73d9ee45575f285bffe0e16bd92f544f4136d5c8d |
|
MD5 | e28f4da13f2fe59fd6088d44f06ab1a9 |
|
BLAKE2b-256 | f043144ce62dbc28c417b709cb1d08743b0f899630371a51c97d1aae8fd690fa |
File details
Details for the file pydapper-0.10.0-py3-none-any.whl
.
File metadata
- Download URL: pydapper-0.10.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.9.19 Linux/6.5.0-1017-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34c946d42274c2868dd6c5fca33bd9a477803f41c2922177775c897832f95761 |
|
MD5 | 2add03e353be0414d81aa776409bc3cb |
|
BLAKE2b-256 | f73d2f0b7e4efa138a37d1d142e0e1b099e6623045da88e44a268a4dcdf25fe2 |