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 keyStringAttribute- Text fieldsIntegerAttribute- Integer with optional min/maxFixedPointAttribute- Decimal numbersBooleanAttribute- Boolean valuesBytesAttribute- Binary dataPasswordAttribute- Password fields (hidden in templates)DatetimeAttribute- Datetime valuesConnectionAttribute- Foreign key relationshipsSubElementsAttribute- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79ac1bdd8b9401c26b3840ba776e51384c2490225676f4a709f4dd10a7940303
|
|
| MD5 |
6933e818aca354864df5175d8007ee75
|
|
| BLAKE2b-256 |
aac2614d4c863c32fe3ee66a94399a52d8340be959d50de85e6a656dc8156c5a
|
Provenance
The following attestation bundles were made for dbentity-1.0.0.tar.gz:
Publisher:
publish.yml on pavelrevak/dbentity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbentity-1.0.0.tar.gz -
Subject digest:
79ac1bdd8b9401c26b3840ba776e51384c2490225676f4a709f4dd10a7940303 - Sigstore transparency entry: 1203430744
- Sigstore integration time:
-
Permalink:
pavelrevak/dbentity@e2f9626ccf24fcee56d264c9d90c904803f2c2c3 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/pavelrevak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e2f9626ccf24fcee56d264c9d90c904803f2c2c3 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4c666bf707bc53dd59413457b240f6eeef2011e7a542e6f928a94d445b2f041
|
|
| MD5 |
c370edc45cebfa7b43f95f3820cb6985
|
|
| BLAKE2b-256 |
ea28a5ef5c828ac1170b5947d55c62b50eb7af610a85a5cc447c1bab7385e689
|
Provenance
The following attestation bundles were made for dbentity-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on pavelrevak/dbentity
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
dbentity-1.0.0-py3-none-any.whl -
Subject digest:
a4c666bf707bc53dd59413457b240f6eeef2011e7a542e6f928a94d445b2f041 - Sigstore transparency entry: 1203430751
- Sigstore integration time:
-
Permalink:
pavelrevak/dbentity@e2f9626ccf24fcee56d264c9d90c904803f2c2c3 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/pavelrevak
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e2f9626ccf24fcee56d264c9d90c904803f2c2c3 -
Trigger Event:
release
-
Statement type: