{"library":"rest-connector","title":"pyATS REST Connector","description":"The `rest-connector` package provides the `Rest` connection plugin for the pyATS framework, enabling automated interaction with REST APIs for network devices or other API endpoints. It is part of the larger Cisco pyATS ecosystem and is actively maintained, with a release cadence tied to pyATS itself, typically several releases per year. It simplifies making HTTP requests within pyATS test automation.","language":"python","status":"active","last_verified":"Mon May 18","install":{"commands":["pip install rest-connector pyats"],"cli":null},"imports":["from pyats.topology import Testbed","from pyats.connections.rest import Rest"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom pyats.topology import Testbed\n\n# 1. Create a testbed.yaml file:\n#   devices:\n#     my_rest_api:\n#       os: rest\n#       connections:\n#         rest:\n#           class: pyats.connections.rest.Rest\n#           arguments:\n#             host: example.com\n#             port: 443\n#             ssl_verify: True\n#             headers:\n#               Content-Type: application/json\n#             credentials:\n#               username: ${{ REST_USERNAME }}\n#               password: ${{ REST_PASSWORD }}\n\n# Set environment variables for credentials (for a real API)\n# os.environ['REST_USERNAME'] = 'myuser'\n# os.environ['REST_PASSWORD'] = 'mypassword'\n\n# For this example, we'll use a placeholder and mock if needed\n# In a real scenario, example.com/api/data would be queried.\n# For a runnable example that doesn't hit a real server, we assume a simple GET\n# and print the raw text, as full mocking is out of quickstart scope.\n\n# Mocking a testbed for a runnable example without actual file I/O\n# In a real scenario, this would load from a 'testbed.yaml' file.\nclass MockConnection:\n    def __init__(self, host, port, ssl_verify, headers, credentials):\n        self.host = host\n        self.port = port\n        self.ssl_verify = ssl_verify\n        self.headers = headers\n        self.credentials = credentials\n\n    def get(self, path, headers=None, verify=None, auth=None):\n        class MockResponse:\n            def __init__(self, text, status_code=200):\n                self.text = text\n                self.status_code = status_code\n\n            def json(self):\n                import json\n                return json.loads(self.text)\n\n        if path == '/api/data':\n            print(f\"[Mock] GET request to {self.host}:{self.port}{path}\")\n            return MockResponse('{\"status\": \"success\", \"data\": [1,2,3]}')\n        return MockResponse('{\"error\": \"not found\"}', status_code=404)\n\nclass MockRestDevice:\n    def __init__(self, name, connections_config):\n        self.name = name\n        self.rest = MockConnection(\n            connections_config['rest']['arguments']['host'],\n            connections_config['rest']['arguments']['port'],\n            connections_config['rest']['arguments']['ssl_verify'],\n            connections_config['rest']['arguments']['headers'],\n            connections_config['rest']['arguments']['credentials']\n        )\n\n    def connect(self):\n        print(f\"[Mock] Connecting to device {self.name}\")\n        # Simulate connection logic\n\n# Simulate a simple testbed and device using the mock classes\ntestbed_config = {\n    'devices': {\n        'my_rest_api': {\n            'os': 'rest',\n            'connections': {\n                'rest': {\n                    'class': 'pyats.connections.rest.Rest',\n                    'arguments': {\n                        'host': 'example.com',\n                        'port': 443,\n                        'ssl_verify': True,\n                        'headers': {'Content-Type': 'application/json'},\n                        'credentials': {\n                            'username': os.environ.get('REST_USERNAME', 'mockuser'),\n                            'password': os.environ.get('REST_PASSWORD', 'mockpass')\n                        }\n                    }\n                }\n            }\n        }\n    }\n}\n\n# In a real scenario, load from file:\n# testbed = Testbed('testbed.yaml')\n# For this quickstart, we'll create a mock Testbed/device\nclass MockTestbed:\n    def __init__(self, config):\n        self.devices = {\n            name: MockRestDevice(name, device_config)\n            for name, device_config in config['devices'].items()\n        }\n\nmock_testbed = MockTestbed(testbed_config)\ndevice = mock_testbed.devices['my_rest_api']\n\n# 2. Connect to the device (initiates the REST session)\ndevice.connect()\n\n# 3. Make an API call\ntry:\n    response = device.rest.get('/api/data')\n    print(f\"API Response Status: {response.status_code}\")\n    if response.status_code == 200:\n        print(f\"API Response JSON: {response.json()}\")\n    else:\n        print(f\"API Error: {response.text}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")","lang":"python","description":"This quickstart demonstrates how to set up a REST API connection using a pyATS testbed configuration. It involves defining a device of `os: rest` type in a YAML testbed file, then connecting to it from Python and making a simple GET request. Credentials are securely fetched from environment variables. A mock setup is provided for immediate execution without a live API or testbed file.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-18","installed_version":"26.4","pypi_latest":"26.4","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":70,"avg_install_s":16.2,"avg_import_s":1.8,"wheel_type":"sdist"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"rest-connector","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.7,"mem_mb":24.9,"disk_size":"360.9M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"rest-connector","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":17.2,"import_time_s":1.34,"mem_mb":24.9,"disk_size":"198M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"rest-connector","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"rest-connector","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":14.3,"import_time_s":2.14,"mem_mb":27.6,"disk_size":"212M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"rest-connector","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"rest-connector","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":14.1,"import_time_s":2.52,"mem_mb":27.4,"disk_size":"211M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"rest-connector","exit_code":1,"wheel_type":null,"failure_reason":"build_error","import_side_effects":null,"install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":null},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"rest-connector","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":14,"import_time_s":2.35,"mem_mb":28.1,"disk_size":"209M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"rest-connector","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":1.34,"mem_mb":20.9,"disk_size":"202.8M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"rest-connector","exit_code":0,"wheel_type":"sdist","failure_reason":null,"import_side_effects":"clean","install_time_s":21.2,"import_time_s":1.18,"mem_mb":20.9,"disk_size":"426M"}]}}