Skip to main content

Lightweight Python ORM library for PostgreSQL

Project description

dbentity

Lightweight Python ORM library for PostgreSQL.

Installation

pip install dbentity

Features

  • Declarative entity definitions with typed attributes
  • Automatic SQL query generation
  • Support for JOIN operations
  • Query builder with boolean logic (AND, OR, NOT)
  • Database migration support
  • No external dependencies

Quick Start

from dbentity.db_entity import DbEntity
from dbentity.attribute import IndexAttribute, StringAttribute, IntegerAttribute
from dbentity.db_control import OrderByDesc, Limit

class User(DbEntity):
    TABLE = 'users'
    ITEMS = (
        IndexAttribute(),
        StringAttribute('name', form_key='user_name'),
        IntegerAttribute('age', minimal=0, maximal=150),
    )

# Query with controls
users = User.db_list(db, OrderByDesc('age'), Limit(10), name='John')
user = User.db_get(db, uid=123)

# Create new entity
user = User.create(db, name='Jane', age=25)

# Update
user.age = 26
user.db_save(db)

# Delete
user.db_delete(db)

Attribute Types

  • IndexAttribute / CreateIndexAttribute - Primary key
  • StringAttribute - Text fields
  • IntegerAttribute - Integer with optional min/max
  • FixedPointAttribute - Decimal numbers
  • BooleanAttribute - Boolean values
  • BytesAttribute - Binary data
  • PasswordAttribute - Password fields (hidden in templates)
  • DatetimeAttribute - Datetime values
  • ConnectionAttribute - Foreign key relationships
  • SubElementsAttribute - One-to-many relationships

Query Controls

from dbentity.db_control import (
    Where, And, Or, Not,
    Lt, Gt, Le, Ge,
    OrderBy, OrderByAsc, OrderByDesc,
    Limit, Offset,
    LeftJoin, RightJoin,
    GroupBy,
)

# Complex queries
users = User.db_list(
    db,
    Or(Where(name='John'), Where(name='Jane')),
    Gt(age=18),
    Lt(age=65),
    OrderByDesc('age'),
    Limit(10),
)

# Joins
posts = Post.db_list(
    db,
    LeftJoin('author', name='John'),
    OrderByDesc('created_at'),
)

Database Migrations

from dbentity.db_upgrade import db_upgrade

SQL_UPGRADE_FILES = [
    (1, 'upgrade_001.sql'),
    (2, 'upgrade_002.sql'),
]

db_upgrade(db, log, 'sql/', 'init.sql', SQL_UPGRADE_FILES)

License

MIT

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

dbentity-1.0.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

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

dbentity-1.0.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file dbentity-1.0.0.tar.gz.

File metadata

  • Download URL: dbentity-1.0.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbentity-1.0.0.tar.gz
Algorithm Hash digest
SHA256 79ac1bdd8b9401c26b3840ba776e51384c2490225676f4a709f4dd10a7940303
MD5 6933e818aca354864df5175d8007ee75
BLAKE2b-256 aac2614d4c863c32fe3ee66a94399a52d8340be959d50de85e6a656dc8156c5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbentity-1.0.0.tar.gz:

Publisher: publish.yml on pavelrevak/dbentity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dbentity-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dbentity-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 12.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbentity-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a4c666bf707bc53dd59413457b240f6eeef2011e7a542e6f928a94d445b2f041
MD5 c370edc45cebfa7b43f95f3820cb6985
BLAKE2b-256 ea28a5ef5c828ac1170b5947d55c62b50eb7af610a85a5cc447c1bab7385e689

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbentity-1.0.0-py3-none-any.whl:

Publisher: publish.yml on pavelrevak/dbentity

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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