Skip to content

apk

ApkAutoremovablePackages

Orphaned packages that purge would remove.

Commands:

apk add --purge --simulate 2>/dev/null

Returns:

list[ApkPackageVersion]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_apk_autoremovable.py.

ApkExplicitPackages

The explicitly installed apk packages.

Commands:

cat -- /etc/apk/world 2>/dev/null || true

Returns:

list[ApkPackageVersion]

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_apk_explicit_packages.py.

ApkHeldPackages

The version-pinned apk packages.

Commands:

cat -- /etc/apk/world 2>/dev/null || true

Returns:

list[ApkPackageVersion]

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_hold.py.

ApkInstalledPackages

The installed apk packages.

Commands:

apk list --installed

Returns:

list[ApkPackageVersion]

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_apk_packages.py.

ApkPackage

Detailed information about a specific apk package, as an ApkPackageInfo.

Commands:

apk info -a <package> 2>/dev/null || true

Returns:

ApkPackageInfo | None

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_apk_package.py.

ApkPackageInfo

Attributes:

Name Type Description
name

The package name, e.g. "curl".

version

The version-and-release apk reports, e.g. "8.14.0-r0" -- the same shape ApkInstalledPackages reports in its entries' version field.

description

The one-line package description (apk's description).

url

The upstream homepage (apk's webpage field), "" when the package prints none.

license

The SPDX license identifier (apk's license), "" when apk prints none.

size

The installed size in bytes (apk's installed size), 0 when apk prints none.

depends

The package's dependency strings (apk's depends on rows), in apk's printed order.

provides

The virtual names the package provides (apk's provides rows), in apk's printed order.

ApkPackageVersion

Attributes:

Name Type Description
name

The bare package name, e.g. "curl" -- the @tag a world line may carry is not part of it.

version

The version-and-release ("8.14.0-r0") for ApkInstalledPackages and ApkAutoremovablePackages; the world constraint verbatim, operator included ("=8.14.0-r0", ">~9.7_p1-r4"), for the world-derived ApkExplicitPackages and ApkHeldPackages, "" when a world line carries no version bound.

ApkRepositories

The configured apk repositories, as a list of ApkRepository dicts.

Commands:

cat -- /etc/apk/repositories 2>/dev/null || true

Returns:

list[ApkRepository]

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_apk_repositories.py.

ApkRepositoriesFile

The current content of the apk repositories file, or None when it is absent.

Commands:

test -e <path> && { printf '#reemote-apkrepositories\n'; cat -- <path>; }

Returns:

str | None

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_repository.py.

ApkRepository

Attributes:

Name Type Description
url

The repository URL, e.g. "https://dl-cdn.alpinelinux.org/alpine/v3.19/main".

tag

The repository tag selecting the repository -- the @-prefixed word apk reads before the URL ("testing" for a @testing <url> line, kept without the leading @), used by apk add --repository and /etc/apk/world tags -- or the empty string when the line carries none.

autoremove async

autoremove(
    ctx: OpContext, **kwargs: Any
) -> AsyncGenerator[Command]

Remove orphan packages nothing reaches any more.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

The apk purge command, when orphans are purgable.

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_autoremove.py.

hold async

hold(
    ctx: OpContext,
    packages: str | list[str] | tuple[str, ...],
    present: bool = True,
    version: str | None = None,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Hold packages back from upgrades, or release held ones (apk pins).

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
packages str | list[str] | tuple[str, ...]

Package names to hold or unhold; a single string or a list/tuple. Prefer tuples when building requests via op(), since OperationRequest kwargs must stay hashable.

required
present bool

Whether the hold should be present (True, pin the package) or removed (False, release the pin). Defaults to True.

True
version str | None

The optional version constraint to pin to -- a bare 1.2.3-r0 (normalized to =1.2.3-r0) or an operator-led ~1.2/<2.0. When omitted with present=True, each package is pinned to its currently installed version (ApkInstalledPackages' newest); ignored on the present=False direction. Defaults to None.

None
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated apk hold commands.

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_hold.py.

packages async

packages(
    ctx: OpContext,
    packages: str
    | list[str]
    | tuple[str, ...]
    | None = None,
    present: bool = True,
    latest: bool = False,
    no_cache: bool = False,
    no_scripts: bool = False,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Add/remove/update apk packages.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
packages str | list[str] | tuple[str, ...] | None

Packages to ensure. Prefer tuples when building requests via op(), since OperationRequest kwargs must stay hashable. Versions can be pinned as <pkg>=<version>. Defaults to None.

None
present bool

Whether the packages should be installed. Defaults to True.

True
latest bool

Whether to upgrade installed packages without a pinned version. Defaults to False.

False
no_cache bool

Add --no-cache to the install/upgrade command, bypassing the package cache entirely (neither read from nor write to /var/cache/apk). Defaults to False.

False
no_scripts bool

Add --no-scripts to the install/upgrade command, skipping post-install triggers and scriptlets. Defaults to False.

False
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated apk package commands.

Raises:

CommandNotFoundError, HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_apk_packages.py.

repository async

repository(
    ctx: OpContext,
    src: str,
    present: bool = True,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Add/remove an apk repository line in /etc/apk/repositories.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
src str

Repository line -- a bare URL (https://dl-cdn.alpinelinux.org/alpine/v3.19/community) or an @tag URL line (@testing https://.../edge/testing).

required
present bool

Whether the repository should exist in the file. Defaults to True.

True
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated apk repository line commands.

Raises:

CommandNotFoundError, HostConnectionError, ValueError

Examples:

Examples can be found in examples/modules/apk/apk_repository.py.

virtual async

virtual(
    ctx: OpContext,
    tag: str,
    packages: str
    | list[str]
    | tuple[str, ...]
    | None = None,
    present: bool = True,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Manage an apk virtual package group..

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

required
tag str

The virtual package name apk records in /etc/apk/world -- the group's identity, created with apk add -t <tag> and removed with apk del <tag>.

required
packages str | list[str] | tuple[str, ...] | None

The member packages the virtual group depends on; a single string, a list/tuple, or None. Prefer tuples when building requests via op(), since OperationRequest kwargs must stay hashable. Versions can be pinned as <pkg>=<version>. Defaults to None.

None
present bool

Whether the virtual group should exist. Defaults to True.

True
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated apk virtual package commands.

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/apk/apk_virtual.py.