Python Dictionary with timed expiring keys
Project description
py-ttl-dict
Python Dictionary that supports expiring keys.
Usage
import ttldict
import time
my_dict = ttldict.TTLDict()
my_dict.set("key", "value," 2) # Expire Key after 2 seconds
print(my_dict.get("key")) # Prints "value"
time.sleep(3)
print(my_dict.get("key")) # Prints "None"
Install
$ pip install py-ttl-dict
Additional Usage
Convert to a Python Dict
import ttldict
import time
my_dict = ttldict.TTLDict()
my_dict.set("key", "value," 10)
python_dict = my_dict.as_dict()
print(python_dict)
Implementation Details
This implementation maintains a map
of KV-pairs as well as a heap
of expiry times. Insert is O(logn)
, Update TTL is O(n)
and all accessors are O(klogn)
where k
is the number of entries that must be evicted.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for pyttldict-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10cf8626f6696ed489249fc0dc05e05246559ceca02fd2bae67c6fe799714333 |
|
MD5 | 09e46b97286b1646f8b5439f6b466b18 |
|
BLAKE2b-256 | f217fe532bb6bed01ba2ae3542d90545fde9197af658b99c38672dc5972983e6 |