Package: expiringsqlitedict
expiringsqlitedict -- expiring file-backeddictA lightweight wrapper around Python's sqlite3 database with a MutableMapping
interface:fromexpiringsqlitedictimportSqliteDictwithSqliteDict('./my_db.sqlite')asmydict:mydict['some_key']=any_picklable_objectprint(mydict['some_key'])# prints the new valueforkey,valueinmydict.items():print((key,value))print(len(mydict))# etc... all dict functions workjson is used internally by default to serialize the values. Keys are
arbitrary strings, values arbitrary json-able objects.  This must be used
within a context manager, and serialization can be overridden with your own.
The database is wrapped with a transaction, and any exception thrown out of the
context manager rolls back all changes.This was forked off ofsqlitedictin order to add auto-expiring functionality, and initially was quite similar to
it.  Version 2.0 split of completely and takes the module into a complete
rewrite, mostly to remove unnecessary Python 2 compatibility, simplify the API,
completely enforce a context manager for typical cases, add full typing
throughout, and use sqlite triggers for expiration cleanup.Version 3 set the default encoding to json, and made many other API refinements.This version also does not vacuum at all automatically.  It did in previous
versions, but this was kind of a silly behavior to put into the library itself.
If you want your database file intermittently vacuumed, you should put such
behavior into a crontab or use thesqlite3module to do it yourself
intermittently.FeaturesValues can be any json-capable objects (this can be customized to be as
flexible as you need, through custom serializers)Support for access from multiple programs or threads, with locking fully
managed by sqlite itself.A very simple codebase that is easy to read, relying on sqlite for as much
behavior as possible.A simple autocommit wrapper (SimpleSqliteDict), if you really can't
handle a context manager and need something that fully handles like a dict.
You can specify aisolation_levelon this to have to commit and roll back
yourself.An on-demand wrapper (OnDemand), for situations where you want to open and
close the database in as narrow a window as possible.Support for custom serialization or compression:importorjsonwithSqliteDict('some.db',serializer=orjson)asmydict:mydict['some_key']=some_json_encodable_objectprint(mydict['some_key'])InstallationThe module has no dependencies beyond Python itself.Install with pip as usual:pipinstallexpiringsqlitedictTestingYou may test this by runningtest.pywithPYTHONPATHset to the current
working directory.  There is a convenience justfile to do this for you when you
run:justtestThis will run all tests against all supported versions of Python (and 3.6), as
well as all supported versions of Alpine, CentOS, Debian, Fedora, and Ubuntu
Linux.DocumentationDocumentation is available on readthedocsStandard Python document strings are inside the module>>>importexpiringsqlitedict>>>help(expiringsqlitedict)Comments, bug reportsexpiringsqlitedictresides ongithub. You can file issues or pull
requests there.expiringsqlitedictis open source software released under theMozilla Public License 2.0All versions copyright (c) 2018-2023 Absolute Performance, Inc.