Skip to main content

dirsql (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.

Documentation

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:

db = DirSQL(
    "./my-blog",
    ignore=["**/drafts/**", "**/.git/**"],
    tables=[...],
)

Path-table scans (SELECT ... FROM './') respect .gitignore files by default. Pass no_ignore=True to restore the full walk; the built-in node_modules/.git defaults and any ignore patterns still apply:

db = DirSQL("./my-blog", no_ignore=True)

Loading SQLite extensions

Pass extensions to load SQLite extension shared libraries onto the connection at startup (before any CREATE TABLE). Each entry is a dict with a path and an optional entrypoint init-symbol override:

db = DirSQL(
    "./my-blog",
    tables=[...],
    extensions=[
        {"path": "./ext/vec0.dylib", "entrypoint": "sqlite3_vec_init"},
        {"path": "./ext/myext.so"},  # entrypoint derived from the filename
    ],
)
await db.ready()

# The extension's functions are now callable in queries:
rows = await db.query("SELECT vec_version() AS v")

dirsql enables extension loading only while loading the configured libraries, then disables it again, so the SQL load_extension() function is never exposed to your queries. Programmatic entries load first, followed by any [[dirsql.extension]] entries declared in a config file. See the config reference.

Watching for changes

db.watch() returns an async iterator of row-level change events as files change on disk:

async for event in db.watch():
    print(f"{event.action} on {event.table}: {event.row}")
    if event.action == "error":
        print(f"  error: {event.error}")

Each event has .action ("insert", "update", "delete", or "error"), .table, .row (the new row, or the deleted row on delete), .old_row (the previous row, on update), .file_path, and .error (on error).

CLI

pip install dirsql also installs a dirsql console script. dirsql "<sql>" (or uvx dirsql "<sql>") runs one query and prints the rows as JSON — the default. dirsql server starts an HTTP server exposing the SDK over HTTP: POST /query for SQL and GET /events for a Server-Sent Events change stream. See the CLI reference.

License

MIT

Release files for dirsql 0.4.41

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

Source distribution (sdist)

Source distribution for dirsql 0.4.41
File Size Uploaded
dirsql-0.4.41.tar.gz 474.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for dirsql 0.4.41
File
dirsql-0.4.41-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details
dirsql-0.4.41-cp310-abi3-manylinux_2_28_x86_64.whl CPython 3.10 abi3 Linux glibc 2.28+ x86-64 Details
dirsql-0.4.41-cp310-abi3-manylinux_2_28_aarch64.whl CPython 3.10 abi3 Linux glibc 2.28+ ARM64 Details
dirsql-0.4.41-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details
dirsql-0.4.41-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details

Total release size: 15.6 MB

Release files / dirsql-0.4.41.tar.gz

Download URL dirsql-0.4.41.tar.gz
Size 474.0 kB
Tags Source
SHA-256 checksum
How to use checksums
95320f6d31c444e041742d68c6f7c2c7d3129a83e0df24020995b14c9d932f69
BLAKE2b-256 checksum
How to use checksums
801cfdaa682180889e62d26e8111624249d5cffebe013ec23861640658d7d8ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / dirsql-0.4.41-cp310-abi3-win_amd64.whl

Download URL dirsql-0.4.41-cp310-abi3-win_amd64.whl
Size 3.1 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
d65596cdac73c1aff30fe7c6107ba12a3364dd1f2c7bf82a983ad0f876ef010c
BLAKE2b-256 checksum
How to use checksums
a659573c3e85d163a08580c774f3610f307f1d2e4157abb45e6b724ae6104bd4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / dirsql-0.4.41-cp310-abi3-manylinux_2_28_x86_64.whl

Download URL dirsql-0.4.41-cp310-abi3-manylinux_2_28_x86_64.whl
Size 3.2 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
79e44b6c1017c786d3343abc932faabaa9e85e37abd6b3056615c21d1b83f411
BLAKE2b-256 checksum
How to use checksums
5250f67a208a250c50763a2b6f375bcdead6328c6af855d07110d8cae1be0d5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / dirsql-0.4.41-cp310-abi3-manylinux_2_28_aarch64.whl

Download URL dirsql-0.4.41-cp310-abi3-manylinux_2_28_aarch64.whl
Size 3.0 MB
Tags CPython 3.10 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
558d72c288f5e18142354706bf539d1429a01b624e2859d3ba41058f5a763514
BLAKE2b-256 checksum
How to use checksums
b290e9e216dd0696304ed49617e0ee24d5bc96a0248dde01e43fcdd45f460834
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / dirsql-0.4.41-cp310-abi3-macosx_11_0_arm64.whl

Download URL dirsql-0.4.41-cp310-abi3-macosx_11_0_arm64.whl
Size 2.8 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
0edabf0ee757636899a8da333095064b508f960380984c420a9d195459bc7ce0
BLAKE2b-256 checksum
How to use checksums
1eab79162e4aeb7266bd004728a00535eb043fcf270b1c998f662018bbd0faa6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release files / dirsql-0.4.41-cp310-abi3-macosx_10_12_x86_64.whl

Download URL dirsql-0.4.41-cp310-abi3-macosx_10_12_x86_64.whl
Size 3.0 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
c7ab5f29cd84889928e9da076b7e81b5b57b35c44d7650247e14b2b137a0ceb0
BLAKE2b-256 checksum
How to use checksums
83e35c062630850abe55502fcb73c936d5812f576a024a0775ddd1dbac595d5e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 17, 2026.

Transparency log

Release history Release notifications | RSS feed

0.4.56

6 release files

0.4.55

6 release files

0.4.54

6 release files

0.4.53

6 release files

0.4.52

6 release files

0.4.51

6 release files

0.4.50

6 release files

0.4.49

6 release files

0.4.48

6 release files

0.4.47

6 release files

0.4.46

6 release files

0.4.45

6 release files

0.4.44

6 release files

0.4.43

6 release files

0.4.42

6 release files

This release

0.4.41 This release

6 release files

0.4.40

6 release files

0.4.30

6 release files

0.4.29

6 release files

0.4.28

6 release files

0.4.27

6 release files

0.4.26

6 release files

0.4.25

6 release files

0.4.24

6 release files

0.4.23

6 release files

0.4.22

6 release files

0.4.21

6 release files

0.4.20

6 release files

0.4.19

6 release files

0.4.18

6 release files

0.4.17

6 release files

0.4.16

6 release files

0.4.9

6 release files

0.4.8

6 release files

0.4.7

6 release files

0.4.6

6 release files

0.4.5

6 release files

0.4.4

6 release files

0.4.3

6 release files

0.4.2

6 release files

0.4.1

6 release files

0.4.0

6 release files

0.3.99

6 release files

0.3.98

6 release files

0.3.97

6 release files

0.3.96

6 release files

0.3.95

6 release files

0.3.94

6 release files

0.3.93

6 release files

0.3.92

6 release files

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