{"id":24353,"library":"pylxd","title":"pylxd","description":"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.","status":"active","version":"2.4.1","language":"python","source_language":"en","source_url":"https://github.com/canonical/pylxd","tags":["lxd","containers","virtual-machines","canonical","rest-api"],"install":[{"cmd":"pip install pylxd","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"Client is the main entry point; pylxd module itself does not expose Client directly.","wrong":"import pylxd","symbol":"Client","correct":"from pylxd import Client"},{"note":"Client is exposed at the package level; importing from pylxd.client is an internal detail and may break.","wrong":"from pylxd.client import Client","symbol":"Client","correct":"from pylxd import Client"}],"quickstart":{"code":"from pylxd import Client\n\n# Connect to local LXD (via Unix socket)\nclient = Client()\n\n# Or connect to remote LXD with password\n# client = Client(endpoint='https://10.0.0.1:8443', cert=('/path/to/client.crt', '/path/to/client.key'), verify=True)\n# client.authenticate('password')\n\n# List instances\ninstances = client.instances.all()\nfor instance in instances:\n    print(instance.name, instance.status)\n\n# Create a container\nconfig = {'name': 'my-container', 'source': {'type': 'image', 'alias': 'ubuntu/22.04'}}\ncontainer = client.instances.create(config, wait=True)\nprint(f\"Created {container.name}\")\n\n# Start container\ncontainer.start(wait=True)\nprint(f\"{container.name} is {container.status}\")","lang":"python","description":"Connect to LXD, list instances, create and start a container."},"warnings":[{"fix":"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').","message":"In pylxd 2.3.8 and later, the /1.0/containers and /1.0/virtual-machines endpoints are removed; all operations now use /1.0/instances. Code that relied on container-specific endpoints (e.g., client.containers) may break.","severity":"breaking","affected_versions":">=2.3.8"},{"fix":"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.","message":"Storage and profile operations became asynchronous in LXD, requiring pylxd 2.3.7+. Some methods that previously returned immediately now return an operation object that must be waited on.","severity":"breaking","affected_versions":">=2.3.7"},{"fix":"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.","message":"The requests-unixsocket library (used for local socket connections) is incompatible with requests 2.32.0+. As of pylxd 2.3.4, the library pins requests <2.32.0, but future versions may break.","severity":"deprecated","affected_versions":"<2.3.4"},{"fix":"client = Client(endpoint='https://...', cert=('cert.pem', 'key.pem')); client.authenticate('mypassword')","message":"When connecting to a remote LXD with password authentication, you must call client.authenticate(password) after creating the client. The password is not passed in the constructor.","severity":"gotcha","affected_versions":"all"},{"fix":"config = {'name': 'vm1', 'type': 'virtual-machine', 'source': {'type': 'image', 'alias': 'ubuntu/22.04'}}","message":"Instance creation uses the /1.0/instances endpoint. The config dict must include a 'type' key (e.g., 'container' or 'virtual-machine') to specify the instance type. Omitting it may default to container but is ambiguous.","severity":"gotcha","affected_versions":">=2.3.8"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure the client certificate is added to the LXD trust store: `lxc config trust add client.crt` on the LXD host.","cause":"Authentication failed due to invalid certificate or missing trust relationship.","error":"pylxd.exceptions.LXDAPIException: 'trust'"},{"fix":"Add user to the lxd group: `sudo usermod -aG lxd $USER` then log out and back in.","cause":"The LXD Unix socket is not accessible to the current user (not in lxd group).","error":"requests.exceptions.ConnectionError: ('Connection aborted.', PermissionError(13, 'Permission denied'))"},{"fix":"Verify the resource name/alias exists. For images, use `lxc image list` to check available aliases.","cause":"The requested resource (e.g., instance, image) does not exist on the LXD server.","error":"pylxd.exceptions.LXDAPIException: 'not found'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}