Skip to main content

A lightweight SQLite ORM for Python

Project description

pylite-orm

🌍 Languages: English | 中文


pylite-orm is a lightweight and relatively new SQLite ORM library for Python. It provides developers with concise and intuitive interfaces for SQLite operations.

Given that there are already many excellent Python ORMs (such as SQLAlchemy, Tortoise-ORM, Peewee), why do we still need pylite-orm ?

Because in many scenarios — desktop software, mobile applications, small CMSs, embedded systems, automation scripts — using a single-file database like SQLite with those ORMs can feel too heavy. pylite-orm offers a simple API and minimal memory footprint — it has only a small amount of syntax, and the entire library is just 40KB in size. These are the core reasons and key advantages behind the existence of pylite-orm.

Features of pylite-orm:

  • Simple and easy to use, quick to get started
  • Small codebase, low memory usage
  • Support for transactions
  • Support for multiple database connections
  • Support for multi-table queries and relationships (one-to-one, one-to-many)
  • Support for native SQL queries
  • Support for populating query results into Python objects, lists, dictionaries, and the most popular Pydantic models, etc.
  • Built-in data migration tool, production-ready

If you are familiar with SQLAlchemy/SQLModel, Peewee, or other popular Python ORMs, you can start using pylite-orm immediately with zero learning cost.

If you are new to ORMs, pylite-orm allows you to deliver code quickly, and in the future, mastering other ORMs will become even easier.

Install pylite-orm

pip install pylite-orm

Getting Started Examples

Define Data Model

from pylite_orm import  DbModel, DbField, DbType
from datetime import datetime

class User(DbModel):
    id = DbField(db_type=DbType.INT, pk=True)
    name = DbField(db_type=DbType.TEXT)
    age = DbField(db_type=DbType.INT)
    created_at = DbField(db_type=DbType.TEXT, default_factory=datetime.now)

Create Table Using Migration Commands

# This is a set of operations under the command line prompt.
pylite-migr init --db mydb.db
pylite-migr create user
pylite-migr upgrade

Connect to Database

from pylite_orm import DbConn, DbSession

db = DbConn("mydb.db")
dbs = DbSession(db)

Insert Data

user = User(name="Tom", age=25)
dbs.insert(User).item(user).exec()

Query Data

# single query
user: User = dbs.select(User).filter(User.id == 1).first()
# multiple query
users: list[User] = dbs.select(User).filter(User.age > 20).all()
# multiple query (populate to dictionary)
users_dicts: list[dict] = dbs.select(User).filter(User.age > 20).serial()

Update Data

user.age = 35
data = user.asdict(exec_unset=True) # only update the modified data
dbs.update(User).item(data).filter(User.id == user.id).exec()

Delete Data

dbs.delete(User).filter(User.id == user.id).exec()

It's that simple!

For project development-level, more complex queries and operations, please read the documentation.

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

pylite_orm-0.1.4.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

pylite_orm-0.1.4-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file pylite_orm-0.1.4.tar.gz.

File metadata

  • Download URL: pylite_orm-0.1.4.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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}

File hashes

Hashes for pylite_orm-0.1.4.tar.gz
Algorithm Hash digest
SHA256 0571c7f74ba277c7023d7513975a54b6c8994daee987e15e4a4fcb5e54ecdde6
MD5 a74ea5cf9ad8ebbbfdabd19b439f9a26
BLAKE2b-256 bb1094d5bdc2afabdd374d25d68b32fbc9c33883a9aed402938dfc5b2a3ba14c

See more details on using hashes here.

File details

Details for the file pylite_orm-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: pylite_orm-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 23.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","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}

File hashes

Hashes for pylite_orm-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 57bf355be0e8a585d6609e8780b2f86a3ab6405d2b81cc7c9430e83f7a316b0b
MD5 c29cae6b743c6e646b88a9e8dc7c3c9c
BLAKE2b-256 adf250b76754511aad4a55082dd8afd433a6ca1d9c98a3c77d86cb24c4eef121

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