Skip to main content
=========================================================================
expiringsqlitedict -- persistent ``dict``, backed-up by SQLite and pickle
=========================================================================

|License|_

.. _Downloads: https://pypi.python.org/pypi/expiringsqlitedict
.. _License: https://pypi.python.org/pypi/expiringsqlitedict

A lightweight wrapper around Python's sqlite3 database with a simple, Pythonic
dict-like interface. This fork is modified to implement a metatable and
automatic expiring and vacuuming semantics, as well as some appropriate locking.
This also compresses values automatically.

.. code-block:: python

>>> from expiringsqlitedict import SqliteDict
>>> with SqliteDict('./my_db.sqlite', autocommit=True) as mydict:
>>> mydict['some_key'] = any_picklable_object
>>> print mydict['some_key'] # prints the new value
>>> for key, value in mydict.iteritems():
>>> print key, value
>>> print len(mydict) # etc... all dict functions work

Pickle is used internally to (de)serialize the values. Keys are arbitrary strings,
values arbitrary pickle-able objects. This must be used within a context
manager.

Features
--------

* Values can be **any picklable objects** (uses ``cPickle`` with the highest protocol).
* Support for **access from multiple programs or threads**, using a lockfile.
* Support for **custom serialization or compression**:

.. code-block:: python

# use JSON instead of pickle
>>> import json
>>> mydict = SqliteDict('./my_db.sqlite', encode=json.dumps, decode=json.loads)

# apply zlib compression after pickling
>>> import zlib, pickle, sqlite3
>>> def my_encode(obj):
... return sqlite3.Binary(zlib.compress(pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)))
>>> def my_decode(obj):
... return pickle.loads(zlib.decompress(bytes(obj)))
>>> mydict = SqliteDict('./my_db.sqlite', encode=my_encode, decode=my_decode)


Installation
------------

The module has no dependencies beyond Python itself.

Install or upgrade with::

pip install expiringsqlitedict

or from the `source tar.gz <http://pypi.python.org/pypi/expiringsqlitedict>`_::

python setup.py install

Documentation
-------------

Standard Python document strings are inside the module:

.. code-block:: python

>>> import expiringsqlitedict
>>> help(expiringsqlitedict)

(but it's just ``dict`` with a commit, really).

**Beware**: because of Python semantics, ``expiringsqlitedict`` cannot know when
a mutable SqliteDict-backed entry was modified in RAM. For example,
``mydict.setdefault('new_key', []).append(1)`` will leave ``mydict['new_key']``
equal to empty list, not ``[1]``. You'll need to explicitly assign the mutated
object back to SqliteDict to achieve the same effect:

.. code-block:: python

>>> val = mydict.get('new_key', [])
>>> val.append(1) # sqlite DB not updated here!
>>> mydict['new_key'] = val # now updated


For developers
--------------

Install::

# pip install nose
# pip install coverage

To perform all tests::

# make test-all

To perform all tests with coverage::

# make test-all-with-coverage


Comments, bug reports
---------------------

``expiringsqlitedict`` resides on `github <https://github.com/absperf/expiringsqlitedict>`_. You can file issues or pull
requests there.


----

``expiringsqlitedict`` is open source software released under the
`Apache 2.0 license <http://opensource.org/licenses/apache2.0.php>`_.
Copyright (c) 2011-2018 `Radim Řehůřek <http://radimrehurek.com>`_ and
contributors. The changes in this fork copyright (c) 2018 Absolute Performance,
Inc.


Release files for expiringsqlitedict 1.2.0

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

Built distribution (wheel)

Table of built distributions (wheels) for expiringsqlitedict 1.2.0
File Interpreter ABI Platform
expiringsqlitedict-1.2.0-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / expiringsqlitedict-1.2.0-py2.py3-none-any.whl

Download URL expiringsqlitedict-1.2.0-py2.py3-none-any.whl
Size 11.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
ad74c9125d4a95d1d66880c401f0c3cbbf3218d5bf3e31b6fb37cb48c881ec9a
BLAKE2b-256 checksum
How to use checksums
109f944cd66dc9c30c1558150d4c4492fcadf57e85338598f2ba0968f3c9c179
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

7.0.5

2 release files

7.0.4

2 release files

7.0.2

2 release files

7.0.1

2 release files

7.0.0

2 release files

6.2.0

2 release files

6.1.0

2 release files

6.0.0

2 release files

5.0.2

2 release files

5.0.1

2 release files

5.0.0

2 release files

4.1.0

2 release files

4.0.1

2 release files

4.0.0

2 release files

3.2.1

2 release files

3.2.0

2 release files

3.1.0

2 release files

3.0.1

2 release files

3.0.0

2 release files

2.2.1

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

1 release file

1.2.4

1 release file

1.2.3

1 release file

1.2.2

1 release file

1.2.1

1 release file

This release

1.2.0 This release

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

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