pylxd is a Python library for interacting with the LXD REST API, providing a client for managing containers, virtual machines, images, networks, storage, and profiles on LXD instances. Current version is 2.4.1, requiring Python >=3.10. The library is maintained by Canonical and follows the LXD API changes. Releases happen irregularly, driven by LXD updates and bug fixes.
pip install pylxdVerified import paths — ran on the pinned version, not inferred.
Connect to LXD, list instances, create and start a container.
Use client.instances instead of client.containers or client.virtual_machines. The Instance model now handles both types; set instance type in create config via 'type' key (e.g., 'container' or 'virtual-machine').
Use wait=True or call client.operations.wait(operation) after operations like storage pool creation or profile update. Check the returned Operation object for status.
Upgrade to pylxd >=2.3.4, which restricts requests version. If you must use newer requests, consider using an HTTPClient adapter or switch to TCP endpoint.
client = Client(endpoint='https://...', cert=('cert.pem', 'key.pem')); client.authenticate('mypassword')config = {'name': 'vm1', 'type': 'virtual-machine', 'source': {'type': 'image', 'alias': 'ubuntu/22.04'}}Ensure the client certificate is added to the LXD trust store: `lxc config trust add client.crt` on the LXD host.
Add user to the lxd group: `sudo usermod -aG lxd $USER` then log out and back in.
Verify the resource name/alias exists. For images, use `lxc image list` to check available aliases.
No dependency data recorded yet.