Skip to main content

Interactive REPL for Playwright browser automation with automatic script generation

Project description

Playwright Interpreter

Interactive REPL for Playwright browser automation with automatic Python script generation.

Record commands as you explore a site, then export a standalone Playwright script you can run, share, or check into version control.

Installation

pip install playwright-interpreter
playwright install

For development:

git clone https://github.com/playwright-interpreter/playwright-interpreter.git
cd playwright-interpreter
pip install -e ".[dev]"
playwright install

Quick Start

Launch the interactive REPL:

playwright-interpreter

Example session:

Playwright Interpreter v0.1.0

pi> launch
pi> goto https://google.com
pi> fill textarea "playwright interpreter"
pi> click input[type=submit]
pi> screenshot result.png
pi> code
pi> exit

The code command displays the generated script:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(headless=False)

    page = browser.new_page()

    page.goto("https://google.com")
    page.fill("textarea", "playwright interpreter")
    page.click("input[type=submit]")
    page.screenshot(path="result.png")

    browser.close()

On exit, the session is saved automatically:

  • session.json — recorded commands
  • generated_script.py — executable Playwright script

REPL Usage

Meta Commands

Command Description
help Show all available commands
history Show executed commands
code Display generated Python script
save Save session.json and generated_script.py
clear Clear recorded actions
export <file> Export script to a custom filename
load <session.json> Load a previous session
exit Exit, save session, and close browser

Playwright Commands

Command Description
launch Launch Chromium browser (opens a new page)
new_page Open a new browser page
goto <url> Navigate to a URL
click <selector> Click an element
dblclick <selector> Double-click an element
hover <selector> Hover over an element
fill <selector> <text> Fill an input field
type <selector> <text> Type text into an element
press <selector> <key> Press a key on an element
wait <milliseconds> Wait for a duration
reload Reload the current page
back Navigate back
forward Navigate forward
screenshot <file> Save a screenshot
close Close the browser

Quoted strings are supported for selectors and text with spaces:

pi> fill "#search" "playwright interpreter"

CLI Commands

Interactive REPL

playwright-interpreter

Replay a Session

Re-execute recorded actions from a saved session:

playwright-interpreter replay session.json

Generate Script

Create a Playwright script from a session file without opening a browser:

playwright-interpreter generate session.json
playwright-interpreter generate session.json -o my_script.py

Examples

Save During a Session

pi> launch
pi> goto https://example.com
pi> screenshot home.png
pi> save

Load a Previous Session

pi> load session.json
pi> code

Export to Custom File

pi> export my_automation.py

Development

Run tests with coverage:

pytest

Run tests without coverage threshold:

pytest --no-cov

Project structure:

playwright_interpreter/
├── cli.py          # Typer CLI entrypoint
├── repl.py         # Interactive REPL
├── parser.py       # shlex-based command parser
├── commands.py     # Command definitions
├── executor.py     # Playwright command execution
├── session.py      # Browser session management
├── recorder.py     # Action recording and persistence
├── generator.py    # Python script generation
├── models.py       # Pydantic data models
├── exceptions.py   # Custom exceptions
└── utils.py        # Shared utilities

Publishing

Build and publish to PyPI:

pip install build twine
python -m build
twine upload dist/*

Ensure Playwright browsers are installed on target machines:

playwright install

License

MIT License — see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

playwright_interpreter-0.1.0.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

playwright_interpreter-0.1.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file playwright_interpreter-0.1.0.tar.gz.

File metadata

  • Download URL: playwright_interpreter-0.1.0.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for playwright_interpreter-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e9d25e408971690c89374198266a144add701d6cd9e9d1609df75760f1af1d45
MD5 b8ce4cdb2367eb9bf9e76d3df77724d7
BLAKE2b-256 d6cb2db2ac35d499cad7d581348fbb2b3dbbfbd780eaddfb36b676d9b3e9bcc4

See more details on using hashes here.

File details

Details for the file playwright_interpreter-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for playwright_interpreter-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20c8eda2473e899d142dbcc090ae9fbffb3ab9a2c2e30006573f4a798e0bea73
MD5 7840eb5a863b9a5d51b7a95484167502
BLAKE2b-256 fc77aeaa522d56f63be3a95057ffc69e5f75c5692c99da38e55cab60daac1443

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page