sqlfs
fsspec adapter backed by SQL.
sqlfs exposes a single node table as an fsspec filesystem (protocol = "sql").
Paths form a tree and file bodies are stored as JSON. Works over SQLite and
PostgreSQL via SQLAlchemy.
Installation
pip install joha-sqlfs
Or with uv:
uv add joha-sqlfs
Development setup
uv sync --group dev
prek install
Current scope
- synchronous filesystem operations only
- path CRUD via
pipe/cat,ls,glob,rm,info, andopen - SQLite and PostgreSQL backends via SQLAlchemy
- file payloads are stored as JSON with
content_type = "application/json" - table creation and migrations stay on the client side
Schema contract
sqlfs does not create or own the table. The client creates the
fs_node table; sqlfs connects and validates the contract on startup.
Required columns:
pathparenttype(fileordir)content_typecontentsizeatimemtimectime
A minimal SQLite-compatible schema looks like this:
CREATE TABLE fs_node (
path TEXT PRIMARY KEY,
parent TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN ('file', 'dir')),
content_type TEXT,
content TEXT,
size INTEGER NOT NULL DEFAULT 0,
atime REAL,
mtime REAL,
ctime REAL
);
CREATE INDEX ix_fs_node_parent ON fs_node(parent);
For PostgreSQL, content can be a JSON-capable type such as JSONB.
Usage
Register the "sql" protocol on the client side, then use it through fsspec:
import fsspec
from sqlfs import SQLFileSystem
fsspec.register_implementation("sql", SQLFileSystem)
fs = fsspec.filesystem(
"sql",
url="sqlite:///app.db", # or "postgresql+psycopg://user:pass@host/db"
table="fs_node",
)
fs.pipe_file("/cv/1/data", b'{"name": "John Doe"}')
fs.cat("/cv/1/data") # b'{"name": "John Doe"}'
fs.ls("/cv") # ["/cv/1"]
fs.glob("/cv/*/data") # ["/cv/1/data"]
File-like access works too:
with fs.open("/cv/1/data", "wb") as f:
f.write(b'{"name": "John Doe"}')
Tests
uv run pytest
The PostgreSQL test cases use testcontainers and require Docker.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file joha_sqlfs-0.1.1.tar.gz.
File metadata
- Download URL: joha_sqlfs-0.1.1.tar.gz
- Upload date:
- Size: 92.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d924b5fe8d3e00a98e999465ceae734767b9de343b1ee3e810b7221a63737060
|
|
| MD5 |
ed71ca13727e866990dd15878c455833
|
|
| BLAKE2b-256 |
c5cca58db78dadaed524eadc21777cae86c99a055de2d93dfc9ff0608d83bed0
|
File details
Details for the file joha_sqlfs-0.1.1-py3-none-any.whl.
File metadata
- Download URL: joha_sqlfs-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23aba96c3e5f27fa4a8cc8c142667a0a3168684e41760ae6aa71fb61488ef865
|
|
| MD5 |
f28c674652c5c4f7472d2b0678bf53b7
|
|
| BLAKE2b-256 |
6fad25774464009c7ccb8d926d8665cf57a1681b902c7a20c177e105ef4353ba
|