Skip to main content

A simple PostgreSQL to Python mapper.

Project description

halfORM

PyPI version Python versions PostgreSQL versions License Tests Coverage Downloads

⚠️ BREAKING CHANGE in v0.18 — psycopg2 → psycopg 3

halfORM 0.18 drops psycopg2 and requires psycopg 3.

pip uninstall psycopg2-binary
pip install "psycopg[binary]"

If you use custom psycopg2 adapters in your own code, rewrite them with the psycopg 3 Dumper/Loader API. See the full migration notes in CHANGELOG.md.

psycopg2 users: the 0.17.x branch is maintained for psycopg2 and receives bug fixes.

halfORM is a database-first ORM for PostgreSQL. You write the schema in SQL; halfORM introspects it at runtime and gives you Python objects to work with your data. No migrations, no code generation.

The central idea: a Relation object is a predicate. It describes the logical condition that rows must satisfy to belong to the relation. Its extension — the set of rows that currently satisfy the predicate in the database — is what you read, update, or delete.

Install

pip install half_orm

Configure

# ~/.half_orm/blog
[database]
name = blog
user = alice
password = secret
host = localhost

Usage

from half_orm.model import Model

blog = Model('blog')
Post   = blog.get_relation_class('blog.post')
Author = blog.get_relation_class('blog.author')

# Insert
alice = Author(
    first_name='Alice', last_name='Martin', email='alice@example.com'
).ho_insert()

# Query — Author(last_name='Martin') is the predicate "is an author named Martin"
for row in Author(last_name='Martin').ho_select('id', 'email'):
    print(row)

# Update a singleton (predicate identifies exactly one row)
Author(id=alice['id']).ho_assert_is_singleton().ho_update(email='alice@newdomain.com')

# Delete
Author(id=alice['id']).ho_assert_is_singleton().ho_delete()

Documentation

License

halfORM is licensed under the GPL-3.0 license.

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

half_orm-0.18.10.tar.gz (61.1 kB view details)

Uploaded Source

Built Distribution

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

half_orm-0.18.10-py3-none-any.whl (57.4 kB view details)

Uploaded Python 3

File details

Details for the file half_orm-0.18.10.tar.gz.

File metadata

  • Download URL: half_orm-0.18.10.tar.gz
  • Upload date:
  • Size: 61.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.19

File hashes

Hashes for half_orm-0.18.10.tar.gz
Algorithm Hash digest
SHA256 c0438f42eed1f63bdabaa0e81cc0957b20d37da4da9b79d192276b0b92639904
MD5 004c1a2289eb6a88a37d382a489ea510
BLAKE2b-256 f88a4e852fc45d2902792daeb509ce517d9aa1309e859d06e6cfee49f034cc10

See more details on using hashes here.

File details

Details for the file half_orm-0.18.10-py3-none-any.whl.

File metadata

  • Download URL: half_orm-0.18.10-py3-none-any.whl
  • Upload date:
  • Size: 57.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.8.19

File hashes

Hashes for half_orm-0.18.10-py3-none-any.whl
Algorithm Hash digest
SHA256 8798e9d61a616854fa5c674c0b6f21d777c52e8cd84168e8c6388ad0c04288ef
MD5 23f7c8dde004cc5f32140e9760239687
BLAKE2b-256 cc89a925ada433feb82417534756b36b699c936e560b4d4659b001eba55d5397

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