dictime

Dictionary with the dimension of time


Keywords
dict, list, expire, future, cache
License
Apache-2.0
Install
pip install dictime==0.0.1

Documentation

dictime

Build Status Version codecov.io

Time dimensional dictionaries, featuring expiring and future key values. dictime extends the standard python dict with 3 distinct additions

Install

pip install dictime

Extends dict with

  1. keys that may have a future value, but not exist now
  2. keys that can expire in the future
  3. keys that have multiple values, but only one value at any given time

Policies

  1. keys can only have 1 value at any moment
    • the extra values will be removed in the order they were added
  2. calling methods like ":key" in dictime or dictime.has_key(":key") will result in True only when the key has a value that is present.
    • Therefore, if the key has no value now, but does so in the future it will return False

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 on datetime
    • datetime.timedelta: the value will expire on now + timedelta
    • dict: expire on now + timedelta(**dict)
  • future accepts:
    • None: set this keys value now
    • datetime.datetime: the key will have this value on datetime
    • datetime.timedelta: the value will have this value on now + timedelta
    • dict: the key will have this value on now + timedelta(**dict)