Registry / http-networking / rest-connector

rest-connector

JSON →
library26.5pypypiunverified

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.

pip install rest-connector pyats
INSTALL
IMPORT
SIG · REST-CONNECTOR
R
rest-connector
http-networkingpythonv26.5
Install
16.0s avg
Import
1793ms
Disk
264MB
Pass rate
7/ 10
Env Coverage7 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v26.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 16.35s
py 3.11
✕ build_error
✓ 14.73s
py 3.12
✕ build_error
✓ 14.13s
py 3.13
✕ build_error
✓ 13.88s
py 3.9
✓ —
✓ 20.83s
264MB installed
● package 264MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Testbed
from pyats.topology import Testbed
from rest_connector.topology import Testbed
The core Testbed class is part of pyATS topology, not directly from rest-connector.
Rest
from pyats.connections.rest import Rest
from rest_connector import Rest
The Rest connection class is located within the pyATS connections namespace, not at the top level of the rest-connector package.

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.

import os from pyats.topology import Testbed # 1. Create a testbed.yaml file: # devices: # my_rest_api: # os: rest # connections: # rest: # class: pyats.connections.rest.Rest # arguments: # host: example.com # port: 443 # ssl_verify: True # headers: # Content-Type: application/json # credentials: # username: ${{ REST_USERNAME }} # password: ${{ REST_PASSWORD }} # Set environment variables for credentials (for a real API) # os.environ['REST_USERNAME'] = 'myuser' # os.environ['REST_PASSWORD'] = 'mypassword' # For this example, we'll use a placeholder and mock if needed # In a real scenario, example.com/api/data would be queried. # For a runnable example that doesn't hit a real server, we assume a simple GET # and print the raw text, as full mocking is out of quickstart scope. # Mocking a testbed for a runnable example without actual file I/O # In a real scenario, this would load from a 'testbed.yaml' file. class MockConnection: def __init__(self, host, port, ssl_verify, headers, credentials): self.host = host self.port = port self.ssl_verify = ssl_verify self.headers = headers self.credentials = credentials def get(self, path, headers=None, verify=None, auth=None): class MockResponse: def __init__(self, text, status_code=200): self.text = text self.status_code = status_code def json(self): import json return json.loads(self.text) if path == '/api/data': print(f"[Mock] GET request to {self.host}:{self.port}{path}") return MockResponse('{"status": "success", "data": [1,2,3]}') return MockResponse('{"error": "not found"}', status_code=404) class MockRestDevice: def __init__(self, name, connections_config): self.name = name self.rest = MockConnection( connections_config['rest']['arguments']['host'], connections_config['rest']['arguments']['port'], connections_config['rest']['arguments']['ssl_verify'], connections_config['rest']['arguments']['headers'], connections_config['rest']['arguments']['credentials'] ) def connect(self): print(f"[Mock] Connecting to device {self.name}") # Simulate connection logic # Simulate a simple testbed and device using the mock classes testbed_config = { 'devices': { 'my_rest_api': { 'os': 'rest', 'connections': { 'rest': { 'class': 'pyats.connections.rest.Rest', 'arguments': { 'host': 'example.com', 'port': 443, 'ssl_verify': True, 'headers': {'Content-Type': 'application/json'}, 'credentials': { 'username': os.environ.get('REST_USERNAME', 'mockuser'), 'password': os.environ.get('REST_PASSWORD', 'mockpass') } } } } } } } # In a real scenario, load from file: # testbed = Testbed('testbed.yaml') # For this quickstart, we'll create a mock Testbed/device class MockTestbed: def __init__(self, config): self.devices = { name: MockRestDevice(name, device_config) for name, device_config in config['devices'].items() } mock_testbed = MockTestbed(testbed_config) device = mock_testbed.devices['my_rest_api'] # 2. Connect to the device (initiates the REST session) device.connect() # 3. Make an API call try: response = device.rest.get('/api/data') print(f"API Response Status: {response.status_code}") if response.status_code == 200: print(f"API Response JSON: {response.json()}") else: print(f"API Error: {response.text}") except Exception as e: print(f"An error occurred: {e}")
Debug
Known issues
gotchaBy default, `ssl_verify` is `True` for secure connections. For internal APIs with self-signed certificates, users often disable it (e.g., `ssl_verify: False` in testbed arguments). This should be strictly avoided in production environments due to significant security risks.
fix
For development, set `ssl_verify: False`. For production, ensure valid, trusted certificates are used, or explicitly trust the CA by providing a `ca_bundle` path in connection arguments.
affects: All versions
gotchaWhile direct instantiation of `pyats.connections.rest.Rest` is possible, the recommended and most robust way to use `rest-connector` within the pyATS framework is through a `Testbed` definition. This approach handles connection lifecycle, integrates with other pyATS features, and centralizes configuration.
fix
Always define REST devices within a `Testbed` YAML file and load it using `from pyats.topology import Testbed`.
affects: All versions
gotchaREST APIs often impose rate limits or require pagination for large datasets. `rest-connector` provides basic request functionality; users are responsible for implementing logic to handle these API-specific constraints (e.g., retries, sleep intervals, parsing pagination headers/links).
fix
Implement retry mechanisms (e.g., using `tenacity`), check `Retry-After` headers for rate limits, and write explicit loops or functions to handle paginated responses based on API documentation.
affects: All versions
breakingMajor version upgrades of the core `pyATS` framework (e.g., from 21.x to 22.x) can sometimes introduce changes to connection arguments, credential handling, or underlying library versions that affect `rest-connector` behavior. Always consult the pyATS release notes.
fix
Review the pyATS release notes for any breaking changes related to connection plugins. Update testbed configurations and Python code to align with the new pyATS version's requirements.
affects: Inter-major pyATS versions
Upgrade
Version history
26.5latest on PyPI · released May 28, 2026
Audit
Dependencies
pyatsrequiredrest-connector is a plugin for the pyATS framework and is typically used within a pyATS testbed environment.
requestsrequiredCore HTTP client library used by rest-connector for making requests.
Agent activity
5 hits · last 30 days
node
4
Resources
rest-connector — pip install rest-connector · libregistry