Skip to main content

cdipy

Chrome Devtools Interface that instruments Chrome via the devtools protocol.

Meant to serve as a pythonic version of chrome-remote-interface.

Note: cdipy requires CDP flat mode. Always pass flatten=True when calling Target.attachToTarget, otherwise target sessions will not receive messages.

Example Usage

import asyncio
import base64
import logging
import sys

from cdipy import ChromeDevTools
from cdipy import ChromeDevToolsTarget
from cdipy import ChromeRunner


LOGGER = logging.getLogger("cdipy.scripts.screenshot")
FILENAME = "screenshot.png"


async def async_main(url):
    # Start Chrome
    chrome = ChromeRunner()
    await chrome.launch()

    # Connect to devtools websocket
    cdi = ChromeDevTools(chrome.websocket_uri)
    await cdi.connect()

    # Create a new target and attach to it
    target = await cdi.Target.createTarget(url="about:blank")
    session = await cdi.Target.attachToTarget(targetId=target["targetId"], flatten=True)

    # Create a ChromeDevToolsTarget class to handle target messages
    cdit = ChromeDevToolsTarget(cdi, session["sessionId"])

    # Enable 'Page' events
    await cdit.Page.enable()

    # Navigate to URL
    LOGGER.info("Navigating to %s", url)
    await cdit.Page.navigate(url=url)

    # Wait for the Page.loadEventFired event
    # This may not ever fire on some pages, so it's good to set a limit
    try:
        await cdit.wait_for("Page.loadEventFired", 10)
    except asyncio.TimeoutError:
        print("Loaded event never fired!")

    # Take a screenshot
    screenshot_response = await cdit.Page.captureScreenshot(format="png")
    screenshot_bytes = base64.b64decode(screenshot_response["data"])

    with open(FILENAME, "w+b") as fileobj:
        fileobj.write(screenshot_bytes)

    LOGGER.info("wrote %s", FILENAME)

    # Disconnect from devtools; chrome is killed when the runner is collected
    await cdi.close()


def main():
    logging.basicConfig(level=logging.INFO)

    asyncio.run(async_main(sys.argv[1]))


if __name__ == "__main__":
    main()

Skipping Parameter Validation

By default, cdipy validates the parameters you pass to CDP commands against the protocol definition. To skip this validation, set the CDIPY_SKIP_VALIDATION environment variable:

export CDIPY_SKIP_VALIDATION=1

This passes your keyword arguments directly to the protocol without checking them against the command's parameter list. Domains and commands are resolved dynamically by name, so the protocol definition is never downloaded at all. Useful if the cached protocol definition is out of date, or to avoid the download entirely.

Metadata

Release files for cdipy 0.6.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 cdipy 0.6.0
File Size Uploaded Provenance Actions
cdipy-0.6.0.tar.gz 12.3 kB With provenance Details for cdipy-0.6.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cdipy 0.6.0
File Interpreter ABI Platform Actions
cdipy-0.6.0-py3-none-any.whl Python 3 none any Details for cdipy-0.6.0-py3-none-any.whl

Total release size: 24.7 kB

Release files / cdipy-0.6.0.tar.gz

Download URL cdipy-0.6.0.tar.gz
Size 12.3 kB
Tags Source
SHA-256 checksum
How to use checksums
016324459fe95b4db4f5037f3f7e983bf68de1eea6c926177e87659aef7b824d
BLAKE2b-256 checksum
How to use checksums
f3545fbbac0c116ee34fa252bd46c3c06ad71bce32b112ef567c92069163fd5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Release files / cdipy-0.6.0-py3-none-any.whl

Download URL cdipy-0.6.0-py3-none-any.whl
Size 12.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f90d0830af2d54d37437bb06be81c8d3e7d2115fbb19433c3eefaece0fda79e9
BLAKE2b-256 checksum
How to use checksums
48442945a29b0bb9a4ec96de3649293123f462d8fe66029b1a489118f3484a83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

Security for cdipy 0.6.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.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for cdipy-0.6.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.

Transparency log

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