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 sequentially scanned lookups.
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.
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 membership misses to be short-circuited without scanning the full bucket deque, at the cost of filter rebuild on each rotation.
RotatingTTLSet and RotatingTTLDict rotate automatically on both time and capacity. RotatingTTLBloom rotates automatically only by time, because estimating the number of items in a Bloom filter requires counting all set bits, which is too expensive to do on every insertion. Instead, maybe_rotate_by_saturation() can be called manually to check if the active bucket has exceeded its capacity, and if so — trigger rotation (to enforce the configured FPR).
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.
RotatingTTLSetandRotatingTTLDictuse roughly 3–4× less memory thancachetools.TTLCacheat all tested capacities.RotatingTTLBloomcan reduce memory even further, depending on the configuredbucket_fprandnum_buckets. - Write-heavy workloads. RoTTL's write path avoids the expensive per-item bookkeeping required for exact TTL, making it 6–15x faster than
cachetools.TTLCache(varies by usage of fast-reject 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.1.tar.gz.
File metadata
- Download URL: rottl-0.0.1.tar.gz
- Upload date:
- Size: 9.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e855fe7a2e938db90a90d49b4fe1310005611a0f124637bf86aa0729a9811632
|
|
| MD5 |
6841556ebc5558b55f8c501b6523329c
|
|
| BLAKE2b-256 |
4283b8287793074efa6addcb61cd2f9bd8e320b4bc217c7b5492327269def174
|
Provenance
The following attestation bundles were made for rottl-0.0.1.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.1.tar.gz -
Subject digest:
e855fe7a2e938db90a90d49b4fe1310005611a0f124637bf86aa0729a9811632 - Sigstore transparency entry: 1257320436
- Sigstore integration time:
-
Permalink:
sharvul/rottl@f5d18c37d3d2b1f28e3b86b8fbfa3bce9c76480f -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/sharvul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f5d18c37d3d2b1f28e3b86b8fbfa3bce9c76480f -
Trigger Event:
release
-
Statement type:
File details
Details for the file rottl-0.0.1-py3-none-any.whl.
File metadata
- Download URL: rottl-0.0.1-py3-none-any.whl
- Upload date:
- Size: 9.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 |
1e0ab05e4744b3f7770cc6f3e7b928f69b4bf2fda75f20379a0626315aa20936
|
|
| MD5 |
e2772c148ee4b033123fb8afa7dca846
|
|
| BLAKE2b-256 |
4633873330f9ff27979323cbf751e09617b6537bfb9a9deb3202bb6cce6922f1
|
Provenance
The following attestation bundles were made for rottl-0.0.1-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.1-py3-none-any.whl -
Subject digest:
1e0ab05e4744b3f7770cc6f3e7b928f69b4bf2fda75f20379a0626315aa20936 - Sigstore transparency entry: 1257320533
- Sigstore integration time:
-
Permalink:
sharvul/rottl@f5d18c37d3d2b1f28e3b86b8fbfa3bce9c76480f -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/sharvul
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@f5d18c37d3d2b1f28e3b86b8fbfa3bce9c76480f -
Trigger Event:
release
-
Statement type: