Utilitarian Python ORM for Postgres, backed by asyncpg, Pydantic, and PyPika
Project description
p3orm
Utilitarian Python ORM for Postgres, backed by asyncpg, Pydantic, and PyPika
Philosophy
90% of the time we talk to a database is with a CRUD operation. p3orm provides convenience helpers for fetching (one, first, many), inserting (one, many), updating (one), and deleting (one, many).
The remaining 10% is a bit more complicated. p3orm doesn't attempt to hide SQL queries or database interactions behind any magic. Instead, it empowers you to write direct and legible SQL queries with PyPika and execute them explicitly against the database.
Objects created or fetched by p3orm are dead, they're just Pydantic models. If you want to interact with the database, you do so explicitly.
Features
- Comprehensive type annotations (full intellisense support)
- Type validation
- Full support for PyPika queries
- Support for all
asyncpgtypes
Installation
Install with poetry
poetry add p3orm
or with pip
pip install p3orm
Basic Usage
from datetime import datetime
from p3orm.core import Porm
from p3orm.table import Table, PormField
class Thing(Table):
id = PormField(int, "id", pk=True, autogen=True)
name = PormField(str, "name")
created_at = PormField(datetime, "created_at", autogen=True)
await Porm.connect(user=..., password=..., database=..., host=..., port=...)
thing = Thing(name="Name")
inserted = await Thing.insert_one(thing)
fetched = await Thing.fetch_first(Thing.id == 1)
fetched.name = "Changed"
updated = await Thing.update_one(fetched)
deleted = await Thing.delete_where(Thing.id == updated.id)
Usage
See docs
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file p3orm-0.4.0.tar.gz.
File metadata
- Download URL: p3orm-0.4.0.tar.gz
- Upload date:
- Size: 9.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.0 Linux/5.11.0-1028-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05a058c78e474490c56a8cfb13b5104b7538885ed799e6b676ee63161e587bc3
|
|
| MD5 |
ee17c53adda6461056f2209dc542387a
|
|
| BLAKE2b-256 |
800cbd967e15595e937790a819987640258812a13bb4a9159e41c612c016c1a6
|
File details
Details for the file p3orm-0.4.0-py3-none-any.whl.
File metadata
- Download URL: p3orm-0.4.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.12 CPython/3.10.0 Linux/5.11.0-1028-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
855a181cc031a74492032046bbb3050e985728c971fd4ffe97718cc8588adf9a
|
|
| MD5 |
99af9cf1f87fc5faeee06ef78cb7f357
|
|
| BLAKE2b-256 |
b01355b945dd418fa6b1fd58732aee599e04f14d827ecabcdd0b2165de58a068
|