Metadata-Version: 2.1
Name: pyttldict
Version: 1.0.0
Summary: Python Dictionary with timed expiring keys
Author-email: Gurjant Kalsi <me@gurjantkalsi.com>
License: MIT License
        
        Copyright (c) 2024 Gurjant Kalsi
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/gkalsi/ttl-dict
Keywords: ttl,expiry,dictionary,expiring
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE

# py-ttl-dict
Python Dictionary that supports expiring keys.

## Usage
```Python
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
```Bash
$ pip install py-ttl-dict
```

## Additional Usage
### Convert to a Python Dict
```Python
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.
