TTL
Define a TTL field and use .from_now() to compute epoch timestamps.
Define TTL in Model
class Sessions(db.Table):
__table_name__ = "sessions"
pk = PK("session_id")
ttl = TTL("expires_at")
Usage
sessions = Sessions()
sessions.put(
session_id="sess_123",
expires_at=sessions.ttl.from_now(hours=24)
)
# Combine units
sessions.put(
session_id="sess_456",
expires_at=sessions.ttl.from_now(days=7, hours=12)
)
# All time units: days=, hours=, minutes=, seconds=
Available Time Units
| Unit | Description |
|---|---|
days | Number of days |
hours | Number of hours |
minutes | Number of minutes |
seconds | Number of seconds |
info
from_now() returns an int (Unix epoch timestamp). DynamoDB will automatically delete the item after the TTL expires (typically within 48 hours of expiration).