Skip to main content

fluxwright

Run hundreds of headless Chrome jobs on one machine, with a Playwright-style API. Each new_page is a fresh browser context on a pooled Chrome. The engine queues jobs when every slot is busy, restarts browsers before they bloat, and replaces browsers that crash.

Docs: https://fluxwright.vercel.app

Requires a local Chrome/Chromium binary (FLUXWRIGHT_CHROMIUM, CHROME, CHROMIUM, or a standard install path). For headless jobs, chrome-headless-shell is picked up from PATH or Puppeteer's/Playwright's cache and opens pages much faster: npx @puppeteer/browsers install chrome-headless-shell@stable.

Install

pip install fluxwright

Wheels cover Windows x64, macOS (Intel and Apple Silicon) and Linux x86_64, for Python 3.10 and newer. Anywhere else, pip builds from source, which needs Rust.

Use

asyncio:

import asyncio
from fluxwright.async_api import async_playwright

async def main():
    async with async_playwright() as p:
        browser = await p.chromium.launch(max_browsers=4)
        page = await browser.new_page()
        await page.goto("https://example.com")
        print(await page.get_by_role("heading").text_content())  # "Example Domain"
        print(await page.evaluate("() => location.hostname"))
        png = await page.screenshot(full_page=True)  # bytes
        await page.close()
        await browser.close()

asyncio.run(main())

Blocking code:

from fluxwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch()
    page = browser.new_page()
    page.goto("https://example.com")
    print(page.title())
    browser.close()

The names are Playwright's, so a Playwright script for the features below runs after changing playwright.async_api to fluxwright.async_api (or sync_api). chromium can also be imported directly: from fluxwright.async_api import chromium.

Many jobs at once: start them all and let the engine queue them.

async def job(browser, url):
    page = await browser.new_page()
    try:
        await page.goto(url)
        return await page.title()
    finally:
        await page.close()

titles = await asyncio.gather(*(job(browser, url) for url in urls))

The sync API runs every call on one event loop in a background thread, so its objects work from any thread: a ThreadPoolExecutor of jobs sharing one browser is fine (Playwright's sync API does not allow that).

API

Method What it does
chromium.launch(max_browsers=None, executable_path=None, headless=None, queue_timeout=None) Start the pool (4 browsers by default). Headless uses chrome-headless-shell when installed (as Playwright does), else Chrome; FLUXWRIGHT_CHROMIUM or executable_path overrides. When every slot is busy, new_page waits its turn however long the queue is, so starting every job at once works; with queue_timeout (ms) it raises TimeoutError after that long instead, counting a browser start when one is needed
browser.new_page(...) A fresh browser context. Every option applies to this page only: proxy={"server", "bypass", "username", "password"}, user_agent, locale, timezone_id, geolocation={"latitude", "longitude", "accuracy"} (with permissions=["geolocation"]), permissions, viewport={"width", "height"}, device_scale_factor, color_scheme, storage_state (a dict or a file path)
browser.new_context(...) A context with new_page's options, as Playwright's new_context: context.new_page(), pages, route / unroute (routes added first apply from the page's first request), storage_state, cookies(), close(). Each context holds one page, so jobs never share cookies; a second new_page() raises Error
page.storage_state(path=None) Every cookie in the context plus localStorage of the current origin, in Playwright's format. With path, also saved as JSON for new_page(storage_state=path)
page.goto(url, wait_until=None) Navigate. wait_until: load (default), domcontentloaded, networkidle, commit
page.title() / page.content() Read
page.click(selector) / page.fill(selector, value) Scrolls into view, waits until enabled, stable, and not covered. Selector: CSS, text=Foo, text="Exact", role=button[name="Save"]
page.get_by_role(role, name=None, exact=None) / get_by_text(text, exact=None) / get_by_label / get_by_placeholder / get_by_test_id(id) / page.locator(selector) A Locator with click(), fill(v), wait_for(), text_content(), bounding_box(), screenshot(path=None) and evaluate("(el, arg) => ...", arg)
locator.nth(i) / .first / .last / filter(has_text=...) / locator.get_by_role(...) and the other finders Narrow a locator: by position (negative counts from the end), by contained text (case-insensitive), or by searching inside its matches
page.frame_locator(iframe_selector) The same finders inside an iframe, same- or cross-origin; nest with .frame_locator()
page.evaluate(expression, arg=None) Runs JavaScript in the page and returns its JSON result, awaiting promises. A function ("(x) => x * 2") is called with arg; anything else is evaluated as is. A thrown error raises fluxwright.Error
page.screenshot(full_page=None, path=None) PNG bytes, also written to path
page.route(url, handler) / page.unroute(url, handler=None) Request interception: url is a glob (**/api/*), a compiled regex or a function of the URL; the handler gets route (and request, if it takes two arguments) and answers with route.fulfill(status, headers, body, json, path, content_type), route.continue_(url, method, headers, post_data), route.abort(error_code) or route.fallback(). The handler added last runs first
page.on("console" | "pageerror", handler) / once / remove_listener Console messages (.type, .text) and uncaught errors (fluxwright.Error with .name, .message, .stack) as they happen
page.on("request" | "response" | "requestfinished" | "requestfailed", handler) Network traffic of the page, its popups and iframes: Request (.url, .method, .headers, .post_data, .resource_type, .failure) and Response (.status, .ok, .headers, .request, body(), text(), json())
page.expect_response(url_or_predicate, timeout=None) / expect_request with block: the first match from now on, a glob or regex for the URL or a function of the Response / Request; info.value is it. Default timeout 30 s
page.on("dialog", handler) Answer alert, confirm, prompt and beforeunload with dialog.accept(prompt_text) or dialog.dismiss(). Without a listener, or when no listener answers, a dialog is dismissed (beforeunload accepted), so the page never hangs
page.expect_download(timeout=None) / page.wait_for_download(timeout=None) The next download the page finished: .url, .suggested_filename, path(), save_as(path). Files are deleted when the page closes
page.console_messages() / page.page_errors() What the page, its popups and iframes logged, and the exceptions nothing caught, the last 1000 of each. Fail a job with assert await page.page_errors() == []
page.set_viewport_size({"width", "height"}) CSS-pixel viewport for this page
page.wait_for_selector(selector) Waits until visible (Playwright's default state)
page.close() / browser.close() Dispose the context / shut down

Timeouts are in milliseconds, as in Playwright. Errors are fluxwright.Error, and fluxwright.TimeoutError when something ran out of time. Close pages when a job is done; a page you forget is cleaned up when Python collects it.

In the sync API, route handlers run on worker threads and event listeners one at a time on a thread of their own, so both can call the page.

Develop

pip install maturin pytest
maturin develop   # needs Rust
pytest            # against a real Chrome

License

Licensed under the Apache License, Version 2.0.

Metadata

Release files for fluxwright 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fluxwright 0.5.0
File Size Uploaded Provenance Actions
fluxwright-0.5.0.tar.gz 125.8 kB Without provenance Details for fluxwright-0.5.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for fluxwright 0.5.0
File Actions
fluxwright-0.5.0-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for fluxwright-0.5.0-cp310-abi3-win_amd64.whl
fluxwright-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for fluxwright-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
fluxwright-0.5.0-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for fluxwright-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
fluxwright-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for fluxwright-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 7.8 MB

Release files / fluxwright-0.5.0.tar.gz

Download URL fluxwright-0.5.0.tar.gz
Size 125.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8267d3779b69d946121c33d93ecf25a1041bf448ea4e53b0efab76c26e33c24c
BLAKE2b-256 checksum
How to use checksums
22d484cffda23e451ade51fef959c78d755e7aeb3a5aef1af2cda8daf32f55bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Release files / fluxwright-0.5.0-cp310-abi3-win_amd64.whl

Download URL fluxwright-0.5.0-cp310-abi3-win_amd64.whl
Size 2.0 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
126a0f60f2c5284c2edf9388667a1f00d28de2d6a7deeae56ec0fce352a9472c
BLAKE2b-256 checksum
How to use checksums
70acc32888079fbd813f25d212d4692b321b0fb5edbc221539eb02327b54b558
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Release files / fluxwright-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fluxwright-0.5.0-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 2.0 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
344d7c5aa6b154f0375e55fa29b308dad3790ec0716471a6bd7f26c5043e9634
BLAKE2b-256 checksum
How to use checksums
3c5f1d7bb006975b722fca5bfc342e37d60c90c4ff0a3e0771b7607bf5a5efec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Release files / fluxwright-0.5.0-cp310-abi3-macosx_11_0_arm64.whl

Download URL fluxwright-0.5.0-cp310-abi3-macosx_11_0_arm64.whl
Size 1.9 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
712911f6ece1fb160c61b1a4bb8cdd371d4a1ca9f868057b1160708ed985e762
BLAKE2b-256 checksum
How to use checksums
d5e88d2397cffa5954d06999eb60442a81fc4ac8a9e48e3031eabfce27f70aad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Release files / fluxwright-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl

Download URL fluxwright-0.5.0-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.8 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f078239bc1fb61a9a97651d4ea8685e2b6ca30652bbf10c5f26a5c82f1d87f6f
BLAKE2b-256 checksum
How to use checksums
92c79311b0069e2f9b92e1696c321ea484553decf2191d4e1b5254dd82864866
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.11

Security for fluxwright 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page