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.1

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.1
File Size Uploaded Provenance Actions
fluxwright-0.5.1.tar.gz 126.9 kB Without provenance Details for fluxwright-0.5.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for fluxwright 0.5.1
File Actions
fluxwright-0.5.1-cp310-abi3-win_amd64.whl CPython 3.10 abi3 Windows x86-64 Details for fluxwright-0.5.1-cp310-abi3-win_amd64.whl
fluxwright-0.5.1-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.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
fluxwright-0.5.1-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for fluxwright-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
fluxwright-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for fluxwright-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 7.0 MB

Release files / fluxwright-0.5.1.tar.gz

Download URL fluxwright-0.5.1.tar.gz
Size 126.9 kB
Tags Source
SHA-256 checksum
How to use checksums
93ba7c09b377481d13463682efc47f40af6ed64ba28ad15d33672c5e97b926e3
BLAKE2b-256 checksum
How to use checksums
17b2cd5f4c47fcac2c2976837e32ad1f0b678e3069fc24928d30a8a994b189f6
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.1-cp310-abi3-win_amd64.whl

Download URL fluxwright-0.5.1-cp310-abi3-win_amd64.whl
Size 1.8 MB
Tags CPython 3.10 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
95520c110f80de39ac6d04e7a1f40cb33978ade0317129c445d9be9828bac4d5
BLAKE2b-256 checksum
How to use checksums
56a77c461f68e3279407361b7297b9674497c795e878ce225ba89ba77a7a0533
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.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL fluxwright-0.5.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 1.8 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
395dd4970624873f4ad3c6d142cff3e59379e587666e088c45d44e26d94e0d61
BLAKE2b-256 checksum
How to use checksums
ad84f47983771fd78fde8c6fd1fc8ac0aef68edd8eaecfbd42189e0360a06bab
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.1-cp310-abi3-macosx_11_0_arm64.whl

Download URL fluxwright-0.5.1-cp310-abi3-macosx_11_0_arm64.whl
Size 1.6 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
34aefb3623becc459e40dec1c9e9960fd592ef5803d345e8f83f11c639af4d2d
BLAKE2b-256 checksum
How to use checksums
55ad626570a8fb37871c0e6a6f70c0e0927ea8d5776b71c7c59161092f82ea7c
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.1-cp310-abi3-macosx_10_12_x86_64.whl

Download URL fluxwright-0.5.1-cp310-abi3-macosx_10_12_x86_64.whl
Size 1.6 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
1fd0c41ccf57019060efa68bf76442808c129e64520e74628004401eaea70508
BLAKE2b-256 checksum
How to use checksums
7acb79116b4308c802b07c3a297bf78607dc8582129a555ee2d1214f69790c44
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.1

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