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
pymssqlmysql-connector-pythonoracledbgoogle-cloud-bigquerysqlite3psycopg
Async dbapis
aiopgpsycopg
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!
Metadata
Release files for pydapper 0.13.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pydapper-0.13.1.tar.gz | 13.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pydapper-0.13.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.0 kB
Release files / pydapper-0.13.1.tar.gz
| Download URL | pydapper-0.13.1.tar.gz |
|---|---|
| Size | 13.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
593e1790c9b72033a852d98c4b21850a093b78dba263a11c60f5a92a81664480
|
|
BLAKE2b-256 checksum How to use checksums |
42603533bd10f85ca31db438a108d66b3f5c39794cdb7bc0a34227ece41af7b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.10.20 Linux/6.17.0-1010-azure
|
Release files / pydapper-0.13.1-py3-none-any.whl
| Download URL | pydapper-0.13.1-py3-none-any.whl |
|---|---|
| Size | 18.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa3677a4531d0096d764524cf909d34d1eaae656d94b915e8b7a08e7cca4d619
|
|
BLAKE2b-256 checksum How to use checksums |
2c48287f165c06dea567f724e074ff116f11e5cd7c615a39595e2e9c9b41a539
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.10.20 Linux/6.17.0-1010-azure
|