playwright-python

A Python library that automates Chromium, Firefox, and WebKit through one reliable, auto-waiting API.

Library
PyPI
v1.64.1
15,061 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
94 /100 Excellent
Development Activity 100
Maintenance 100
Community 76
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 90
Code Quality 92
Innovation 90
Learning Curve 85

Playwright for Python is Microsoft’s official Python binding for the Playwright browser automation engine, letting developers drive Chromium, Firefox, and WebKit from a single, consistent API. It’s built for end-to-end testing and web scraping/automation workloads that need to reliably interact with real, modern web pages rather than a simplified DOM.

Under the hood, the Python package is a thin, fully-typed client over a bundled Node.js driver process: every call — clicking, navigating, waiting for network activity — is proxied over a message channel to the actual browser-automation engine, while the Python-facing API exposes both a synchronous surface (sync_playwright()) and an asyncio-based surface (async_playwright()) generated from the same underlying implementation. That means teams can pick whichever style fits their codebase (plain pytest scripts vs. asyncio-based scrapers) without giving up feature parity or auto-waiting semantics.

The library ships with built-in auto-waiting (actions wait for elements to be actionable before proceeding), network interception and mocking, multiple browser contexts for isolated sessions, and codegen/trace-viewer tooling exposed through its bundled CLI (playwright install, playwright codegen) for scaffolding and debugging tests.

What You Get

  • A single API that drives Chromium, Firefox, and WebKit without browser-specific code paths
  • Both a synchronous API (sync_playwright) and an asyncio-native API (async_playwright) generated from one shared implementation
  • Auto-waiting actions that wait for elements to become actionable, cutting down on manual sleeps and flaky selectors
  • Network interception and request/response mocking via route handlers
  • Isolated, disposable browser contexts for parallel, state-free test sessions
  • A bundled CLI (playwright install, playwright codegen, trace viewer) for driver setup, test recording, and debugging

Common Use Cases

  • End-to-end test suites for web applications, typically wired into pytest via the pytest-playwright plugin
  • Web scraping and data extraction from JavaScript-heavy pages that require a real rendering engine
  • Automated visual regression testing using screenshot comparisons across Chromium/Firefox/WebKit
  • Scripted browser workflows such as form submission, login flows, and multi-step user journeys
  • Cross-browser compatibility verification for web apps without maintaining separate browser-specific test code

Under The Hood

Architecture

The Python bindings wrap a bundled Node.js driver process launched via playwright/_impl/_driver.py’s compute_driver_executable(), communicating over a stdio-based message channel (playwright/_impl/_connection.py) that serializes calls to the driver process and receives events back as they occur. The public-facing modules (playwright/sync_api, playwright/async_api) are thin, code-generated facades over the shared low-level implementation objects in playwright/_impl/ (_browser.py, _browser_context.py, _page.py, _frame.py, and others), mapped through _impl_to_api_mapping.py so one core implementation backs both API styles. The synchronous facade achieves blocking calls by running the actual async event loop on a background thread and switching context with greenlets (_greenlets.py), so callers get synchronous-looking code while all real browser protocol traffic stays fully async underneath. This is a cleanly layered design: the Python-side objects are essentially typed proxies over remote state living in the driver process, so a change to that message-channel protocol would ripple through every _impl class, but the public API layer itself stays decoupled from that churn via the generated mapping layer.

Tech Stack

The package itself is pure Python (>=3.10) with a minimal runtime dependency footprint — pyee for the event-emitter pattern used in the connection/channel messaging layer, and greenlet for the sync/async context-switching bridge — while the actual browser engines are delegated to a versioned Node.js driver (pinned via DRIVER_VERSION/NODE_VERSION) built from Microsoft’s own playwright-core npm package and bundled per-platform at install time through setup.py’s custom wheel logic, covering macOS/Linux/Windows across x86_64/arm64. Packaging uses setuptools with setuptools-scm for version derivation and auditwheel for manylinux compliance, and the playwright console-script entry point simply shells out to the bundled Node.js driver binary.

Code Quality

Testing is extensive: a large tests/ suite is split into parallel sync/ and async/ variants plus shared common/ fixtures, run under pytest with asyncio_mode=auto, alongside per-engine golden-image directories (golden-chromium, golden-firefox, golden-webkit) for reference-image comparisons, all exercised across platforms in CI (.github/workflows/ci.yml and Azure Pipelines). Static analysis is comprehensive and enforced via pre-commit hooks covering black, isort, flake8, mypy (with disallow_untyped_defs and warn_redundant_casts), and a local pyright hook, alongside a custom license-header check. Error handling is explicit and typed through a dedicated _errors.py module (TargetClosedError, rewrite_error) rather than broad exception swallowing.

API Design The library’s core design bet is generating both a synchronous API (sync_playwright()) and an asyncio-native API (async_playwright()) from one shared implementation and protocol definition, via scripts/generate_sync_api.py and scripts/generate_async_api.py producing each API’s _generated.py. Rather than forcing developers into either a blocking (Selenium-style) or async-only client, Playwright gives both styles identical semantics and feature parity — auto-waiting, network interception, and multi-browser support — from a single source of truth, reducing the API-surface duplication and drift that hand-maintained sync/async twins usually accumulate.

Used by 15 apps in this directory

Go
36%

OpenPanel

Devops · Hosting Control Panel

764

Docker-powered web hosting control panel that gives every user a fully isolated environment with dedicated web server, database, and networking — VPS-grade security on shared hardware.

View details
87
Repo Health
75
Technical
63
Dependency
Built with
Go 36%
HTML 30%
TypeScript 24%
Updated 6 days ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 5 days ago
Python
87%
Apache 2.0

PrivateGPT

AI Development

57,611

The open-source API layer that turns local LLMs into production private AI applications with full Claude API compatibility

View details
88
Repo Health
83
Technical
70
Dependency
Built with
Python 87%
Updated 6 days ago
TypeScript
98%
MIT

Promptfoo

AI Development

26,358

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
67
Dependency
Built with
TypeScript 98%
Updated 5 days ago
Python
64%
AGPL 3.0

Shadowbroker

Analytics · Monitoring · Security

11,358

Self-hosted OSINT dashboard that fuses 60+ live intelligence feeds — flight tracking, ship AIS, satellites, CCTV, seismic and radio networks — into one real-time map, with an agent-ready command channel for AI co-analysts.

View details
85
Repo Health
83
Technical
71
Dependency
Built with
Python 64%
TypeScript 32%
Updated 6 days ago
Python
79%
AGPL 3.0

Skyvern

AI Agents · Automation

23,257

Skyvern (YC S2023) automates browser-based workflows by pairing LLMs with computer vision, letting agents click, fill, and extract data on sites they've never seen, without brittle XPath selectors that break on every layout change.

View details
89
Repo Health
82
Technical
70
Dependency
Built with
Python 79%
TypeScript 19%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers