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

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

Details for the file pyttldict-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyttldict-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.6

File hashes

Hashes for pyttldict-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 10cf8626f6696ed489249fc0dc05e05246559ceca02fd2bae67c6fe799714333
MD5 09e46b97286b1646f8b5439f6b466b18
BLAKE2b-256 f217fe532bb6bed01ba2ae3542d90545fde9197af658b99c38672dc5972983e6

See more details on using hashes here.

Supported by

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