Skip to main content

No project description provided

Project description

Introduction

This library provides the same experience of builtin dict, plus automatical time-to-live (TTL) management.

Different from some other libraries, this one does not require background thread and guarantees that the expired items does not affect results.

Note that technically our TTLDict class is a subclass of MutableMapping instead of dict.

How to Install

Simply run pip install time-to-live-dict.

Usage Example

In [1]: from ttl_dict import TTLDict

In [2]: from datetime import timedelta

In [3]: from time import sleep

In [4]: ttl = timedelta(seconds=2)
   ...:
   ...: d = TTLDict(ttl, {"a": 1})
   ...: print(d)
   ...:
   ...: sleep(1)
   ...: print(d)
   ...:
   ...: sleep(1)
   ...: print(d)
{'a': 1}
{'a': 1}
{}

In [5]: ttl1 = timedelta(seconds=2)
   ...: ttl2 = timedelta(seconds=4)
   ...:
   ...: d1 = TTLDict(ttl1, {"a": 1})
   ...: d2 = TTLDict(ttl2, {"b": 2})
   ...:
   ...: d = d1 | d2
   ...: print(d)
   ...:
   ...: sleep(2)
   ...: print(d)
   ...:
   ...: sleep(2)
   ...: print(d)
{'a': 1, 'b': 2}
{'b': 2}
{}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

time_to_live_dict-0.1.1.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

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

time_to_live_dict-0.1.1-py3-none-any.whl (3.6 kB view details)

Uploaded Python 3

File details

Details for the file time_to_live_dict-0.1.1.tar.gz.

File metadata

  • Download URL: time_to_live_dict-0.1.1.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.9

File hashes

Hashes for time_to_live_dict-0.1.1.tar.gz
Algorithm Hash digest
SHA256 37180e10a4fa447dec56e9e80abd8465749a00ad5dd67b0201fe1e7d72b87447
MD5 4cd0e8e1d1962caf7b3e9729e3f7bf2a
BLAKE2b-256 a60236e39a6e6da3b9f6ffa54675571ca58e0a6d6c3ff7065ab2b598c746bc26

See more details on using hashes here.

File details

Details for the file time_to_live_dict-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for time_to_live_dict-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7324628408663ae3b801d8fa979f39b27678fafad1870226db1db245d08b8d55
MD5 7023e59f4f181a63948311793c3710da
BLAKE2b-256 4f545a4b6056ff4a8b135e9e25f24a11f60348811e5475b54790b54ae7723950

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