Install Playwright Browsers from Python

1.0.0 · active · verified Thu Apr 16

install-playwright is a Python library that provides a programmatic way to execute the `playwright install` CLI command, which downloads browser binaries (Chromium, Firefox, WebKit) required by the Playwright automation library. This allows Python applications to manage Playwright browser installations directly, without needing to shell out to a subprocess. The current version is 1.0.0, and it follows an infrequent release cadence, primarily updating for compatibility or minor feature additions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `install_playwright` to programmatically install Playwright browser binaries. It first imports `sync_playwright` from the main `playwright` library to access browser type objects, then calls `install()` with the desired browser types. After installation, it includes a simple Playwright usage example to verify successful setup.

from playwright.sync_api import sync_playwright
from install_playwright import install

with sync_playwright() as p:
    # Install Chromium browser binaries
    print("Installing Chromium...")
    install([p.chromium])
    print("Chromium installed.")

    # Optionally, install other browsers
    # print("Installing Firefox and WebKit...")
    # install([p.firefox, p.webkit])
    # print("Firefox and WebKit installed.")

    # Example of using Playwright after installation
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("http://example.com")
    print(f"Page title: {page.title()}")
    browser.close()

view raw JSON →