AIOCDP
This library provides an async wrapper around the Chrome DevTools Protocol.
About
To be the underlying engine for any projects using Chrome DevTools Protocol. This library should embody the following:
- Flexibility: Allow for any use case that the CDP supports.
- Minimal external dependencies: Opt for built-in python libraries where possible.
- Clean code: No hacks, workarounds, or spaghetti code.
Usage
Starting Chrome
The following will launch chrome through the command line.
import asyncio
from aiocdp import Chrome
async def setup_chrome():
chrome = Chrome.init(
host="localhost",
port=9222,
)
chrome.start()
# run your logic here
if __name__ == "__main__":
asyncio.run(setup_chrome())
NOTE: If you had chrome open previously, you may run into connection issues. If this is the case, close your tabs, run the script to relaunch chrome, and then reopen your tabs.
Opening a tab
import asyncio
from aiocdp import Chrome
async def setup_tabs():
chrome = Chrome.init(
host="localhost",
port=9222,
)
chrome.start()
# opens a new tab. Return aiocdp.ITarget instance.
target = chrome.new_tab("https://www.google.com")
target = chrome.new_tab("https://www.yahoo.com")
target = chrome.new_tab("https://www.github.com/amirdevstudio/aiocdp")
# opens a new tab. The parameter is optional
target = chrome.new_tab()
if __name__ == "__main__":
asyncio.run(setup_tabs())
Package
You can find the AIOCDP package published to pypi.org/project/aiocdp
For Developers
Scope
This library is built to be "one and done" except for performance optimizations or design changes. This library should limit the dependencies it has on the CDP unless it's a core feature (opening sessions, etc.).
Dependencies
- Built-in
dataclassesmodule for classes - Built-in
typingmodule for type hints, enum literals, and other goodies - Built-in
jsonmodule for JSON serialization - Built-in
asynciomodule for async functionality - External
requestsmodule for HTTP communication - External
websocketsmodule for websocket communication
Internals
Module Organization
aiocdp- Root package. Contains core and utility modulesaiocdp.core- Core functionality for communicating with the Chrome DevTools Protocolaiocdp.core.chrome.Chrome-> Represents the Chrome instance / process.aiocdp.core.target.Target-> Represents a chrome devtools protocol target (Page, Frame, Worker, etc)aiocdp.core.connection.Connection-> Represents a websocket connection to a targetaiocdp.core.session.TargetSession-> Represents a session to a specific target.aiocdp.core.stream.EventStream-> Represents a stream of events from a connection.aiocdp.core.stream.EventStreamReader-> Readonly reader to an event stream.
TODO:
- Setup proper typehints for setting subclasses. (use a type var in a shared module)
- documentation
Publishing to PyPi
- Update the version in
pyproject.toml - Run
python -m pip install build twine - Run
python -m build - Run
twine check dist/* - Run
twine upload dist/aiocdp-<MAJOR>.<MINOR>.<PATCH>*
Release files for aiocdp 1.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiocdp-1.1.8.tar.gz | 12.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiocdp-1.1.8-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.4 kB
Release files / aiocdp-1.1.8.tar.gz
| Download URL | aiocdp-1.1.8.tar.gz |
|---|---|
| Size | 12.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91cf0277c2797e909b4c24c8e7d7783cd7f17291ba2342905eb9633f75bcbbf7
|
|
BLAKE2b-256 checksum How to use checksums |
19a31dea2bf259d732906d2461d4a9d9905352893e41737a18efcbfc2745bfe0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|
Release files / aiocdp-1.1.8-py3-none-any.whl
| Download URL | aiocdp-1.1.8-py3-none-any.whl |
|---|---|
| Size | 17.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
10d337ee2080e097e72b13b7c25f6c157fcc313e8458174ff7483ba24733ed68
|
|
BLAKE2b-256 checksum How to use checksums |
3f4ec98db90fc7618e9dc40dd187307070ca7420f1cf48e4ced637975d97028a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.12.6
|