Skip to main content

p3orm

p3orm logo

Utilitarian Python ORM for Postgres/SQLite powered by asyncpg/aiosqlite, Pydantic, and PyPika


Documentation: https://rafalstapinski.github.io/p3orm

Source Code: https://github.com/rafalstapinski/p3orm


Test Status pypi Supported Python Versions: 3.8, 3.9, 3.10 MIT License


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.

Notably, 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.

tl;dr - p3orm makes easy things easy, and hard things possible


Features

  • Comprehensive type annotations (full intellisense support)
  • String type validation an parsing powered by Pydantic
  • Support for PyPika queries
  • Support for all postgres datatypes
  • Support for all sqlite datatypes

Installation

Install with poetry

poetry add p3orm[sqlite]
# or
poetry add p3orm[postgres]

or with pip

pip install p3orm[sqlite]
# or
pip install p3orm[postgres]

The [sqlite] extra installs aiosqlite as p3orm's database driver, whereas [postgres] installs asyncpg.


Basic Usage

from datetime import datetime
from p3orm import Column, Table

from p3orm import sqlite as db
# or: from p3orm import postgres as db

class Thing(Table):
    id = Column(int, pk=True, autogen=True)
    name = Column(str)
    created_at = Column(datetime, autogen=True)

await db().connect(":memory:")

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)

await db().disconnect()

Metadata

Release files for p3orm 0.10.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for p3orm 0.10.3
File Size Uploaded
p3orm-0.10.3.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for p3orm 0.10.3
File Interpreter ABI Platform
p3orm-0.10.3-py3-none-any.whl Python 3 none any Details

Total release size: 25.3 kB

Release files / p3orm-0.10.3.tar.gz

Download URL p3orm-0.10.3.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7438bef916283fcd4c4094a5b916380a19330913ad70517b31be41869aca0cc7
BLAKE2b-256 checksum
How to use checksums
ca984a7102897228b0d6f6b9eba6e9e630ee1c376dedfdf2d0bea04ac2c94e6a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1016-azure

Release files / p3orm-0.10.3-py3-none-any.whl

Download URL p3orm-0.10.3-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
238c2cfb06a29e0057dd40ee83146d04a10e3c15233cf3b0daf6f443c7377c93
BLAKE2b-256 checksum
How to use checksums
b74e0b6809c061a2c96af08a5c02ba5fd823a48b72297d1142694b25a74f165f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.10.12 Linux/6.2.0-1016-azure

Release history Release notifications | RSS feed

This release

0.10.3 This release

2 release files

0.10.2

2 release files

0.10.1

2 release files

0.10.0

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page