introduction

swindl is the storage side of a Python web application: your objects in plain JSON files, searchable through a real search index, as one Store. No database server, no ORM, no migrations of a schema you never wanted.

It is three small libraries that work together:

It is made for the same software as SWL, its web side: admin screens, registries, catalogues, case files. Data that people search, filter and edit all day, in amounts from a few thousand to a few hundred thousand objects per kind.

motivation

Keep the data in files a person can read, make every change all-or-nothing, and let a real search engine, in process, answer the questions. That is swindl.

quick start

pip install swindl

A model says what is stored and what can be searched:

from sil.indexfield import IndexField
from sjdbl.field import Field
from swindl.store import Base, Store
from swindl.store.indexes import Commit
from swindl.store.store import QueryParams


class Record(Base):
    FIELDS = Base.FIELDS + [Field.str("title"), Field.str("artist"), Field.int("year")]
    INDEX = Base.INDEX + [
        IndexField.unqualified("all"),
        IndexField.untokenized("artist_exact", drilldown=True),
        IndexField.int("year", sortable=True),
    ]

    def index_values(self):
        values = super().index_values()
        values.update(all=f"{self.title} {self.artist}", artist_exact=self.artist,
                      year=self.year)
        return values


store = Store(data_dir, [Record], commit=Commit(immediate=True))

with store.transaction():                     # all of it, or none of it
    store.put(Record.create(title="Kind of Blue", artist="Miles Davis", year=1959))
    store.put(Record.create(title="Blue Train", artist="John Coltrane", year=1958))

result = store.query(QueryParams(
    Record, query="blue", sort="year", drilldown=[{"name": "artist_exact"}]))
result.total                                  # 2
[r.title for r in result.objs]                # ['Blue Train', 'Kind of Blue']
result.drilldown                              # {'artist_exact': [('John Coltrane', 1), ...]}

On disk: data_dir/store/Record/<id>.json, one readable file per record, and data_dir/index/Record/, the search index, which can always be rebuilt from the files.

what you get

docs

history

swindl grew out of Seecr’s work on search systems that harvest, enrich and index data. Its predecessor stored objects with SQLAlchemy in MySQL, which became slow with larger data sets and needed a database server next to every application. sjdbl replaced it with plain files; sil replaced Lucene, through a JVM, with tantivy, in process. What is left is small enough to understand completely.

Simplicity is a great virtue but it requires hard work to achieve it and education to appreciate it. And to make matters worse: complexity sells better.
Edsger W. Dijkstra, EWD 896 (1984)