Skip to main content

Python PyPika Postgres ORM

Project description

p3orm

p3orm logo

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

Test pypi Test

Philosophy

90% of the time we talk to a database is with a CRUD operation. porm 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. porm 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.

Object 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 asyncpg types

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(Thing.id == updated.id)

Usage

See docs

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-0.2.1.tar.gz (6.4 kB view hashes)

Uploaded Source

Built Distribution

p3orm-0.2.1-py3-none-any.whl (6.5 kB view hashes)

Uploaded Python 3

Supported by

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