A high-performance Python library providing bucket-based rotating data structures with approximate TTL eviction and strict memory constraints.
Project description
RoTTL — Rotating TTL Data Structures
RoTTL provides memory-efficient rotating sets, dicts, and Bloom filters with approximate TTL-based eviction.
Rather than maintaining per-item expiry timestamps, the TTL window is divided into a fixed number of rotating buckets — expired buckets are evicted as a whole, trading per-item precision for significantly lower memory usage and faster writes, at the cost of sequential bucket scans.
The library exposes three structures:
RotatingTTLSet— a rotating, TTL-based set backed by native Pythonsetbuckets.RotatingTTLDict— a rotating, TTL-based dict backed by native Pythondictbuckets.RotatingTTLBloom— a rotating, TTL-based Bloom filter backed byrbloom.
All three structures rotate automatically based on time and capacity, though capacity tracking differs between implementations:
RotatingTTLSetandRotatingTTLDict: Capacity is checked inline on every insertion via an $O(1)$len()call.RotatingTTLBloom: Estimating the number of unique inserted items requires inspecting filter occupancy by counting set bits — an $O(M)$ operation. To keep the hot path $O(1)$ for the vast majority of insertions, capacity is managed via an amortized countdown that defers the check.
RotatingTTLSet and RotatingTTLDict support an optional history fast-reject mode, which maintains an auxiliary Bloom filter over all non-expired historical buckets. This allows most negative lookups to be rejected without scanning the full bucket deque, at the cost of filter rebuild on each rotation.
When to use RoTTL
- Approximate TTL is acceptable. Expiry happens at bucket boundaries, not per item. Under normal load (no capacity-based eviction), items live between
ttl - (ttl / num_buckets)andttlseconds. Capacity pressure can cause earlier eviction. - Memory-constrained environments. RoTTL's bucket-level eviction avoids per-item bookkeeping, keeping structure overhead proportional to bucket count rather than item count.
RotatingTTLDictuses roughly 3–4× less memory thancachetools.TTLCache.
- Write-heavy workloads. RoTTL's write path is lightweight — no per-item expiry metadata is maintained on insertion.
RotatingTTLDictis 6–15× faster thancachetools.TTLCacheon insertions (varies by fast-reject usage and rotation pressure).
- Lookup performance scales with configuration. Lookups scan up to
num_bucketsbuckets, so with a small bucket count the overhead is negligible. With a large bucket count, hit cost depends on which bucket the item is found in, and miss cost grows linearly.RotatingTTLSetandRotatingTTLDict's history fast-reject option makes most miss latency independent ofnum_buckets, at the cost of slower rotations.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rottl-0.0.4.tar.gz.
File metadata
- Download URL: rottl-0.0.4.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e96f834e63e707668462f317458a7fdd54717dd57acb4d6736c308705cd9a26d
|
|
| MD5 |
b34c3ad3c2012b281e50655023503a58
|
|
| BLAKE2b-256 |
2595c3276a63dae9bf3781103c9d34cb430cf47e5167a4ea522e92979a5b6d0b
|
Provenance
The following attestation bundles were made for rottl-0.0.4.tar.gz:
Publisher:
python-publish.yml on sharvul/rottl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rottl-0.0.4.tar.gz -
Subject digest:
e96f834e63e707668462f317458a7fdd54717dd57acb4d6736c308705cd9a26d - Sigstore transparency entry: 1394311621
- Sigstore integration time:
-
Permalink:
sharvul/rottl@f843ed402e4767de436a154371a3b105c52eca00 -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/sharvul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f843ed402e4767de436a154371a3b105c52eca00 -
Trigger Event:
release
-
Statement type:
File details
Details for the file rottl-0.0.4-py3-none-any.whl.
File metadata
- Download URL: rottl-0.0.4-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
58050d45e6f89ce046f67c56525f66352c68bc883e6c548ba200c82c3fffe5fd
|
|
| MD5 |
18e776bc705f16b040514b9474ff0a1b
|
|
| BLAKE2b-256 |
c8149ea5c0f1f1369c1857536bf846869b1c146bdde22ba6dc2a4c515d8dcdf0
|
Provenance
The following attestation bundles were made for rottl-0.0.4-py3-none-any.whl:
Publisher:
python-publish.yml on sharvul/rottl
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rottl-0.0.4-py3-none-any.whl -
Subject digest:
58050d45e6f89ce046f67c56525f66352c68bc883e6c548ba200c82c3fffe5fd - Sigstore transparency entry: 1394311639
- Sigstore integration time:
-
Permalink:
sharvul/rottl@f843ed402e4767de436a154371a3b105c52eca00 -
Branch / Tag:
refs/tags/v0.0.4 - Owner: https://github.com/sharvul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f843ed402e4767de436a154371a3b105c52eca00 -
Trigger Event:
release
-
Statement type: