A dictionary where values are removed after a certain time
Project description
TimerDict
This package provides a simple dictionary-like class, which drops items after a set amount of time.
from datetime import timedelta
from typing import Union
# When creating a TimerDict specify for how long items should live for:
my_dict = TimerDict(default_duration=timedelta(minutes=5))
# Then add items like you would to any dictionary
my_dict["foo"] = "bar"
# Or use the `put` method if you want to explicitly set the duration for a key
my_dict.put('foo', 'bar', timedelta(seconds=10))
# Getting items also works just like you'd would expect
print(my_dict['foo'])
Implementation Details
Internally, the dict keeps a queue of all items and when they should be removed.
The items are then purged whenever control flow passes to the dictionary, such
as when adding or getting an item. There is no separate thread or async
task
running in the background.
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
timer_dict-1.0.0.tar.gz
(3.1 kB
view details)
Built Distribution
File details
Details for the file timer_dict-1.0.0.tar.gz
.
File metadata
- Download URL: timer_dict-1.0.0.tar.gz
- Upload date:
- Size: 3.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.10.9 Linux/6.2.5-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d53ae6d42bf722abdb9c061c6beb8a9d1ca9485e7c82c39decd43f64017e0215 |
|
MD5 | e5f6b3b5e0bf7d6553ec37a8bf245865 |
|
BLAKE2b-256 | 6d4b1d1a0720fc448f789d41297b6e063fc38e33f4df227f4a36436b6653c9e1 |
File details
Details for the file timer_dict-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: timer_dict-1.0.0-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.4.0 CPython/3.10.9 Linux/6.2.5-arch1-1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90ba4f310c377a6813daecfa6fd3d7d4acdda45527d1b332a413a8bc0c0e04e6 |
|
MD5 | fb14f98a76b1af0574ce7422bc614dc9 |
|
BLAKE2b-256 | 16bd8f6139e75a82f1de7e6e54f535f109c2b4e63a20cedbff15e816d7bee0dd |