Nag

A named nag created by Sponsorkit.nag().

On this page

Class in sponsorkit.nag.

from sponsorkit import Nag

Also importable from sponsorkit.nag.

class Nag:
    ...

A named nag created by sponsorkit.Sponsorkit.nag().

The run counter goes up by one per process per id, on the first due() call. due() returns predicate(result) and (runs >= every or time since last shown >= or_every). shown() resets the counter and records the time.

due() is always False when SPONSORKIT_DISABLE is set, and (unless force=True) when SPONSORKIT_NO_NAG or CI is set or the session is not interactive (stdout/stderr not a TTY, or the interactive=False option). It never signs in.

Don't construct a Nag yourself: call sponsorkit.Sponsorkit.nag(), which validates the arguments and binds the nag to the client's storage.

Attributes#

id#

id: str

The name of the counter, as passed to Sponsorkit.nag().

every#

every: int

Due once this many runs have counted since the nag was last shown.

or_every#

or_every: timedelta | None

Also due once this much time passed since it was last shown, or None.

Methods#

due()#

def due(self, predicate: Predicate | None = None, *, force: bool = False) -> bool

Whether to show the nag now. predicate receives the current ContributionResult.

shown()#

def shown(self) -> None

Record that the nag was shown: resets the run counter and sets lastShown to now.

adue()#

async def adue(self, predicate: Predicate | None = None, *, force: bool = False) -> bool

Async variant of due() (runs in a worker thread).

ashown()#

async def ashown(self) -> None

Async variant of shown().