Bỏ qua

Expression globals

Warning

The current page still doesn't have a translation for this language.

But you can help translating it: Contributing.

These are the safe implementation-registered expression globals. They are available in script= expressions; this page lists the actual contract rather than a manually maintained subset.

Use case

Use these names directly in script= expressions. The expression-evaluation guide provides complete expression use cases; import statements and unlisted globals are not supported.

Functions

abs

Purpose: Return the absolute value of the argument.

Signature: (x, /)

add_days

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime', amount: 'int') -> 'datetime'

add_hours

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime', amount: 'int') -> 'datetime'

add_minutes

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime', amount: 'int') -> 'datetime'

add_months

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime', amount: 'int') -> 'datetime'

add_seconds

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime', amount: 'int') -> 'datetime'

add_weeks

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime', amount: 'int') -> 'datetime'

add_years

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime', amount: 'int') -> 'datetime'

all

Purpose: Return True if bool(x) is True for all values x in the iterable.

Signature: (iterable, /)

any

Purpose: Return True if bool(x) is True for any x in the iterable.

Signature: (iterable, /)

bin

Purpose: Return the binary representation of an integer.

Signature: (number, /)

date_offset

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime', duration: 'str') -> 'datetime'

divmod

Purpose: Return the tuple (x//y, x%y). Invariant: div*y + mod == x.

Signature: (x, y, /)

end_of_day

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime') -> 'datetime'

end_of_month

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime') -> 'datetime'

end_of_year

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime') -> 'datetime'

hex

Purpose: Return the hexadecimal representation of an integer.

Signature: (number, /)

isinstance

Purpose: Return whether an object is an instance of a class or of a subclass thereof.

Signature: (obj, class_or_tuple, /)

len

Purpose: Return the number of items in a container.

Signature: (obj, /)

max

Purpose: max(iterable, *[, default=obj, key=func]) -> value

min

Purpose: min(iterable, *[, default=obj, key=func]) -> value

now_utc

Purpose: Return the current UTC datetime.

Signature: () -> '_datetime.datetime'

oct

Purpose: Return the octal representation of an integer.

Signature: (number, /)

pow

Purpose: Equivalent to baseexp with 2 arguments or baseexp % mod with 3 arguments

Signature: (base, exp, mod=None)

reduce

Purpose: reduce(function, iterable[, initial]) -> value

round

Purpose: Round a number to a given precision in decimal digits.

Signature: (number, ndigits=None)

sorted

Purpose: Return a new list containing all items from the iterable in ascending order.

Signature: (iterable, /, *, key=None, reverse=False)

start_of_day

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime') -> 'datetime'

start_of_month

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime') -> 'datetime'

start_of_year

Purpose: Runtime-provided safe expression function.

Signature: (value: 'datetime') -> 'datetime'

sum

Purpose: Return the sum of a 'start' value (default: 0) plus an iterable of numbers

Signature: (iterable, /, start=0)

today

Purpose: Return the current local date (live wall-clock).

Signature: () -> '_datetime.date'

type

Purpose: Read-only type introspection; blocks the 3-argument class factory form.

Signature: Accepts or returns dynamic Python values; the concrete shape is determined at evaluation time.

type_name

Purpose: Return the runtime type name without exposing the class factory form.

Signature: Accepts or returns dynamic Python values; the concrete shape is determined at evaluation time.

Modules and namespaces

base64

Purpose: Base16, Base32, Base64 (RFC 3548), Base85 and Ascii85 data encodings

Members: b64encode, b64decode, urlsafe_b64encode, urlsafe_b64decode

bisect

Purpose: Bisection algorithms.

calendar

Purpose: Calendar printing functions

Members: month_name, day_name, isleap, monthrange

collections

Purpose: This module implements specialized container datatypes providing

Members: OrderedDict, defaultdict, Counter, namedtuple, deque

datetime

Purpose: Fast implementation of the datetime type.

Members: datetime, date, time, timedelta, timezone, UTC

decimal

Purpose: C decimal arithmetic module

Members: Decimal, ROUND_HALF_UP

dm

Purpose: DATAMIMIC utility functions

Members: clamp, coalesce, random_datetime, random_ip, randstr, short_uuid, slugify, ulid, urlencode

functools

Purpose: functools.py - Tools for working with functions and callable objects

Members: reduce, partial, lru_cache

hashlib

Purpose: hashlib module - A common interface to many hash functions.

Members: md5, sha256, sha512

heapq

Purpose: Heap queue algorithm (a.k.a. priority queue).

hmac

Purpose: HMAC (Keyed-Hashing for Message Authentication) module.

Members: new, compare_digest

ipaddress

Purpose: A fast, lightweight IPv4/IPv6 manipulation library in Python.

Members: ip_address, ip_network

itertools

Purpose: Functional tools for creating and using iterators.

Members: chain, cycle, repeat, islice, product, combinations, permutations, groupby

json

Purpose: JSON (JavaScript Object Notation) https://json.org is a subset of

Members: dumps, loads

math

Purpose: This module provides access to the mathematical functions

Members: ceil, floor, sqrt, sin, cos, tan, log, log10, log2, exp, hypot, degrees, radians, fabs, pi, e

operator

Purpose: Operator interface.

Members: itemgetter, attrgetter

random

Purpose: Random variable generators.

Members: random, randint, randrange, choice, choices, uniform, shuffle, sample

re

Purpose: Support for regular expressions (RE).

Members: compile, match, search, sub, findall, split

statistics

Purpose: Basic statistics module.

Members: mean, median, mode, stdev, variance

string

Purpose: A collection of string constants.

Members: ascii_letters, digits, ascii_lowercase, ascii_uppercase, punctuation

time

Purpose: This module provides various functions to manipulate time values.

Members: time, sleep, monotonic

urllib_parse

Purpose: Parse (absolute and relative) URLs.

Members: urlencode, urlparse, parse_qs

uuid

Purpose: UUID objects (universally unique identifiers) according to RFC 4122.

Members: uuid4, uuid1, UUID

Types and values

Decimal

Purpose: Construct a new Decimal object. 'value' can be an integer, string, tuple,

Faker

Purpose: Proxy class capable of supporting multiple locales

Fraction

Purpose: This class implements rational numbers.

PurePath

Purpose: Base class for manipulating paths without I/O.

ROUND_HALF_UP

Purpose: str(object='') -> str

ZoneInfo

Purpose: Abstract base class for time zone info objects.

bool

Purpose: bool(x) -> bool

dict

Purpose: dict() -> new empty dictionary

enumerate

Purpose: Return an enumerate object.

fake

Purpose: Proxy class capable of supporting multiple locales

filter

Purpose: filter(function or None, iterable) --> filter object

float

Purpose: Convert a string or number to a floating point number, if possible.

int

Purpose: int([x]) -> integer

list

Purpose: Built-in mutable sequence.

map

Purpose: map(func, *iterables) --> map object

range

Purpose: range(stop) -> range object

reversed

Purpose: Return a reverse iterator over the values of the given sequence.

set

Purpose: set() -> new empty set object

str

Purpose: str(object='') -> str

tuple

Purpose: Built-in immutable sequence.

zip

Purpose: zip(*iterables, strict=False) --> Yield tuples until an input is exhausted.