expiringdict


Nameexpiringdict JSON
Version 1.2.2 PyPI version JSON
download
home_pagehttps://www.mailgun.com/
SummaryDictionary with auto-expiring values for caching purposes
upload_time2022-06-21 09:12:30
maintainer
docs_urlNone
authorMailgun Technologies Inc.
requires_python
licenseApache 2
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Expiring Dict
-------------

.. image:: https://travis-ci.org/mailgun/expiringdict.svg?branch=master
    :target: https://travis-ci.org/mailgun/expiringdict

.. image:: https://coveralls.io/repos/github/mailgun/expiringdict/badge.svg?branch=master
    :target: https://coveralls.io/github/mailgun/expiringdict?branch=master

ChangeLog_

expiringdict is a Python caching library. The core of the library is ExpiringDict class which
is an ordered dictionary with auto-expiring values for caching purposes. Expiration happens on
any access, object is locked during cleanup from expired values. ExpiringDict can not store
more than `max_len` elements - the oldest will be deleted.

**Note:** Iteration over dict and also keys() do not remove expired values!

.. _ChangeLog: ./CHANGELOG.rst

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

If you wish to install from PyPi:

.. code-block:: bash

    pip install expiringdict

If you wish to download the source and install from GitHub:

.. code-block:: bash

    git clone git@github.com:mailgun/expiringdict.git
    python setup.py install

or to install with test dependencies (`Nose <http://readthedocs.org/docs/nose/en/latest/>`_, `Mock <http://www.voidspace.org.uk/python/mock/>`_, `coverage <http://nedbatchelder.com/code/coverage/>`_) run from the directory above:

.. code-block:: bash

    pip install -e expiringdict[test]

To run tests with coverage:

.. code-block:: bash

    nosetests --with-coverage --cover-package=expiringdict

Usage
-----

Create a dictionary with capacity for 100 elements and elements expiring in 10 seconds:

.. code-block:: py

    from expiringdict import ExpiringDict
    cache = ExpiringDict(max_len=100, max_age_seconds=10)

put and get a value there:

.. code-block:: py

     cache["key"] = "value"
     cache.get("key")

copy from dict or OrderedDict:

.. code-block:: py

     from expiringdict import ExpiringDict
     my_dict=dict()
     my_dict['test'] = 1
     cache = ExpiringDict(max_len=100, max_age_seconds=10, items=my_dict)
     assert cache['test'] == 1

copy from another ExpiringDict, with or without new length and timeout:

.. code-block:: py

     from expiringdict import ExpiringDict
     cache_hour = ExpiringDict(max_len=100, max_age_seconds=3600)
     cache_hour['test'] = 1
     cache_hour_copy = ExpiringDict(max_len=None, max_age_seconds=None, items=cache_hour)
     cache_minute_copy = ExpiringDict(max_len=None, max_age_seconds=60, items=cache_hour)
     assert cache_minute_copy['test'] == 1


pickle :

.. code-block:: py

    import dill
    from expiringdict import ExpiringDict
    cache = ExpiringDict(max_len=100, max_age_seconds=10)
    cache['test'] = 1
    pickled_cache = dill.dumps(cache)
    unpickled_cache = dill.loads(cache)
    assert unpickled_cache['test'] == 1

            

Raw data

            {
    "_id": null,
    "home_page": "https://www.mailgun.com/",
    "name": "expiringdict",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Mailgun Technologies Inc.",
    "author_email": "admin@mailgun.com",
    "download_url": "https://files.pythonhosted.org/packages/fc/62/c2af4ebce24c379b949de69d49e3ba97c7e9c9775dc74d18307afa8618b7/expiringdict-1.2.2.tar.gz",
    "platform": null,
    "description": "Expiring Dict\n-------------\n\n.. image:: https://travis-ci.org/mailgun/expiringdict.svg?branch=master\n    :target: https://travis-ci.org/mailgun/expiringdict\n\n.. image:: https://coveralls.io/repos/github/mailgun/expiringdict/badge.svg?branch=master\n    :target: https://coveralls.io/github/mailgun/expiringdict?branch=master\n\nChangeLog_\n\nexpiringdict is a Python caching library. The core of the library is ExpiringDict class which\nis an ordered dictionary with auto-expiring values for caching purposes. Expiration happens on\nany access, object is locked during cleanup from expired values. ExpiringDict can not store\nmore than `max_len` elements - the oldest will be deleted.\n\n**Note:** Iteration over dict and also keys() do not remove expired values!\n\n.. _ChangeLog: ./CHANGELOG.rst\n\nInstallation\n------------\n\nIf you wish to install from PyPi:\n\n.. code-block:: bash\n\n    pip install expiringdict\n\nIf you wish to download the source and install from GitHub:\n\n.. code-block:: bash\n\n    git clone git@github.com:mailgun/expiringdict.git\n    python setup.py install\n\nor to install with test dependencies (`Nose <http://readthedocs.org/docs/nose/en/latest/>`_, `Mock <http://www.voidspace.org.uk/python/mock/>`_, `coverage <http://nedbatchelder.com/code/coverage/>`_) run from the directory above:\n\n.. code-block:: bash\n\n    pip install -e expiringdict[test]\n\nTo run tests with coverage:\n\n.. code-block:: bash\n\n    nosetests --with-coverage --cover-package=expiringdict\n\nUsage\n-----\n\nCreate a dictionary with capacity for 100 elements and elements expiring in 10 seconds:\n\n.. code-block:: py\n\n    from expiringdict import ExpiringDict\n    cache = ExpiringDict(max_len=100, max_age_seconds=10)\n\nput and get a value there:\n\n.. code-block:: py\n\n     cache[\"key\"] = \"value\"\n     cache.get(\"key\")\n\ncopy from dict or OrderedDict:\n\n.. code-block:: py\n\n     from expiringdict import ExpiringDict\n     my_dict=dict()\n     my_dict['test'] = 1\n     cache = ExpiringDict(max_len=100, max_age_seconds=10, items=my_dict)\n     assert cache['test'] == 1\n\ncopy from another ExpiringDict, with or without new length and timeout:\n\n.. code-block:: py\n\n     from expiringdict import ExpiringDict\n     cache_hour = ExpiringDict(max_len=100, max_age_seconds=3600)\n     cache_hour['test'] = 1\n     cache_hour_copy = ExpiringDict(max_len=None, max_age_seconds=None, items=cache_hour)\n     cache_minute_copy = ExpiringDict(max_len=None, max_age_seconds=60, items=cache_hour)\n     assert cache_minute_copy['test'] == 1\n\n\npickle :\n\n.. code-block:: py\n\n    import dill\n    from expiringdict import ExpiringDict\n    cache = ExpiringDict(max_len=100, max_age_seconds=10)\n    cache['test'] = 1\n    pickled_cache = dill.dumps(cache)\n    unpickled_cache = dill.loads(cache)\n    assert unpickled_cache['test'] == 1\n",
    "bugtrack_url": null,
    "license": "Apache 2",
    "summary": "Dictionary with auto-expiring values for caching purposes",
    "version": "1.2.2",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "b8526dd0970c496764eea3bbbb30497c",
                "sha256": "09a5d20bc361163e6432a874edd3179676e935eb81b925eccef48d409a8a45e8"
            },
            "downloads": -1,
            "filename": "expiringdict-1.2.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b8526dd0970c496764eea3bbbb30497c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8456,
            "upload_time": "2022-06-21T09:12:28",
            "upload_time_iso_8601": "2022-06-21T09:12:28.652017Z",
            "url": "https://files.pythonhosted.org/packages/cb/84/a04c59324445f4bcc98dc05b39a1cd07c242dde643c1a3c21e4f7beaf2f2/expiringdict-1.2.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "04bf921308b3334f4c2fbaab35e5b4b7",
                "sha256": "300fb92a7e98f15b05cf9a856c1415b3bc4f2e132be07daa326da6414c23ee09"
            },
            "downloads": -1,
            "filename": "expiringdict-1.2.2.tar.gz",
            "has_sig": false,
            "md5_digest": "04bf921308b3334f4c2fbaab35e5b4b7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8137,
            "upload_time": "2022-06-21T09:12:30",
            "upload_time_iso_8601": "2022-06-21T09:12:30.415281Z",
            "url": "https://files.pythonhosted.org/packages/fc/62/c2af4ebce24c379b949de69d49e3ba97c7e9c9775dc74d18307afa8618b7/expiringdict-1.2.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-06-21 09:12:30",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "expiringdict"
}
        
Elapsed time: 0.03940s