Skip to main content

Postgres Not an ORM

A simple library that helps you interact with Postgres databases

  • Write raw SQL queries
  • Marshall queries into Pydantic models for type safety
  • Manage sessions and transactions using simple context api
  • Automatically create Open Telemetry spans for monitoring

Basic Examples

from pydantic import BaseModel

from pnorm import AsyncPostgresClient, PostgresCredentials

creds = PostgresCredentials(host="", port=5432, user="", password="", dbname="")
client = AsyncPostgresClient(creds)

class User(BaseModel):
    name: str
    age: int

# If we expect there to be exactly one "john"
john = await client.get(User, "select * from users where name = %(name)s", {"name": "john"})
# john: User or throw exception

# Get the first "mike" or return None
mike = await client.find(Users, "select * from users where name = %(name)s", {"name": "mike"})
# mike: User | None

# Get all results
adults = await client.select(User, "select * from users where age >= 18")
# adults: tuple[User, ...]

await client.execute("delete from users where age >= 18")

Keep connection alive

async with client.start_session(schema="admin") as session:
    # Connection end
    # > Set the search path to "admin"

    await session.execute("create table users (name varchar, age integer)")
    await session.execute(
        "insert into users (name, age) values (%(name)s, %(age)s),
        User(name="sally", age=20),
    )
    
    # Connection end

Create a transaction

This example, retrieves a user from the users table, deletes the user, in python increments the user's age, then inserts the user back into the DB. Because this is in a transaction, the user will exist in the database with it's previous age (in case of a failure) or exist in the database with their new age.

async with client.create_transaction() as transaction:
    # Transaction start

    await transaction.execute("delete from users where name = %(name)s", {"name": "mike"})
    person.age += 1
    await transaction.execute("insert into users (name, age) (%(name)s, %(age)s))", person)
   
    # Transaction end

Inspired by

Metadata

Release files for pnorm 0.0.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 pnorm 0.0.3
File Size Uploaded Provenance Actions
pnorm-0.0.3.tar.gz 20.8 kB Without provenance Details for pnorm-0.0.3.tar.gz

Built distribution (wheel)

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

Total release size: 38.9 kB

Release files / pnorm-0.0.3.tar.gz

Download URL pnorm-0.0.3.tar.gz
Size 20.8 kB
Tags Source
SHA-256 checksum
How to use checksums
16aa3fecee3edeb370cd8ae51eb3b3efdaa5a2a7937603c6298a8ea0f9a65230
BLAKE2b-256 checksum
How to use checksums
ea64711b1f45e88fc4b996d2ed59b71540e78b29992a7e01bed24c4cf3ca722c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pnorm-0.0.3-py3-none-any.whl

Download URL pnorm-0.0.3-py3-none-any.whl
Size 18.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3755802e25bf4fadef94a61f7eb5398286a1a8eee43adf54ef28fc859f2c64f2
BLAKE2b-256 checksum
How to use checksums
66df32888cff40e885c24dabacdafe0372d825af04daff0e23cbc93b31c05710
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pnorm 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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