Skip to main content

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

Project description

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()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

p3orm-1.0.0a1.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

p3orm-1.0.0a1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file p3orm-1.0.0a1.tar.gz.

File metadata

  • Download URL: p3orm-1.0.0a1.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/6.2.0-1018-azure

File hashes

Hashes for p3orm-1.0.0a1.tar.gz
Algorithm Hash digest
SHA256 75b2b9930b2bdd3160e2b4f03ed6521729293ef77fb73bd737db127b6dcd1e8c
MD5 92c91de6608711ca1f5fc297c05f6c4a
BLAKE2b-256 7bb9ec5e4e9aff2d1cf8487444a12462db25353c9bc414843558b368db97a2ba

See more details on using hashes here.

File details

Details for the file p3orm-1.0.0a1-py3-none-any.whl.

File metadata

  • Download URL: p3orm-1.0.0a1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.7.1 CPython/3.12.0 Linux/6.2.0-1018-azure

File hashes

Hashes for p3orm-1.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 0f4a856ed0f1e989c3fbdd66f25b6011ad8208f4a417af0d20ed8338a81ec97c
MD5 386d976cd614a6fd66bc7bae8471c7c2
BLAKE2b-256 ea55beec8c87af4a00231dde416e7aa1cd0cf445e616b86355b0ac642f23c7a8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page