Skip to content

snap module

SnapPackage

Detailed information about one installed snap package, as a SnapPackageInfo.

Commands:

snap info <package> 2>/dev/null || true

Returns:

SnapPackageInfo | None

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/snap/snap_snap_package.py.

SnapPackageInfo

Attributes:

Name Type Description
name

The snap's name (the name: field), e.g. "lxd".

publisher

The publisher as snap prints it, verification glyph included ("Canonical✓", "Canonical**"); "" when the package reports none.

snap_id

The snap's store id (the snap-id: field); "" when snap prints none.

channel

The tracked channel read from the tracking: row as <track>/<risk> ("4.0/stable", "latest/stable"); the branch (a trailing /ubuntu-20.04) is dropped. "" when snap prints none.

version

The installed version read from the installed: row ("4.0.9-8e2046b"); "" when snap prints none.

SnapPackages

The names of the installed snap packages.

Commands:

snap list 2>/dev/null || true

Returns:

list[str]

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/snap/snap_snap_packages.py.

package async

package(
    ctx: OpContext,
    packages: str
    | list[str]
    | tuple[str, ...]
    | None = None,
    channel: str = "latest/stable",
    classic: bool = False,
    present: bool = True,
    **kwargs: Any,
) -> AsyncGenerator[Command]

Install, remove or re-channel snap packages.

Parameters:

Name Type Description Default
ctx OpContext

Execution context for the operation.

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

Snaps to ensure. Prefer tuples when building requests via op(), since OperationRequest kwargs must stay hashable. Defaults to None.

None
channel str

The tracking channel to install on or switch an installed snap to. Defaults to "latest/stable".

'latest/stable'
classic bool

Whether to install with --classic confinement (access to system resources like traditional packages). Applies to the install direction only. Defaults to False.

False
present bool

Whether the snaps should be installed. Defaults to True.

True
**kwargs Any

Additional keyword arguments.

{}

Yields:

Name Type Description
Command AsyncGenerator[Command]

Generated snap package commands.

Raises:

HostConnectionError

Examples:

Examples can be found in examples/modules/snap/snap_package.py.