Skip to main content

module  pixeltable.functions.string

Pixeltable UDFs for StringType. It closely follows the Pandas pandas.Series.str API. Example:
import pixeltable as pxt

t = pxt.get_table(...)
t.select(t.str_col.capitalize()).collect()

udf  capitalize()

Signature
capitalize(self: pxt.String) -> pxt.String
Return string with its first character capitalized and the rest lowercased. Equivalent to str.capitalize().

udf  casefold()

Signature
casefold(self: pxt.String) -> pxt.String
Return a casefolded copy of string. Equivalent to str.casefold().

udf  center()

Signature
center(
    self: pxt.String,
    width: pxt.Int,
    fillchar: pxt.String = ' '
) -> pxt.String
Return a centered string of length width. Equivalent to str.center(). Parameters:
  • width (pxt.Int): Total width of the resulting string.
  • fillchar (pxt.String): Character used for padding.

udf  contains()

Signature
contains(
    self: pxt.String,
    substr: pxt.String,
    case: pxt.Bool = True
) -> pxt.Bool
Test if string contains a substring. Parameters:
  • substr (pxt.String): string literal or regular expression
  • case (pxt.Bool): if False, ignore case

udf  contains_re()

Signature
contains_re(
    self: pxt.String,
    pattern: pxt.String,
    flags: pxt.Int = 0
) -> pxt.Bool
Test if string contains a regular expression pattern. Parameters:
  • pattern (pxt.String): regular expression pattern
  • flags (pxt.Int): flags for the re module

udf  count()

Signature
count(
    self: pxt.String,
    pattern: pxt.String,
    flags: pxt.Int = 0
) -> pxt.Int
Count occurrences of pattern or regex. Parameters:
  • pattern (pxt.String): string literal or regular expression
  • flags (pxt.Int): flags for the re module

udf  endswith()

Signature
endswith(self: pxt.String, substr: pxt.String) -> pxt.Bool
Return True if the string ends with the specified suffix, otherwise return False. Equivalent to str.endswith(). Parameters:
  • substr (pxt.String): string literal

udf  fill()

Signature
fill(self: pxt.String, width: pxt.Int) -> pxt.String
Wraps the single paragraph in string, and returns a single string containing the wrapped paragraph. Equivalent to textwrap.fill(). Parameters:
  • width (pxt.Int): Maximum line width.
  • kwargs (Any): Additional keyword arguments to pass to textwrap.fill().

udf  find()

Signature
find(
    self: pxt.String,
    substr: pxt.String,
    start: pxt.Int = 0,
    end: pxt.Int | None = None
) -> pxt.Int
Return the lowest index in string where substr is found within the slice s[start:end]. Equivalent to str.find(). Parameters:
  • substr (pxt.String): substring to search for
  • start (pxt.Int): slice start
  • end (pxt.Int | None): slice end

udf  findall()

Signature
findall(
    self: pxt.String,
    pattern: pxt.String,
    flags: pxt.Int = 0
) -> pxt.Json
Find all occurrences of a regular expression pattern in string. Equivalent to re.findall(). Parameters:
  • pattern (pxt.String): regular expression pattern
  • flags (pxt.Int): flags for the re module

udf  format()

Signature
format(self: pxt.String) -> pxt.String
Perform string formatting. Equivalent to str.format().

udf  fullmatch()

Signature
fullmatch(
    self: pxt.String,
    pattern: pxt.String,
    case: pxt.Bool = True,
    flags: pxt.Int = 0
) -> pxt.Bool
Determine if string fully matches a regular expression. Equivalent to re.fullmatch(). Parameters:
  • pattern (pxt.String): regular expression pattern
  • case (pxt.Bool): if False, ignore case
  • flags (pxt.Int): flags for the re module

udf  index()

Signature
index(
    self: pxt.String,
    substr: pxt.String,
    start: pxt.Int = 0,
    end: pxt.Int | None = None
) -> pxt.Int
Return the lowest index in string where substr is found within the slice [start:end]. Raises ValueError if substr is not found. Equivalent to str.index(). Parameters:
  • substr (pxt.String): substring to search for
  • start (pxt.Int): slice start
  • end (pxt.Int | None): slice end

udf  isalnum()

Signature
isalnum(self: pxt.String) -> pxt.Bool
Return True if all characters in the string are alphanumeric and there is at least one character, False otherwise. Equivalent to [str.isalnum()](https://docs.python.org/3/library/stdtypes.html#str.isalnum

udf  isalpha()

Signature
isalpha(self: pxt.String) -> pxt.Bool
Return True if all characters in the string are alphabetic and there is at least one character, False otherwise. Equivalent to str.isalpha().

udf  isascii()

Signature
isascii(self: pxt.String) -> pxt.Bool
Return True if the string is empty or all characters in the string are ASCII, False otherwise. Equivalent to str.isascii().

udf  isdecimal()

Signature
isdecimal(self: pxt.String) -> pxt.Bool
Return True if all characters in the string are decimal characters and there is at least one character, False otherwise. Equivalent to str.isdecimal().

udf  isdigit()

Signature
isdigit(self: pxt.String) -> pxt.Bool
Return True if all characters in the string are digits and there is at least one character, False otherwise. Equivalent to str.isdigit().

udf  isidentifier()

Signature
isidentifier(self: pxt.String) -> pxt.Bool
Return True if the string is a valid identifier according to the language definition, False otherwise. Equivalent to str.isidentifier()

udf  islower()

Signature
islower(self: pxt.String) -> pxt.Bool
Return True if all cased characters in the string are lowercase and there is at least one cased character, False otherwise. Equivalent to str.islower()

udf  isnumeric()

Signature
isnumeric(self: pxt.String) -> pxt.Bool
Return True if all characters in the string are numeric characters, False otherwise. Equivalent to str.isnumeric()

udf  isspace()

Signature
isspace(self: pxt.String) -> pxt.Bool
Return True if there are only whitespace characters in the string and there is at least one character, False otherwise. Equivalent to str.isspace()

udf  istitle()

Signature
istitle(self: pxt.String) -> pxt.Bool
Return True if the string is a titlecased string and there is at least one character, False otherwise. Equivalent to str.istitle()

udf  isupper()

Signature
isupper(self: pxt.String) -> pxt.Bool
Return True if all cased characters in the string are uppercase and there is at least one cased character, False otherwise. Equivalent to str.isupper()

udf  join()

Signature
join(sep: pxt.String, elements: pxt.Json) -> pxt.String
Return a string which is the concatenation of the strings in elements. Equivalent to str.join()

udf  len()

Signature
len(self: pxt.String) -> pxt.Int
Return the number of characters in the string. Equivalent to len(str)

udf  ljust()

Signature
ljust(
    self: pxt.String,
    width: pxt.Int,
    fillchar: pxt.String = ' '
) -> pxt.String
Return the string left-justified in a string of length width. Equivalent to str.ljust() Parameters:
  • width (pxt.Int): Minimum width of resulting string; additional characters will be filled with character defined in fillchar.
  • fillchar (pxt.String): Additional character for filling.

udf  lower()

Signature
lower(self: pxt.String) -> pxt.String
Return a copy of the string with all the cased characters converted to lowercase. Equivalent to str.lower()

udf  lstrip()

Signature
lstrip(
    self: pxt.String,
    chars: pxt.String | None = None
) -> pxt.String
Return a copy of the string with leading characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, whitespace characters are removed. Equivalent to str.lstrip() Parameters:
  • chars (pxt.String | None): The set of characters to be removed.

udf  match()

Signature
match(
    self: pxt.String,
    pattern: pxt.String,
    case: pxt.Bool = True,
    flags: pxt.Int = 0
) -> pxt.Bool
Determine if string starts with a match of a regular expression Parameters:
  • pattern (pxt.String): regular expression pattern
  • case (pxt.Bool): if False, ignore case
  • flags (pxt.Int): flags for the re module

udf  normalize()

Signature
normalize(self: pxt.String, form: pxt.String) -> pxt.String
Return the Unicode normal form. Equivalent to unicodedata.normalize() Parameters:
  • form (pxt.String): Unicode normal form ('NFC', 'NFKC', 'NFD', 'NFKD')

udf  pad()

Signature
pad(
    self: pxt.String,
    width: pxt.Int,
    side: pxt.String = 'left',
    fillchar: pxt.String = ' '
) -> pxt.String
Pad string up to width Parameters:
  • width (pxt.Int): Minimum width of resulting string; additional characters will be filled with character defined in fillchar.
  • side (pxt.String): Side from which to fill resulting string ('left', 'right', 'both')
  • fillchar (pxt.String): Additional character for filling

udf  partition()

Signature
partition(self: pxt.String, sep: pxt.String = ' ') -> pxt.Json
Splits string at the first occurrence of sep, and returns 3 elements containing the part before the separator, the separator itself, and the part after the separator. If the separator is not found, return 3 elements containing string itself, followed by two empty strings.

udf  removeprefix()

Signature
removeprefix(self: pxt.String, prefix: pxt.String) -> pxt.String
Remove prefix. If the prefix is not present, returns string.

udf  removesuffix()

Signature
removesuffix(self: pxt.String, suffix: pxt.String) -> pxt.String
Remove suffix. If the suffix is not present, returns string.

udf  repeat()

Signature
repeat(self: pxt.String, n: pxt.Int) -> pxt.String
Repeat string n times.

udf  replace()

Signature
replace(
    self: pxt.String,
    substr: pxt.String,
    repl: pxt.String,
    n: pxt.Int | None = None
) -> pxt.String
Replace occurrences of substr with repl. Equivalent to str.replace(). Parameters:
  • substr (pxt.String): string literal
  • repl (pxt.String): replacement string
  • n (pxt.Int | None): number of replacements to make (if None, replace all occurrences)

udf  replace_re()

Signature
replace_re(
    self: pxt.String,
    pattern: pxt.String,
    repl: pxt.String,
    n: pxt.Int | None = None,
    flags: pxt.Int = 0
) -> pxt.String
Replace occurrences of a regular expression pattern with repl. Equivalent to re.sub(). Parameters:
  • pattern (pxt.String): regular expression pattern
  • repl (pxt.String): replacement string
  • n (pxt.Int | None): number of replacements to make (if None, replace all occurrences)
  • flags (pxt.Int): flags for the re module

udf  reverse()

Signature
reverse(self: pxt.String) -> pxt.String
Return a reversed copy of the string. Equivalent to str[::-1].

udf  rfind()

Signature
rfind(
    self: pxt.String,
    substr: pxt.String,
    start: pxt.Int | None = 0,
    end: pxt.Int | None = None
) -> pxt.Int
Return the highest index where substr is found, such that substr is contained within [start:end]. Equivalent to str.rfind(). Parameters:
  • substr (pxt.String): substring to search for
  • start (pxt.Int | None): slice start
  • end (pxt.Int | None): slice end

udf  rindex()

Signature
rindex(
    self: pxt.String,
    substr: pxt.String,
    start: pxt.Int | None = 0,
    end: pxt.Int | None = None
) -> pxt.Int
Return the highest index where substr is found, such that substr is contained within [start:end]. Raises ValueError if substr is not found. Equivalent to str.rindex().

udf  rjust()

Signature
rjust(
    self: pxt.String,
    width: pxt.Int,
    fillchar: pxt.String = ' '
) -> pxt.String
Return the string right-justified in a string of length width. Equivalent to str.rjust(). Parameters:
  • width (pxt.Int): Minimum width of resulting string.
  • fillchar (pxt.String): Additional character for filling.

udf  rpartition()

Signature
rpartition(self: pxt.String, sep: pxt.String = ' ') -> pxt.Json
This method splits string at the last occurrence of sep, and returns a list containing the part before the separator, the separator itself, and the part after the separator.

udf  rstrip()

Signature
rstrip(
    self: pxt.String,
    chars: pxt.String | None = None
) -> pxt.String
Return a copy of string with trailing characters removed. Equivalent to str.rstrip(). Parameters:
  • chars (pxt.String | None): The set of characters to be removed. If omitted or None, whitespace characters are removed.

udf  slice()

Signature
slice(
    self: pxt.String,
    start: pxt.Int | None = None,
    stop: pxt.Int | None = None,
    step: pxt.Int | None = None
) -> pxt.String
Return a slice. Parameters:
  • start (pxt.Int | None): slice start
  • stop (pxt.Int | None): slice end
  • step (pxt.Int | None): slice step

udf  slice_replace()

Signature
slice_replace(
    self: pxt.String,
    start: pxt.Int | None = None,
    stop: pxt.Int | None = None,
    repl: pxt.String | None = None
) -> pxt.String
Replace a positional slice with another value. Parameters:
  • start (pxt.Int | None): slice start
  • stop (pxt.Int | None): slice end
  • repl (pxt.String | None): replacement value

udf  startswith()

Signature
startswith(self: pxt.String, substr: pxt.String) -> pxt.Int
Return True if string starts with substr, otherwise return False. Equivalent to str.startswith(). Parameters:
  • substr (pxt.String): string literal

udf  strip()

Signature
strip(
    self: pxt.String,
    chars: pxt.String | None = None
) -> pxt.String
Return a copy of string with leading and trailing characters removed. Equivalent to str.strip(). Parameters:
  • chars (pxt.String | None): The set of characters to be removed. If omitted or None, whitespace characters are removed.

udf  swapcase()

Signature
swapcase(self: pxt.String) -> pxt.String
Return a copy of string with uppercase characters converted to lowercase and vice versa. Equivalent to str.swapcase().

udf  title()

Signature
title(self: pxt.String) -> pxt.String
Return a titlecased version of string, i.e. words start with uppercase characters, all remaining cased characters are lowercase. Equivalent to str.title().

udf  upper()

Signature
upper(self: pxt.String) -> pxt.String
Return a copy of string converted to uppercase. Equivalent to str.upper().

udf  wrap()

Signature
wrap(self: pxt.String, width: pxt.Int) -> pxt.Json
Wraps the single paragraph in string so every line is at most width characters long. Returns a list of output lines, without final newlines. Equivalent to textwrap.fill(). Parameters:
  • width (pxt.Int): Maximum line width.
  • kwargs (Any): Additional keyword arguments to pass to textwrap.fill().