Skip to main content

Python TTL Dict

Documentation Status license tests Pre-commit Mypy

Installation

Installation is available using pip install ttlru-map.

Core Features

  • TTL Dict: A thread-safe dictionary that automatically removes keys after a certain amount of time or if max size is reached.
  • It can be used as a simple in-memory cache.
  • Simple - The TTLMap derives MutableMapping and implements the same interface as the built-in dict class. It can be used as a drop-in replacement for dict.
  • Efficient - The TTLMap is designed to be efficient in terms of both time and space complexity.
  • Thread-safe - The TTLMap is thread-safe. It can be used in multithreaded applications without any additional synchronization.
  • Lazy - The TTLMap is lazy. It does not spawn any additional threads or processes. Computing the time-to-live is done only when the TTLMap is accessed.
  • Zero dependencies - The TTLMap has no dependencies other than the Python standard library.
  • LRU support - The TTLMap supports LRU (least recently used) eviction policy. It can be configured to evict either the last set item or the least recently accessed item.

Usage Examples

from datetime import timedelta
from time import sleep

from ttlru_map import TTLMap

cache: TTLMap[str, str] = TTLMap(ttl=timedelta(seconds=10))

cache['key'] = 'value'
print(cache['key'])  # 'value'

# Wait for 10 seconds
sleep(10)
print(cache['key'])  # KeyError

If you want to add LRU functionality to your cache, you can maxsize argument

from ttlru_map import TTLMap

cache: TTLMap[str, str] = TTLMap(ttl=None, max_size=2)

cache['key1'] = 'value1'
cache['key2'] = 'value2'
cache['key3'] = 'value3'

print(cache.get('key1'))  # None
print(cache.get('key2'))  # 'value2'
print(cache.get('key3'))  # 'value3'

Metadata

Release files for ttlru-map 1.2.0.post2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ttlru-map 1.2.0.post2
File Size Uploaded
ttlru_map-1.2.0.post2.tar.gz 76.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ttlru-map 1.2.0.post2
File Interpreter ABI Platform
ttlru_map-1.2.0.post2-py3-none-any.whl Python 3 none any Details

Total release size: 89.5 kB

Release files / ttlru_map-1.2.0.post2.tar.gz

Download URL ttlru_map-1.2.0.post2.tar.gz
Size 76.0 kB
Tags Source
SHA-256 checksum
How to use checksums
30e58ed07019a15669f51d9069d970df32ff920f8b568469e0ca544dcadf23e8
BLAKE2b-256 checksum
How to use checksums
0f3c3ef72318835f8a551fa2eced1918c43ee468441976642050b1b16e61f61a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 11, 2025.

Transparency log

Release files / ttlru_map-1.2.0.post2-py3-none-any.whl

Download URL ttlru_map-1.2.0.post2-py3-none-any.whl
Size 13.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
14b94680556fc93c5951044bc4b3d0ae00f4045d24799676b024d9b78843016a
BLAKE2b-256 checksum
How to use checksums
0eec989843c28e68e08707a189a4124e8c78f99139f7424bb0ef08c4df6814d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 11, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.2.0.post2 This release

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page