Skip to main content

PostgresLite

Python SQLite library built around asyncpg-style syntax.

No longer do you need to wrestle with raw SQLite. PostgresLite gives you a cleaner, asyncpg-inspired API with everything you'd expect out of the box:

  • Automatic type conversion for DATE, DATETIME, TIMESTAMP, and JSON columns
  • Transaction support via context managers
  • Schema syncing and dumping
  • Both sync and async connections, using the same API

Installing

You need Python >=3.11 to use this library.

Install by using pip install postgreslite in the terminal.

Quick example

Sync

from postgreslite import PostgresLite

pool = PostgresLite("./hello_world.db").connect()

pool.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT UNIQUE NOT NULL)")
pool.execute("INSERT INTO users (name) VALUES (?) ON CONFLICT DO NOTHING", "AlexFlipnote")

data = pool.fetch("SELECT * FROM users")
print(data)  # [{'id': 1, 'name': 'AlexFlipnote'}]

pool.close()

Async

import asyncio
from postgreslite import PostgresLite

async def main():
    pool = PostgresLite("./hello_world.db").connect_async()
    data = await pool.fetch("SELECT * FROM users")
    await pool.close()

asyncio.run(main())

Both connection types support the same API: execute, fetch, fetchrow, fetchval, executemany. asyncpg-style placeholders ($1, $2, …) are also accepted and converted automatically.

Type handling

Columns declared as DATE, DATETIME, TIMESTAMP, or JSON are automatically converted on read:

Column type Python type
DATE datetime.date
DATETIME datetime.datetime
TIMESTAMP datetime.datetime (UTC)
JSON dict / list

Transactions

with pool.transaction():
    pool.execute("UPDATE accounts SET balance = balance - 100 WHERE id = 1")
    pool.execute("UPDATE accounts SET balance = balance + 100 WHERE id = 2")

Raises on error and rolls back automatically. Async pools use async with pool.transaction().

Schema utilities

db = PostgresLite("./hello_world.db")

# Dump current schema to stdout, a file, or a folder of per-table files
db.dump_schema()
db.dump_schema(output="schema.sql")
db.dump_schema(output="schema/")

# Sync a schema definition (SQL string, .sql file, or folder) to the live database
result = db.sync_schema("schema/")

sync_schema adds new tables and missing columns non-destructively by default (safe_mode=True).

Introspection

pool.tables()                  # ['users', 'posts']
pool.table_exists("users")     # True
pool.table_columns("users")    # [<TableColumn name='id' ...>, ...]

Metadata

Release files for PostgresLite 1.0.0

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

Source distribution (sdist)

Source distribution for PostgresLite 1.0.0
File Size Uploaded
postgreslite-1.0.0.tar.gz 13.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for PostgresLite 1.0.0
File Interpreter ABI Platform
postgreslite-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 23.5 kB

Release files / postgreslite-1.0.0.tar.gz

Download URL postgreslite-1.0.0.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9e1b03fcac0b4e9199627e17bfccb897bcf47b3a9ab760825a0164c8caea1750
BLAKE2b-256 checksum
How to use checksums
1fb10cc67ba139ced37927a6b661930547be30ca35f8d58e72f859d0f5a08e77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / postgreslite-1.0.0-py3-none-any.whl

Download URL postgreslite-1.0.0-py3-none-any.whl
Size 10.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9a181e193005b9f10cf50221d0ad96c06fd1760262a044872d865e4165cfb52
BLAKE2b-256 checksum
How to use checksums
dd79b3ec471ef95a15f4b07facbb22b3fb34a8fcc1130b73cf3fe26a10d7fc75
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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