dlt.extract.incremental.context
Time interval context for external schedulers.
TAnyTimeInterval
A (start, end) interval as either a TTimeInterval or a plain datetime tuple.
TimeIntervalContext Objects
@configspec
class TimeIntervalContext(ContainerInjectableContext)
Active time interval from an external scheduler.
allow_external_schedulers
When True, enables allow_external_schedulers on incrementals that left it unset.
interval
@property
def interval() -> Optional[TTimeInterval]
Resolved interval as (start, end) datetime tuple, or None.
timezone
@property
def timezone() -> tzinfo
Timezone both bounds are in, which is the context timezone when there is no interval.
get_interval_context
def get_interval_context() -> Optional[TimeIntervalContext]
Get the active interval context from Container, or None.
_IntervalAccessor Objects
class _IntervalAccessor()
Callable accessor for the active interval. Exposed as dlt.current.interval.
update
def update(*,
start: Optional[TAnyDateTime] = None,
end: Optional[TAnyDateTime] = None) -> None
Override start and/or end, preserving the other bound.
Each new bound is taken into the interval's timezone: naive values (including plain dates and ISO strings without an offset) are read as wall clock there, aware values are converted. Both ends of the interval keep a single timezone.
Arguments:
startOptional[TAnyDateTime] - New start of the interval.endOptional[TAnyDateTime] - New end of the interval.
Raises:
IntervalNotAvailable- If no interval is active.
timezone
@property
def timezone() -> Optional[tzinfo]
Timezone of the active interval, or None when no interval is active.
is_empty
@property
def is_empty() -> bool
True when no interval is active or it has zero length (manual and event runs).
apply_lag
def apply_lag(trigger: str,
count: int = 1,
lag_end: bool = False) -> "_IntervalAccessor"
Lags the active interval start (or end) by count trigger ticks into the past.
The bound snaps to the trigger tick grid: count=0 floors it to the
latest tick, negative count moves it into the future.
Arguments:
triggerstr - Aschedule:orevery:trigger, or a bare cron expression.countint - Number of ticks (orevery:periods) to lag, negative moves into the future. Defaults to 1.lag_endbool - WhenTrue, adjusts the end instead of the start.
Returns:
The accessor itself, so calls can be chained.
Raises:
ValueError- If the adjusted interval is empty or negative.IntervalNotAvailable- If no interval is active.
apply_full_days
def apply_full_days() -> "_IntervalAccessor"
Widens the active interval to full days: start floored to midnight, end extended to the next midnight, each in its own timezone.
Returns:
The accessor itself, so calls can be chained.
Raises:
IntervalNotAvailable- If no interval is active.
timezone
def timezone() -> tzinfo
The context timezone. UTC unless the run declares one through TimezoneContext or
DLT_INTERVAL_TIMEZONE.
Unlike dlt.current.interval.timezone, which describes the zone the interval bounds
happen to carry, this is the zone dlt actually writes values in and is never None.