BrowserStack Local Python

1.2.14 · active · verified Thu Apr 16

The `browserstack-local` Python library provides bindings for the BrowserStack Local testing feature. It allows users to test websites hosted on local development environments, staging environments, or behind firewalls/proxies, by establishing a secure tunnel between the user's machine and the BrowserStack cloud. The library is currently at version 1.2.14 and maintains an active development status with a positive release cadence, often releasing new versions within three months.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to initialize, start, check the status of, and stop a BrowserStack Local tunnel. It uses an environment variable for the BrowserStack Access Key, which is the recommended practice for security. The `verbose` option is added for detailed logging.

import os
from browserstack.local import Local

bs_local = Local()

# Replace <browserstack-accesskey> with your key or set as environment variable BROWSERSTACK_ACCESS_KEY
access_key = os.environ.get('BROWSERSTACK_ACCESS_KEY', 'YOUR_BROWSERSTACK_ACCESS_KEY')

bs_local_args = {
    "key": access_key,
    "verbose": "true" # Optional: enable verbose logging
}

try:
    # Start the Local instance
    bs_local.start(**bs_local_args)
    print("BrowserStack Local started.")

    # Check if BrowserStack Local instance is running
    if bs_local.isRunning():
        print("BrowserStack Local is running.")
        # Your test logic here that uses the local tunnel
    else:
        print("BrowserStack Local is NOT running.")

finally:
    # Stop the Local instance
    if bs_local.isRunning():
        bs_local.stop()
        print("BrowserStack Local stopped.")

view raw JSON →