Skip to main content

Litequery

Litequery is a minimalist library for interacting with SQLite in Python. It lets you define your queries once and call them as methods. No ORM bloat, just raw SQL power, with the flexibility to operate in both asynchronous and synchronous modes.

Why Litequery?

  • Simplicity: Define SQL queries in .sql files. No complex ORM layers.
  • Async first: Built for modern async Python, but also supports synchronous operations for traditional use cases.
  • Flexible: Supports different SQL operations seamlessly.

Installation

pip install litequery

Getting Started

Define Your Queries

Create a queries.sql file. Name your queries using comments and write them in pure SQL.

-- name: get_all_users
SELECT * FROM users;

-- name: get_user_by_id^
SELECT * FROM users WHERE id = :id;

-- name: get_last_user_id$
SELECT MAX(id) FROM users;

-- name: insert_user<!
INSERT INTO users (name, email) VALUES (:name, :email);

-- name: delete_all_users!
DELETE FROM users;

Using Your Queries

Define your database and queries, and then call them as methods. Choose async or sync setup based on your needs. It's as straightforward as it sounds.

import litequery
import asyncio


async def main():
    lq = litequery.setup("database.db", "queries.sql", use_async=True)
    await lq.connect()

    user_id = await lq.insert_user(name="Alice", email="alice@example.com")
    print(user_id)

    users = await lq.get_all_users()
    print(users)

    user = await lq.get_user_by_id(id=user_id)
    print(user)

    rows_count = await lq.delete_all_users()

    await lq.disconnect()


asyncio.run(main())

Transaction Support

Litequery also supports transactions in both async and sync contexts, allowing you to execute multiple queries atomicaly.

import litequery
import asyncio


async def main():
    lq = litequery.setup("database.db", "queries.sql")
    await lq.connect()

    try:
        async with lq.transaction():
            await lq.insert_user(name="Charlie", email="charlie@example.com")
            raise Exception("Force rollback")
            await lq.insert_user(name="Eve", email="eve@example.com")
    except Exception:
        print("Transaction failed")

    users = await lq.get_all_users()
    print(users)

    await lq.disconnect()


asyncio.run(main())

Wrapping Up

Litequery is all about simplicity and efficiency. Why wrestle with bloated ORMs when you can have raw SQL power? If you think there's a better way or have suggestions, let's hear them. Happy querying!

Metadata

Release files for litequery 0.8.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for litequery 0.8.2
File Size Uploaded Provenance Actions
litequery-0.8.2.tar.gz 20.6 kB Without provenance Details for litequery-0.8.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for litequery 0.8.2
File Interpreter ABI Platform Actions
litequery-0.8.2-py3-none-any.whl Python 3 none any Details for litequery-0.8.2-py3-none-any.whl

Total release size: 30.1 kB

Release files / litequery-0.8.2.tar.gz

Download URL litequery-0.8.2.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
182c00ee4ba1e003f05ad6390b971f397b70b3769b69f6c34005b648a651460d
BLAKE2b-256 checksum
How to use checksums
75922336a004592f400b40a5a6067d35c8d95ba298e69f39e7821723155870f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.5

Release files / litequery-0.8.2-py3-none-any.whl

Download URL litequery-0.8.2-py3-none-any.whl
Size 9.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8df65cf525acbec8be36073f2b09dec0aed5a0c1ba0125d7b2c541257688fe3a
BLAKE2b-256 checksum
How to use checksums
cd7e3045aea7c90a932c29547a1a0ae886a890b24ce00f8d69f9bec2eb1b5b65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.9.5

Security for litequery 0.8.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page