# 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:
1. **Flexibility**: Allow for any use case that the CDP supports.
2. **Minimal external dependencies**: Opt for built-in python libraries where possible.
3. **Clean code**: No hacks, workarounds, or spaghetti code.
## Usage
### Starting Chrome
The following will launch chrome through the command line.
```python
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
```python
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.open_tab("https://www.google.com")
target = chrome.open_tab("https://www.yahoo.com")
target = chrome.open_tab("https://www.github.com/amirdevstudio/aiocdp")
# opens a new tab. The parameter is optional
target = chrome.open_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 `dataclasses` module for classes
- Built-in `typing` module for type hints, enum literals, and other goodies
- Built-in `json` module for JSON serialization
- Built-in `asyncio` module for async functionality
- External `requests` module for HTTP communication
- External `websockets` module for websocket communication
## Internals
### Module Organization
- `aiocdp` - Root package. Contains core and utility modules
- `aiocdp.core` - Core functionality for communicating with the Chrome DevTools Protocol
- `aiocdp.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 target
- `aiocdp.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
1. Update the version in `setup.py` and / or `pyproject.toml`
2. Run `python -m pip install build twine`
3. Run `python -m build`
4. Run `twine check dist/*`
5. Run `twine upload dist/aiocdp-<MAJOR>.<MINOR>.<PATCH>*`
Raw data
{
"_id": null,
"home_page": "",
"name": "aiocdp",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": "",
"keywords": "cdp,chrome devtools protocol,chrome,devtools,browser,automation",
"author": "",
"author_email": "Amir Sharapov <amirsharapov.personal@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/03/eb/dc0240aadd65213372d040184d03dd7fccaf5c5e4dc433807cba31df0df8/aiocdp-1.1.7.tar.gz",
"platform": null,
"description": "# AIOCDP\r\n\r\nThis library provides an async wrapper around the Chrome DevTools Protocol.\r\n\r\n## About\r\n\r\nTo be the underlying engine for any projects using Chrome DevTools Protocol. This library should embody the following:\r\n\r\n1. **Flexibility**: Allow for any use case that the CDP supports.\r\n2. **Minimal external dependencies**: Opt for built-in python libraries where possible.\r\n3. **Clean code**: No hacks, workarounds, or spaghetti code.\r\n\r\n## Usage\r\n\r\n### Starting Chrome\r\n\r\nThe following will launch chrome through the command line.\r\n\r\n```python\r\nimport asyncio\r\n\r\nfrom aiocdp import Chrome\r\n\r\n\r\nasync def setup_chrome():\r\n chrome = Chrome.init(\r\n host=\"localhost\",\r\n port=9222,\r\n )\r\n \r\n chrome.start()\r\n \r\n # run your logic here\r\n \r\n\r\nif __name__ == \"__main__\":\r\n asyncio.run(setup_chrome())\r\n```\r\n\r\n_**NOTE:** If you had chrome open previously, you may run into connection issues.\r\nIf this is the case, close your tabs, run the script to relaunch chrome, and then reopen your tabs._\r\n\r\n### Opening a tab\r\n\r\n```python\r\nimport asyncio\r\n\r\nfrom aiocdp import Chrome\r\n\r\nasync def setup_tabs():\r\n chrome = Chrome.init(\r\n host=\"localhost\",\r\n port=9222,\r\n )\r\n \r\n chrome.start()\r\n\r\n # opens a new tab. Return aiocdp.ITarget instance.\r\n target = chrome.open_tab(\"https://www.google.com\")\r\n target = chrome.open_tab(\"https://www.yahoo.com\")\r\n target = chrome.open_tab(\"https://www.github.com/amirdevstudio/aiocdp\")\r\n \r\n # opens a new tab. The parameter is optional\r\n target = chrome.open_tab()\r\n \r\n\r\nif __name__ == \"__main__\":\r\n asyncio.run(setup_tabs())\r\n```\r\n\r\n## Package\r\n\r\nYou can find the AIOCDP package published to pypi.org/project/aiocdp\r\n\r\n# For Developers\r\n\r\n## Scope\r\n\r\nThis library is built to be \"one and done\" except for performance optimizations or design changes.\r\nThis library should limit the dependencies it has on the CDP unless it's a core feature (opening sessions, etc.).\r\n\r\n## Dependencies\r\n\r\n- Built-in `dataclasses` module for classes\r\n- Built-in `typing` module for type hints, enum literals, and other goodies\r\n- Built-in `json` module for JSON serialization\r\n- Built-in `asyncio` module for async functionality\r\n- External `requests` module for HTTP communication\r\n- External `websockets` module for websocket communication\r\n## Internals\r\n\r\n### Module Organization\r\n\r\n- `aiocdp` - Root package. Contains core and utility modules\r\n- `aiocdp.core` - Core functionality for communicating with the Chrome DevTools Protocol\r\n- `aiocdp.core.chrome.Chrome` -> Represents the Chrome instance / process.\r\n- `aiocdp.core.target.Target` -> Represents a chrome devtools protocol target (Page, Frame, Worker, etc)\r\n- `aiocdp.core.connection.Connection` -> Represents a websocket connection to a target\r\n- `aiocdp.core.session.TargetSession` -> Represents a session to a specific target.\r\n- `aiocdp.core.stream.EventStream` -> Represents a stream of events from a connection.\r\n- `aiocdp.core.stream.EventStreamReader` -> Readonly reader to an event stream.\r\n\r\n## TODO:\r\n\r\n- Setup proper typehints for setting subclasses. (use a type var in a shared module)\r\n- documentation\r\n\r\n## Publishing to PyPi\r\n\r\n1. Update the version in `setup.py` and / or `pyproject.toml`\r\n2. Run `python -m pip install build twine`\r\n3. Run `python -m build`\r\n4. Run `twine check dist/*`\r\n5. Run `twine upload dist/aiocdp-<MAJOR>.<MINOR>.<PATCH>*`\r\n",
"bugtrack_url": null,
"license": "",
"summary": "High performance, asynchronous python module for programatic access to Chrome DevTools Protocol.",
"version": "1.1.7",
"project_urls": {
"Homepage": "https://github.com/amirdevstudio/aiocdp"
},
"split_keywords": [
"cdp",
"chrome devtools protocol",
"chrome",
"devtools",
"browser",
"automation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "44de5642c6bc07a097fdce881bf06a456541884e29522d2ecb14ead37ae07752",
"md5": "4235e0d851cb2cc76a42755832785d26",
"sha256": "a5b110dd0958db6a2d6346cf2f7a42f8e30680dade2fa2a19f00fafef113d630"
},
"downloads": -1,
"filename": "aiocdp-1.1.7-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4235e0d851cb2cc76a42755832785d26",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 17757,
"upload_time": "2024-02-10T19:53:51",
"upload_time_iso_8601": "2024-02-10T19:53:51.315743Z",
"url": "https://files.pythonhosted.org/packages/44/de/5642c6bc07a097fdce881bf06a456541884e29522d2ecb14ead37ae07752/aiocdp-1.1.7-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "03ebdc0240aadd65213372d040184d03dd7fccaf5c5e4dc433807cba31df0df8",
"md5": "3a49b7377db4bcdcc5c27f5ad8347430",
"sha256": "9fe780924e49f0d257402680b56523c48e75ff9b0514bf3a5d619c7bdaf8de8b"
},
"downloads": -1,
"filename": "aiocdp-1.1.7.tar.gz",
"has_sig": false,
"md5_digest": "3a49b7377db4bcdcc5c27f5ad8347430",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 12878,
"upload_time": "2024-02-10T19:53:52",
"upload_time_iso_8601": "2024-02-10T19:53:52.783203Z",
"url": "https://files.pythonhosted.org/packages/03/eb/dc0240aadd65213372d040184d03dd7fccaf5c5e4dc433807cba31df0df8/aiocdp-1.1.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-02-10 19:53:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "amirdevstudio",
"github_project": "aiocdp",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "requests",
"specs": [
[
"~=",
"2.31.0"
]
]
},
{
"name": "websockets",
"specs": [
[
"~=",
"12.0"
]
]
},
{
"name": "setuptools",
"specs": [
[
"~=",
"68.2.0"
]
]
}
],
"lcname": "aiocdp"
}