Ephemeral SQL index over a local directory
Actively maintained. Last release 4 weeks ago, commits in 23 of the last 26 weeks. A safe choice.
pip install dirsqldirsql (Python SDK)
Ephemeral SQL index over a local directory. dirsql watches a filesystem, ingests structured files into an in-memory SQLite database, and exposes a SQL query interface -- the filesystem is always the source of truth.
Also available as dirsql on crates.io and dirsql on npm.
Installation
pip install dirsql
Requires Python >= 3.12. Ships as a native extension (Rust via PyO3); prebuilt binary wheels are provided for common platforms.
Quick start
DirSQL is async by default: the constructor returns immediately, scanning runs in a background thread, and you await db.ready() before querying. Each table is a (ddl, glob, extract) triple: the DDL defines the SQLite schema, the glob selects files (relative to the root), and extract turns a matched file into a list of row dicts. dirsql does not read file contents -- if extract needs the file body it reads path itself; return an empty list to skip a file.
import asyncio
import json
from dirsql import DirSQL, Table
async def main():
db = DirSQL(
"./my-blog",
tables=[
Table(
ddl="CREATE TABLE posts (title TEXT, author TEXT)",
glob="posts/*.json",
extract=lambda path: [json.loads(open(path, encoding="utf-8").read())],
),
],
)
await db.ready()
posts = await db.query("SELECT * FROM posts WHERE author = 'alice'")
print(posts)
asyncio.run(main())
Multiple tables and joins
db = DirSQL(
"./my-blog",
tables=[
Table(
ddl="CREATE TABLE posts (title TEXT, author_id TEXT)",
glob="posts/*.json",
extract=lambda path: [json.loads(open(path, encoding="utf-8").read())],
),
Table(
ddl="CREATE TABLE authors (id TEXT, name TEXT)",
glob="authors/*.json",
extract=lambda path: [json.loads(open(path, encoding="utf-8").read())],
),
],
)
await db.ready()
results = await db.query("""
SELECT posts.title, authors.name
FROM posts JOIN authors ON posts.author_id = authors.id
""")
Ignoring files
Pass ignore patterns to skip files during scanning and watching: