Skip to content

misc (7)

cwd

cwd()

Return a new path pointing to the current working directory.

Example

Jinja call:

{{ cwd() }}
Result: /home/runner/work/jinjarope/jinjarope

DocStrings
Source code in pathlib/_abc.py
@classmethod
def cwd(cls):
    """Return a new path pointing to the current working directory."""
    # We call 'absolute()' rather than using 'os.getcwd()' directly to
    # enable users to replace the implementation of 'absolute()' in a
    # subclass and benefit from the new behaviour here. This works because
    # os.path.abspath('.') == os.getcwd().
    return cls('').absolute()

now

now(tz: datetime.tzinfo | None = None) -> datetime.datetime

Get current Datetime.

Example

Jinja call:

{{ now() }}
Result: 2026-11-23 07:46:10.919871

DocStrings

Parameters:

Name Type Description Default
tz tzinfo | None

timezone for retuned datetime

None
Source code in src/jinjarope/envglobals.py
def now(tz: dt.tzinfo | None = None) -> dt.datetime:
    """Get current Datetime.

    Args:
        tz: timezone for retuned datetime
    """
    return dt.datetime.now(tz)

online

online() -> bool

Return true if machine is connected to internet.

Example

Jinja call:

{{ online() }}
Result: True

DocStrings
Source code in src/jinjarope/envglobals.py
def has_internet() -> bool:
    """Return true if machine is connected to internet.

    Checks connection with a HEAD request to the Google DNS server.
    """
    import http.client as httplib

    conn = httplib.HTTPSConnection("8.8.8.8", timeout=2)
    try:
        conn.request("HEAD", "/")
        return True  # noqa: TRY300
    except Exception:  # noqa: BLE001
        return False
    finally:
        conn.close()

randint

randint(a, b)

Return random integer in range [a, b], including both end points.

Example

Jinja call:

{{ randint(1, 10) }}
Result: 6

DocStrings
Source code in python3.13/random.py
def randint(self, a, b):
    """Return random integer in range [a, b], including both end points.
    """

    return self.randrange(a, b+1)

randrange

randrange(start, stop=None, step=1)

Choose a random item from range(stop) or range(start, stop[, step]).

Example

Jinja call:

{{ randrange(1, 10) }}
Result: 9

DocStrings
Source code in python3.13/random.py
def randrange(self, start, stop=None, step=_ONE):
    """Choose a random item from range(stop) or range(start, stop[, step]).

    Roughly equivalent to ``choice(range(start, stop, step))`` but
    supports arbitrarily large ranges and is optimized for common cases.

    """

    # This code is a bit messy to make it fast for the
    # common case while still doing adequate error checking.
    istart = _index(start)
    if stop is None:
        # We don't check for "step != 1" because it hasn't been
        # type checked and converted to an integer yet.
        if step is not _ONE:
            raise TypeError("Missing a non-None stop argument")
        if istart > 0:
            return self._randbelow(istart)
        raise ValueError("empty range for randrange()")

    # Stop argument supplied.
    istop = _index(stop)
    width = istop - istart
    istep = _index(step)
    # Fast path.
    if istep == 1:
        if width > 0:
            return istart + self._randbelow(width)
        raise ValueError(f"empty range in randrange({start}, {stop})")

    # Non-unit step argument supplied.
    if istep > 0:
        n = (width + istep - 1) // istep
    elif istep < 0:
        n = (width + istep + 1) // istep
    else:
        raise ValueError("zero step for randrange()")
    if n <= 0:
        raise ValueError(f"empty range in randrange({start}, {stop}, {step})")
    return istart + istep * self._randbelow(n)

uniform

uniform(a, b)

Get a random number in the range [a, b) or [a, b] depending on rounding.

Example

Jinja call:

{{ uniform(2, 5) }}
Result: 3.2664666035119794

DocStrings
Source code in python3.13/random.py
def uniform(self, a, b):
    """Get a random number in the range [a, b) or [a, b] depending on rounding.

    The mean (expected value) and variance of the random variable are:

        E[X] = (a + b) / 2
        Var[X] = (b - a) ** 2 / 12

    """
    return a + (b - a) * self.random()

utcnow

utcnow() -> datetime.datetime

Get UTC datetime.

Example

Jinja call:

{{ utcnow() }}
Result: 2026-11-23 07:46:10.959193+00:00

DocStrings
Source code in src/jinjarope/envglobals.py
def utcnow() -> dt.datetime:
    """Get UTC datetime."""
    return dt.datetime.now(dt.UTC)