{"library":"softlayer","title":"SoftLayer Python Client","type":"library","description":"The `softlayer-python` library provides both a Python API client and a command-line interface (CLI) for interacting with the IBM Cloud SoftLayer API. It abstracts the complexities of the SOAP/REST API, allowing developers to manage SoftLayer resources such as virtual servers, bare metal, storage, and networking. The current version is 6.2.9, and the project maintains an active release cadence with frequent minor updates and bug fixes.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install softlayer"],"cli":{"name":"slcli","version":"Current: slcli (SoftLayer Command-line) v6.2.9"}},"imports":["import SoftLayer\nclient = SoftLayer.Client(...)","from SoftLayer.exceptions import SoftLayerAPIError"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://softlayer.github.io/","github":"https://github.com/SoftLayer/softlayer-python","docs":null,"changelog":null,"pypi":"https://pypi.org/project/softlayer/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import SoftLayer\nimport os\n\n# SoftLayer API credentials can be set as environment variables (SL_USERNAME, SL_API_KEY)\n# or passed directly. Environment variables are recommended for security.\n# SL_ENDPOINT_URL is optional, defaults to 'api.softlayer.com/rest/v3.1'\nclient = SoftLayer.Client(\n    username=os.environ.get('SL_USERNAME', 'YOUR_USERNAME'),\n    api_key=os.environ.get('SL_API_KEY', 'YOUR_API_KEY'),\n    endpoint_url=os.environ.get('SL_ENDPOINT_URL')\n)\n\ntry:\n    # Example: Get the account details\n    account = client['Account'].getObject()\n    print(f\"Successfully connected to SoftLayer. Account ID: {account['id']}, Company: {account['companyName']}\")\n\n    # Example: List up to 5 virtual guests (VMs)\n    # Object masks are crucial for retrieving full data\n    mask = 'mask[id, hostname, domain, primaryIpAddress, primaryBackendIpAddress]'\n    vms = client['Account'].getVirtualGuests(mask=mask, limit=5)\n    if vms:\n        print(\"\\nVirtual Guests (first 5):\")\n        for vm in vms:\n            print(f\"- ID: {vm.get('id')}, Hostname: {vm.get('hostname')}, IP: {vm.get('primaryIpAddress')}\")\n    else:\n        print(\"\\nNo virtual guests found.\")\n\nexcept SoftLayer.exceptions.SoftLayerAPIError as e:\n    print(f\"Error connecting to SoftLayer API: {e}\")\n    print(\"Please ensure your SL_USERNAME and SL_API_KEY environment variables are correct.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to initialize the SoftLayer client using environment variables for authentication and retrieve basic account information. It also shows an example of fetching virtual guests, highlighting the use of 'object masks' which are fundamental for getting detailed API responses.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}