Skip to main content

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


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

pyttldict-1.0.0-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page