dictime
Time dimensional dictionaries, featuring expiring and future key values.
dictime
extends the standard pythondict
with 3 distinct additions
Install
pip install dictime
dict
with
Extends - keys that may have a future value, but not exist now
- keys that can expire in the future
- keys that have multiple values, but only one value at any given time
Policies
- keys can only have 1 value at any moment
- the extra values will be removed in the order they were added
- calling methods like
":key" in dictime
ordictime.has_key(":key")
will result inTrue
only when the key has a value that ispresent
.- Therefore, if the key has no value now, but does so in the future it will return
False
- Therefore, if the key has no value now, but does so in the future it will return
Examples
from dictime import dictime
from datetime import timedelta
from time import sleep
best = dictime()
best.set("who", "corey", expires=timedelta(seconds=10))
best.set("who", "casey", future=timedelta(seconds=10))
best.get("who") # "corey"
time.sleep(10)
best.get("who") # "casey"
Notice in the example below how the key
who
will have 2 values but they are at different times
Arguments
The method .set()
accepts inline arguments in the following arrangement
_dictime.set(:key, :value, :expires default None, :future default None)
- key: any object
- value: any object
-
expres accepts:
-
None
: the value will never expire -
datetime.datetime
: the value will expire ondatetime
-
datetime.timedelta
: the value will expire onnow + timedelta
-
dict
: expire onnow + timedelta(**dict)
-
-
future accepts:
-
None
: set this keys value now -
datetime.datetime
: the key will have this value ondatetime
-
datetime.timedelta
: the value will have this value onnow + timedelta
-
dict
: the key will have this value onnow + timedelta(**dict)
-