playwright-python

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

Library
PyPI
v1.63.0
15,017 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
91 /100 Excellent
Development Activity 92
Maintenance 100
Community 72
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

Python
100%
Apache 2.0

Agno

AI Development · Automation · Devops

42,358

Build, run, and manage agent platforms with a full production stack — SDK, runtime, and control plane included.

View details
93
Repo Health
87
Technical
66
Dependency
Built with
Python 100%
Updated 4 days ago
Python
62%
MIT

AutoGen

AI Development · Automation

61,194

Build autonomous and human-in-the-loop multi-agent AI systems with a layered, event-driven Python and .NET framework pioneered at Microsoft Research.

View details
56
Repo Health
78
Technical
73
Dependency
Built with
Python 62%
C# 25%
TypeScript 12%
Updated 5 months ago
Python
66%
Other

AutoGPT

AI Assistants · Automation · Productivity

187,596

Build, deploy, and run autonomous AI agents that automate complex multi-step workflows using a visual block-based graph editor.

View details
93
Repo Health
78
Technical
66
Dependency
Built with
Python 66%
TypeScript 33%
Updated 4 days ago
Go
32%
Apache 2.0

CubeSandbox

AI Agents · Developer Tools · Security

12,728

Instant, concurrent, hardware-isolated MicroVM sandboxes for AI agents — E2B-API compatible, sub-60ms cold starts, and a built-in zero-trust egress proxy, all self-hostable at scale.

View details
82
Repo Health
88
Technical
63
Dependency
Built with
Go 32%
Rust 26%
C 22%
Updated 1 weeks ago
Python
70%
Apache 2.0

GPT Researcher

AI Assistants · Productivity

29,650

The pioneering open-source autonomous AI agent that conducts deep, multi-source research and produces citation-backed reports exceeding 2,000 words — faster and more reliably than any human researcher.

View details
91
Repo Health
91
Technical
63
Dependency
Built with
Python 70%
TypeScript 18%
Updated 6 days ago
Python
64%
Other

Keep

Automation · Devops · Monitoring

12,359

The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.

View details
89
Repo Health
79
Technical
66
Dependency
Built with
Python 64%
TypeScript 36%
Updated 1 weeks ago
TypeScript
44%
Other

Magic

AI Agents · Automation · Low Code Platforms

5,043

Magic is an enterprise-grade open-source AI agent platform combining a generalist AI agent, workflow engine, IM, and collaborative office system for running an AI-powered digital workforce.

View details
70
Repo Health
79
Technical
65
Dependency
Built with
TypeScript 44%
PHP 32%
Updated 1 months ago
Python
37%
Other

Open WebUI

AI Agents · AI Assistants

153,390

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
91
Repo Health
75
Technical
66
Dependency
Built with
Python 37%
Svelte 34%
JavaScript 21%
Updated 4 days ago
TypeScript
95%
Other

OpenHands

AI Code Assistants · AI Development

89,328

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 95%
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