{"id":9562,"library":"browserstack-sdk","title":"BrowserStack Python SDK (Legacy)","description":"This is a legacy Python SDK for integrating Selenium-webdriver tests with BrowserStack. It is officially deprecated and no longer actively maintained. BrowserStack now recommends using standard Selenium with BrowserStack capabilities directly. The last release of this SDK was 1.45.0 in April 2022.","status":"deprecated","version":"1.45.0","language":"en","source_language":"en","source_url":"https://github.com/browserstack/browserstack-sdk-python","tags":["testing","selenium","browserstack","web testing","deprecated"],"install":[{"cmd":"pip install browserstack-sdk","lang":"bash","label":"Install Deprecated SDK"}],"dependencies":[{"reason":"Core dependency for WebDriver interactions, requires >=4.0.0","package":"selenium","optional":false},{"reason":"HTTP client for API interactions","package":"requests","optional":false},{"reason":"Used for WebSocket communication, requires >=1.0.0","package":"websocket-client","optional":false}],"imports":[{"note":"This import is specific to the deprecated SDK for managing BrowserStack Local tunnels.","symbol":"Local","correct":"from browserstack.local import Local"}],"quickstart":{"code":"import os\nfrom selenium import webdriver\nfrom selenium.webdriver.common.by import By\nfrom browserstack.local import Local # Specific to the DEPRECATED SDK\n\n# --- WARNING: This SDK is deprecated. Use standard Selenium setup for new projects. ---\n\n# Configuration using environment variables\nBROWSERSTACK_USERNAME = os.environ.get('BROWSERSTACK_USERNAME', 'YOUR_USERNAME')\nBROWSERSTACK_ACCESS_KEY = os.environ.get('BROWSERSTACK_ACCESS_KEY', 'YOUR_ACCESS_KEY')\n\n# Desired capabilities for the test\ndesired_cap = {\n    'bstack:options': {\n        'userName': BROWSERSTACK_USERNAME,\n        'accessKey': BROWSERSTACK_ACCESS_KEY,\n        'buildName': 'BrowserStack Python SDK Example (Legacy)',\n        'sessionName': 'Local Test with Deprecated SDK',\n        'local': 'true' # Enable local testing\n    },\n    'browserName': 'Chrome',\n    'browserVersion': 'latest',\n    'os': 'Windows',\n    'osVersion': '10'\n}\n\nbs_local = None\ndriver = None\n\ntry:\n    # Start BrowserStack Local using the deprecated SDK's Local class\n    bs_local = Local()\n    bs_local_args = {\n        \"key\": BROWSERSTACK_ACCESS_KEY,\n        \"forcelocal\": \"true\"\n    }\n    print(\"Starting BrowserStack Local tunnel...\")\n    bs_local.start(bs_local_args)\n    print(\"BrowserStack Local tunnel started.\")\n\n    # Initialize Selenium WebDriver connected to BrowserStack hub\n    driver = webdriver.Remote(\n        command_executor='https://hub.browserstack.com/wd/hub',\n        desired_capabilities=desired_cap\n    )\n\n    # Perform a test that requires local access\n    driver.get(\"http://bs-local.com:45454/\")\n    print(f\"Page title: {driver.title}\")\n\n    # Example assertion (this specific page is part of BrowserStack Local setup)\n    if \"BrowserStack Local\" in driver.title:\n        print(\"Test Passed: Successfully accessed local URL through BrowserStack Local.\")\n    else:\n        print(\"Test Failed: Could not access local URL.\")\n\nfinally:\n    # Stop BrowserStack Local tunnel\n    if bs_local:\n        print(\"Stopping BrowserStack Local tunnel...\")\n        bs_local.stop()\n        print(\"BrowserStack Local tunnel stopped.\")\n\n    # Quit the WebDriver session\n    if driver:\n        driver.quit()\n        print(\"WebDriver session quit.\")\n\n# To run this example:\n# 1. Set BROWSERSTACK_USERNAME and BROWSERSTACK_ACCESS_KEY environment variables.\n# 2. pip install browserstack-sdk selenium\n# 3. python your_script.py","lang":"python","description":"This quickstart demonstrates how the deprecated `browserstack-sdk` was typically used for setting up BrowserStack Local testing with Selenium. It is provided for historical context and to highlight functionality unique to the SDK. For new projects, it is highly recommended to follow the official BrowserStack documentation for setting up Selenium tests without this SDK."},"warnings":[{"fix":"Migrate your tests to directly use `selenium.webdriver.Remote` and configure BrowserStack capabilities (e.g., `bstack:options`) as described in the official BrowserStack documentation (https://www.browserstack.com/docs/automate/selenium/python/getting-started).","message":"The `browserstack-sdk` library is officially deprecated and no longer actively maintained by BrowserStack. It is strongly recommended to use standard `selenium` with BrowserStack capabilities directly for all new development.","severity":"breaking","affected_versions":"All versions"},{"fix":"Refer to the official BrowserStack documentation for up-to-date best practices for Python and Selenium integration, which provide current and maintained solutions.","message":"Using this deprecated SDK may lead to compatibility issues with newer versions of Python, Selenium, or BrowserStack infrastructure, as it receives no further updates. This could result in unexpected errors or security vulnerabilities.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Consult the BrowserStack documentation on local testing with Python and Selenium for the current setup instructions, which typically do not involve programmatic control from this specific SDK.","message":"The methods for setting up local testing (BrowserStack Local) provided by `browserstack.local.Local` are specific to this deprecated SDK. The recommended approach for local testing now involves setting `bstack:options` in your capabilities and typically starting the local tunnel via the BrowserStack Local application or CLI, not through this SDK.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"If you intend to use the legacy SDK (not recommended), run `pip install browserstack-sdk`. Otherwise, remove all imports related to `browserstack-sdk` (e.g., `from browserstack.local import Local`) and rewrite your test using standard `selenium` methods with direct capability configuration.","cause":"Attempting to import modules from the deprecated `browserstack-sdk` without it being installed, or after migrating to the modern approach that doesn't use these imports.","error":"ModuleNotFoundError: No module named 'browserstack'"},{"fix":"Verify `BROWSERSTACK_USERNAME` and `BROWSERSTACK_ACCESS_KEY` environment variables (or hardcoded values) are correct. Ensure your specified browser and OS capabilities are valid and supported by BrowserStack. If using local testing, verify the BrowserStack Local service is running and configured correctly according to the *latest* BrowserStack documentation, not the SDK's old methods.","cause":"This generic WebDriver error often indicates issues with BrowserStack credentials, outdated capabilities, or problems connecting to the BrowserStack hub. When using the deprecated SDK, it might not correctly handle newer authentication or connection methods.","error":"selenium.common.exceptions.WebDriverException: Message: Error forwarding the new session Error forwarding the new session Request: {}"},{"fix":"If you are migrating away from the deprecated SDK, replace such SDK-specific calls with standard Selenium WebDriver methods or direct BrowserStack capability settings. If you *must* use the SDK, ensure you are calling methods correctly as per its original documentation and that you are using the correct WebDriver instance that the SDK might have wrapped.","cause":"This SDK might have provided helper methods or custom WebDriver wrappers that are no longer available or relevant when using standard `selenium.webdriver.Remote`. Such an error indicates a call to a method specific to the SDK that does not exist on the standard Selenium WebDriver object.","error":"AttributeError: 'Remote' object has no attribute 'get_bstack_local'"}]}