Metadata-Version: 2.1
Name: chromesession
Version: 0.0.0
Summary: contextmanager for managing `selenium` chrome sessions with caching.
License: MIT
Author: Christoph Dörrer
Author-email: d-chris@web.de
Requires-Python: >=3.9,<4.0
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Provides-Extra: driver
Requires-Dist: chromedriver-py (>=134.0.6998.88,<135.0.0.0) ; extra == "driver"
Requires-Dist: requests-cache (>=1.2.1,<2.0.0)
Requires-Dist: responses (>=0.25.7,<0.26.0)
Requires-Dist: selenium (>=4.29.0,<5.0.0)
Description-Content-Type: text/markdown

# chromesession

`chromesession` is a Python package that provides a convenient contextmanager for managing `selenium` chrome sessions.

In addition, a `CachedSession` is provided to directly cache the driver responses.

## Installation

```cmd
pip install chromesession
```

To use the `chromesession.chrome` contextmanager to use `selenium`, the chromedriver must be installed the system.

Alternatively, you can install the latest `chromedriver` as extra.

[![PyPI - eth-hash](https://img.shields.io/pypi/v/chromedriver-py?logo=pypi&logoColor=white&label=chromedriver-py)](https://pypi.org/project/chromedriver-py/)


```cmd
pip install chromesession[driver]
```

## Examples

Cache the specified URLs by fetching them via Selenium and saving the responses.

```python
import logging

from chromesession import CachedSession, chrome


def caching(*urls: str) -> None:

    with CachedSession("caching.sqlite") as session:
        with chrome() as driver:
            for url in urls:
                if url in session:
                    logging.info(f"{url=} already cached.")
                    continue

                try:
                    driver.get(url)
                    session.save_driver(driver)
                except Exception as e:
                    logging.error(f"{url=} failed to cache: {e}", exc_info=True)
                else:
                    logging.info(f"{url=} from cache.")


if __name__ == "__main__":

    caching("https://example.com/", "https://example.com/")
```

## Dependencies

[![PyPI - requests-cache](https://img.shields.io/pypi/v/requests-cache?logo=pypi&logoColor=white&label=requests-cache)](https://pypi.org/project/requests-cache/)
[![PyPI - responses](https://img.shields.io/pypi/v/responses?logo=pypi&logoColor=white&label=responses)](https://pypi.org/project/responses/)
[![PyPI - selenium](https://img.shields.io/pypi/v/selenium?logo=pypi&logoColor=white&label=selenium)](https://pypi.org/project/selenium/)

---

