anki.utils#

Attributes#

Functions#

int_time(→ int)

The time in integer seconds. Pass scale=1000 to get milliseconds.

strip_html(→ str)

strip_html_media(→ str)

Strip HTML but keep media filenames

html_to_text_line(→ str)

ids2str(→ str)

Given a list of integers, return a string '(int1,int2,...)'.

timestamp_id(→ int)

Return a non-conflicting timestamp for table.

max_id(→ int)

Return the first safe ID to use.

base62(→ str)

base91(→ str)

guid64(→ str)

Return a base91-encoded 64bit random number.

join_fields(→ str)

split_fields(→ list[str])

checksum(→ str)

field_checksum(→ int)

tmpdir(→ str)

A reusable temp folder which we clean out on each program invocation.

tmpfile(→ str)

namedtmp(→ str)

Return tmpdir+name. Deletes any existing file.

no_bundled_libs(→ collections.abc.Iterator[None])

call(→ int)

Execute a command. If WAIT, return exit code.

invalid_filename(→ invalid_filename.str | None)

plat_desc(→ str)

version_with_build(→ str)

int_version(→ int)

Anki's version as an integer in the form YYMMPP, e.g. 230900.

int_version_to_str(→ str)

Module Contents#

anki.utils.to_json_bytes: collections.abc.Callable[[Any], bytes]#
anki.utils.int_time(scale: int = 1) int#

The time in integer seconds. Pass scale=1000 to get milliseconds.

anki.utils.strip_html(txt: str) str#
anki.utils.strip_html_media(txt: str) str#

Strip HTML but keep media filenames

anki.utils.html_to_text_line(txt: str) str#
anki.utils.ids2str(ids: collections.abc.Iterable[int | str]) str#

Given a list of integers, return a string ‘(int1,int2,…)’.

anki.utils.timestamp_id(db: anki.dbproxy.DBProxy, table: str) int#

Return a non-conflicting timestamp for table.

anki.utils.max_id(db: anki.dbproxy.DBProxy) int#

Return the first safe ID to use.

anki.utils.base62(num: int, extra: str = '') str#
anki.utils.base91(num: int) str#
anki.utils.guid64() str#

Return a base91-encoded 64bit random number.

anki.utils.join_fields(list: join_fields.list[str]) str#
anki.utils.split_fields(string: str) list[str]#
anki.utils.checksum(data: bytes | str) str#
anki.utils.field_checksum(data: str) int#
anki.utils.tmpdir() str#

A reusable temp folder which we clean out on each program invocation.

anki.utils.tmpfile(prefix: str = '', suffix: str = '') str#
anki.utils.namedtmp(name: str, remove: bool = True) str#

Return tmpdir+name. Deletes any existing file.

anki.utils.no_bundled_libs() collections.abc.Iterator[None]#
anki.utils.call(argv: list[str], wait: bool = True, **kwargs: Any) int#

Execute a command. If WAIT, return exit code.

anki.utils.is_mac = False#
anki.utils.is_win = False#
anki.utils.is_lin = True#
anki.utils.is_gnome#
anki.utils.dev_mode#
anki.utils.hmr_mode#
anki.utils.INVALID_FILENAME_CHARS = ':*?"<>|'#
anki.utils.invalid_filename(str: invalid_filename.str, dirsep: bool = True) invalid_filename.str | None#
anki.utils.plat_desc() str#
anki.utils.version_with_build() str#
anki.utils.int_version() int#

Anki’s version as an integer in the form YYMMPP, e.g. 230900. (year, month, patch). In 2.1.x releases, this was just the last number.

anki.utils.int_version_to_str(ver: int) str#
anki.utils.point_version#
anki.utils.pointVersion#