{"id":8240,"library":"ixnetwork-restpy","title":"IxNetwork Python Client","description":"The ixnetwork-restpy library is the official Python client for automating Keysight's IxNetwork via its REST API. It provides an object-oriented interface to programmatically control test platforms, configure network topologies, generate traffic, and collect statistics. The library is actively maintained, with frequent minor releases (typically monthly or bi-monthly) to support new IxNetwork features and address bug fixes, currently at version 1.9.0.","status":"active","version":"1.9.0","language":"en","source_language":"en","source_url":"https://github.com/OpenIxia/ixnetwork_restpy","tags":["ixnetwork","network-testing","traffic-generator","automation","rest-api","keysight"],"install":[{"cmd":"pip install --upgrade ixnetwork-restpy","lang":"bash","label":"Install or Upgrade"}],"dependencies":[{"reason":"Used for underlying HTTP REST communication with the IxNetwork API server.","package":"requests","optional":false}],"imports":[{"note":"SessionAssistant is the recommended entry point for general scripting, providing simplified session management and access to the IxNetwork object.","symbol":"SessionAssistant","correct":"from ixnetwork_restpy import SessionAssistant"},{"note":"While functional, SessionAssistant is generally preferred for its consolidated features. If using TestPlatform, ensure to import from the full path `ixnetwork_restpy.testplatform.testplatform`. Older examples might show a direct import that is now incorrect.","wrong":"from ixnetwork_restpy import TestPlatform","symbol":"TestPlatform","correct":"from ixnetwork_restpy.testplatform.testplatform import TestPlatform"}],"quickstart":{"code":"import os\nfrom ixnetwork_restpy import SessionAssistant, Files\n\n# Configure connection parameters\nIXNETWORK_API_SERVER_IP = os.environ.get('IXNET_SERVER_IP', '127.0.0.1')\nIXNETWORK_USERNAME = os.environ.get('IXNET_USERNAME', 'admin')\nIXNETWORK_PASSWORD = os.environ.get('IXNET_PASSWORD', 'admin')\n\n# Create a session and connect to IxNetwork\ntry:\n    session_assistant = SessionAssistant(\n        IpAddress=IXNETWORK_API_SERVER_IP,\n        UserName=IXNETWORK_USERNAME,\n        Password=IXNETWORK_PASSWORD,\n        ClearConfig=True, # Clears any existing configuration on the server\n        LogLevel=SessionAssistant.LOGLEVEL_INFO\n    )\n    ixnetwork = session_assistant.Ixnetwork\n    print(f\"Connected to IxNetwork API Server at {IXNETWORK_API_SERVER_IP}\")\n\n    # Example: Create a simple configuration (e.g., two ports, basic traffic)\n    # These IPs and ports must match your physical setup\n    port_map = session_assistant.PortMapAssistant()\n    port_map.Map('10.0.0.1', 1, 1, Name='TxPort') # Chassis IP, Card ID, Port ID\n    port_map.Map('10.0.0.1', 1, 2, Name='RxPort') # Chassis IP, Card ID, Port ID\n    port_map.Connect(ForceOwnership=True)\n    print(\"Ports mapped and connected.\")\n\n    # Add a traffic item\n    traffic_item = ixnetwork.Traffic.TrafficItem.add(Name='Simple Traffic', TrafficType='raw')\n    traffic_item.EndpointSet.add(\n        Sources=ixnetwork.Vport.find(Name='^TxPort$').Protocols.find(),\n        Destinations=ixnetwork.Vport.find(Name='^RxPort$').Protocols.find()\n    )\n    traffic_config = traffic_item.ConfigElement.find()\n    traffic_config.FrameRate.update(Type='percentLineRate', Rate='10')\n    traffic_config.TransmissionControl.update(Type='continuous')\n    print(\"Traffic item configured.\")\n\n    # Apply and start traffic\n    ixnetwork.Traffic.Apply()\n    ixnetwork.Traffic.StartStatelessTrafficBlocking()\n    print(\"Traffic started. Waiting for stats...\")\n\n    # Get and print statistics\n    port_stats = session_assistant.StatViewAssistant('Port Statistics')\n    traffic_item_stats = session_assistant.StatViewAssistant('Traffic Item Statistics')\n    \n    print(\"\\n--- Port Statistics ---\")\n    print(port_stats)\n    print(\"\\n--- Traffic Item Statistics ---\")\n    print(traffic_item_stats)\n\n    # Stop traffic and clear config\n    ixnetwork.Traffic.StopStatelessTrafficBlocking()\n    session_assistant.ClearConfig()\n    print(\"Traffic stopped and configuration cleared.\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    if 'session_assistant' in locals() and session_assistant.Is</span>Connected:\n        # Ensure the session is properly closed if it was opened\n        session_assistant.Session.delete()\n        print(\"Session deleted.\")\n","lang":"python","description":"This quickstart demonstrates how to connect to an IxNetwork API server, authenticate, map physical ports, create a basic traffic item, start/stop traffic, and retrieve statistics. Replace '10.0.0.1' with your IxNetwork chassis IP, and ensure the `IXNET_SERVER_IP`, `IXNET_USERNAME`, and `IXNET_PASSWORD` environment variables are set or updated in the script. It uses `SessionAssistant` for simplified workflow and `PortMapAssistant` for port management."},"warnings":[{"fix":"Review existing scripts and update property access to match the official API. Use `help()` on objects or consult online documentation to verify valid properties.","message":"Introduction of `slots` support in version 1.0.41 (September 2019) causes `AttributeError` when accessing non-existent properties.","severity":"breaking","affected_versions":">=1.0.41"},{"fix":"Always use a configuration file saved with a version of IxNetwork that is equal to or older than the target IxNetwork API server version.","message":"IxNetwork saved configuration files (`.ixncfg`) are generally forward-compatible but not backward-compatible. A configuration saved with a newer IxNetwork server version will not load on an older server version.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate any scripts using `IxNetRestApi` to `ixnetwork-restpy` for continued support and access to new features.","message":"The older `IxNetRestApi` library is deprecated in favor of `ixnetwork-restpy`. The `IxNetRestApi` is no longer maintained, and new features/enhancements will not be added to it.","severity":"deprecated","affected_versions":"All versions (deprecation announced starting around 2021)"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Verify that the `IpAddress` and `RestPort` (if explicitly provided) are correct. Ensure the IxNetwork API server (Windows GUI, Connection Manager, or Linux API Server) is running and accessible from the machine running the script. Check firewall settings on both client and server.","cause":"The Python client failed to establish a connection to the specified IxNetwork API server. This can be due to an incorrect IP address, an inaccessible or incorrect REST API port, the IxNetwork API server not running, or a firewall blocking the connection.","error":"ixnetwork_restpy.errors.ConnectionError: Unable to connect to <IP_ADDRESS>. Check the ip address and consider using the rest_port parameter."},{"fix":"Review the parameters being passed to the method causing the `BadRequestError`. Ensure that all parent objects are properly configured and committed before attempting to add child objects like protocols. Consult the specific IxNetwork API documentation for required attributes and prerequisites.","cause":"This error typically indicates that an API call (often `add()` for a child object) was made with invalid parameters or when the parent object is not in a suitable state to accept the operation. For example, adding a protocol before the virtual port is fully configured or assigned.","error":"ixnetwork_restpy.errors.BadRequestError: ... /vport/protocols => 400 Bad Request"},{"fix":"Utilize the filtering capabilities of `StatViewAssistant` to target specific traffic items by name or other properties. Alternatively, iterate through the rows of the statistics view to extract data for each individual traffic item, as demonstrated in samples using `StatViewAssistant`'s methods.","cause":"When using `StatViewAssistant`, the default retrieval or display might only show a summary or the first matched traffic item if not explicitly filtered or iterated to gather all relevant statistics.","error":"Only getting one 'Traffic Item Statistics' when I have multiple traffic items."}]}