Craft Providers

raw JSON →
3.6.0 verified Fri May 01 auth: no python

Craft-providers is a Python library for managing and provisioning build environments using LXD, Multipass, or Docker. It is part of the Snapcraft ecosystem, currently at version 3.6.0, with a release cadence of approximately monthly.

pip install craft-providers
error ImportError: cannot import name 'LXDInstance' from 'craft_providers'
cause The LXDInstance class is not directly under craft_providers; it is in craft_providers.lxd.
fix
Use: from craft_providers.lxd import LXDInstance
error craft_providers.errors.ProviderError: Failed to launch LXD container
cause LXD is not installed, not running, or the user lacks permissions.
fix
Ensure LXD is installed, the daemon is running, and user is in the lxd group.
breaking In craft-providers 2.0, the API was rewritten. The old craft_providers.bases.Base class hierarchy was replaced with craft_providers.bases.BuilddBase and other concrete base classes.
fix Update code to use new base classes; refer to migration guide.
deprecated craft_providers.lxd.LXDInstance.launch() is deprecated in favor of .create() since version 3.0.
fix Use .create() instead of .launch().
gotcha LXD must be installed and the user must have permission to interact with the LXD socket (usually via lxd group).
fix Install LXD and add user to lxd group, then log out and back in.

Creates an LXD container with Ubuntu Jammy, runs a command, then deletes it.

from craft_providers.lxd import LXDInstance
from craft_providers import bases

instance = LXDInstance(name="my-instance")
instance.create(
    base=bases.BuilddBase(series="jammy")
)
with instance as ctx:
    print(ctx.execute_run(["lsb_release", "-a"]))
instance.delete()