# py-expiring-dict
Python dict with TTL support for auto-expiring caches
# Install
```bash
pip install expiring-dict
```
# Usage
## Class Level TTL
```python
from time import sleep
from expiring_dict import ExpiringDict
cache = ExpiringDict(1) # Keys will exist for 1 second
cache["abc123"] = "some value"
assert "abc123" in cache
sleep(1)
assert "abc123" not in cache
```
## Key Level TTL
```python
from time import sleep
from expiring_dict import ExpiringDict
cache = ExpiringDict() # No TTL set, keys set via [] will not expire
cache["abc"] = "persistent"
cache.ttl("123", "expired", 1) # This will expire after 1 second
assert "abc" in cache
assert "123" in cache
sleep(1)
assert "abc" in cache
assert "123" not in cache
```
Raw data
{
"_id": null,
"home_page": "https://github.com/dparker2/py-expiring-dict",
"name": "expiring-dict",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": null,
"author": "David Parker",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/61/f8/74423159ad15b2f48f0dde2aea000a6892aed8a33171ec424104e5ad4740/expiring-dict-1.1.1.tar.gz",
"platform": null,
"description": "# py-expiring-dict\nPython dict with TTL support for auto-expiring caches\n\n\n# Install\n```bash\npip install expiring-dict\n```\n\n# Usage\n## Class Level TTL\n```python\nfrom time import sleep\nfrom expiring_dict import ExpiringDict\n\ncache = ExpiringDict(1) # Keys will exist for 1 second\n\ncache[\"abc123\"] = \"some value\"\nassert \"abc123\" in cache\nsleep(1)\nassert \"abc123\" not in cache\n```\n\n## Key Level TTL\n```python\nfrom time import sleep\nfrom expiring_dict import ExpiringDict\n\ncache = ExpiringDict() # No TTL set, keys set via [] will not expire\n\ncache[\"abc\"] = \"persistent\"\ncache.ttl(\"123\", \"expired\", 1) # This will expire after 1 second\nassert \"abc\" in cache\nassert \"123\" in cache\nsleep(1)\nassert \"abc\" in cache\nassert \"123\" not in cache\n```\n",
"bugtrack_url": null,
"license": null,
"summary": "Python dict with TTL support for auto-expiring caches",
"version": "1.1.1",
"project_urls": {
"Homepage": "https://github.com/dparker2/py-expiring-dict"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "00bbeb786bb0cbc257d9cba8bb0737223ffce336fa9b3e9ab6ddc6b337b0d6ba",
"md5": "822f81401e5d015a0587ff3b98f2a879",
"sha256": "c5387bfc1cac9b4e78d37ab787a438ca29e20c6d360a230ed3ce8cfca088d53f"
},
"downloads": -1,
"filename": "expiring_dict-1.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "822f81401e5d015a0587ff3b98f2a879",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 3628,
"upload_time": "2024-09-16T17:55:22",
"upload_time_iso_8601": "2024-09-16T17:55:22.138687Z",
"url": "https://files.pythonhosted.org/packages/00/bb/eb786bb0cbc257d9cba8bb0737223ffce336fa9b3e9ab6ddc6b337b0d6ba/expiring_dict-1.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "61f874423159ad15b2f48f0dde2aea000a6892aed8a33171ec424104e5ad4740",
"md5": "3c5fe36867986ecc01f6e6f3b02e176e",
"sha256": "277942edc60d5b123457c1a468698c94923dbfac8d40b263b921c04e6940dc09"
},
"downloads": -1,
"filename": "expiring-dict-1.1.1.tar.gz",
"has_sig": false,
"md5_digest": "3c5fe36867986ecc01f6e6f3b02e176e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3216,
"upload_time": "2024-09-16T17:55:23",
"upload_time_iso_8601": "2024-09-16T17:55:23.404213Z",
"url": "https://files.pythonhosted.org/packages/61/f8/74423159ad15b2f48f0dde2aea000a6892aed8a33171ec424104e5ad4740/expiring-dict-1.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-16 17:55:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "dparker2",
"github_project": "py-expiring-dict",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "expiring-dict"
}