Skip to main content

A lightweight SQLite ORM for Python

Project description

pylite-orm

🌍 Languages: English | 中文


pylite-orm is a relatively new lightweight SQLite ORM tool based on Python. It provides developers with a concise and intuitive interface for SQLite operations.

In the context of many excellent Python ORM frameworks already existing (such as SQLAlchemy, Tortoise-ORM, Peewee), why use pylite-orm?

Obviously, in some specific scenarios, such as desktop software, mobile applications, embedded systems, and script development, SQLite is usually used as a single-file database. In these cases, using the aforementioned ORMs seems heavy, while PyLite-ORM provides a simpler API and smaller memory footprint—it only has a few simple syntaxes and is only 40K in size! This is the meaning of pyLite-orm's existence.

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, Peewee, or other popular Python ORM frameworks, you can immediately start using PyLite-ORM.

1 Install pylite-orm

pip install pylite-orm

2 Getting Started Examples

2.1 Define Data Model

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

class User(Model):
    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)

2.2 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

2.3 Connect to Database

from pylite_orm import DbConn, DbSession

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

2.4 Insert Data

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

2.5 Query Data

users = dbs.select(User).filter(User.age > 20).all()

2.6 Update Data

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

2.7 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 operation guide.

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.1.tar.gz (17.4 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.1-py3-none-any.whl (22.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pylite_orm-0.1.1.tar.gz
  • Upload date:
  • Size: 17.4 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.1.tar.gz
Algorithm Hash digest
SHA256 a0c44f8dd57a9d90cad9a89d3e04029d8867ed939945a880d3d3a402d5b4f39f
MD5 42bde807daf44a88f43643728f277d4e
BLAKE2b-256 874ae5b24857b1abed8ba97ad6db04311c99b2a080f7b41b335f5fcb3720bea4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pylite_orm-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.9 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5bd8b769286050094b42091fcc1ff6588b13f19dd2cf14d0733507f2a59350e0
MD5 3e5d133f73eeed1f37cff522a059cf86
BLAKE2b-256 36af8d3b06c9f18f5e0c0d5df8c385d5be7d6a2076a2dc4850fe854da21e7fe5

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