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.2.tar.gz (17.8 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.2-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylite_orm-0.1.2.tar.gz
  • Upload date:
  • Size: 17.8 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.2.tar.gz
Algorithm Hash digest
SHA256 785cacbeddc26536446b424485bb596c3e212f960fb01cd171eb97a9b9824b46
MD5 860c2f842a40da5969b976c5e14f34d4
BLAKE2b-256 16281ce64147decab48756b6db488a354f0940258182bb749fd6f245a19ec5cc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylite_orm-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 23.4 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5269f76c4b26754d643e4d4ee09c0d4f1bfa0bbc6fb63f7a264018b287699e06
MD5 7a24fe8bef0844e00e24b367453ab92b
BLAKE2b-256 1c183e51111357a005fa84cc28383095c4565760fcfb7700bb0c3cdb50cf703d

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