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