headless-driver 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Nuhman Pk
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: headless-driver
3
+ Version: 0.0.1
4
+ Summary: A simple Python package for managing Selenium Chrome drivers in headless mode.
5
+ Author-email: nuhmanpk <nuhmanpk7@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Nuhman Pk
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/nuhmanpk/headless-driver
29
+ Requires-Python: >=3.7
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: selenium>=4.0.0
33
+ Dynamic: license-file
34
+
35
+ [![PyPI version](https://badge.fury.io/py/headless-driver.svg)](https://badge.fury.io/py/headless-driver)
36
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
37
+ [![Build Status](https://github.com/nuhmanpk/headless-driver/actions/workflows/python-package.yml/badge.svg)](https://github.com/nuhmanpk/headless-driver/actions)
38
+
39
+ # headless-driver
40
+
41
+ A simple Python package for managing Selenium Chrome drivers in headless mode.
42
+
43
+ ## Features
44
+ - Headless Chrome driver management
45
+ - Temporary user data directory
46
+ - Custom window size and user agent
47
+ - Easy cleanup and context manager support
48
+ - Remote and local driver support
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ pip install headless-driver
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ ```python
59
+ from headless import Headless
60
+
61
+ hl = Headless()
62
+ driver = hl.get_driver()
63
+ driver.get("https://example.com")
64
+ print(driver.title)
65
+ hl.quit()
66
+ ```
67
+
68
+ Or use as a context manager:
69
+
70
+ ```python
71
+ from headless import Headless
72
+
73
+ with Headless() as driver:
74
+ driver.get("https://example.com")
75
+ print(driver.title)
76
+ ```
77
+
78
+ ## API Documentation
79
+
80
+ ### Headless class
81
+
82
+ ```python
83
+ Headless(
84
+ user_data_dir: Optional[str] = None,
85
+ window_size: Tuple[int, int] = (1920, 1080),
86
+ user_agent: Optional[str] = None,
87
+ headless: bool = True,
88
+ chrome_driver_path: Optional[str] = '/opt/homebrew/bin/chromedriver',
89
+ additional_args: Optional[List[str]] = None,
90
+ remote_url: Optional[str] = None,
91
+ )
92
+ ```
93
+
94
+ - `user_data_dir`: Path for Chrome user data (temporary if not provided)
95
+ - `window_size`: Browser window size (default: 1920x1080)
96
+ - `user_agent`: Custom user agent string
97
+ - `headless`: Run Chrome in headless mode (default: True)
98
+ - `chrome_driver_path`: Path to chromedriver executable
99
+ - `additional_args`: List of extra Chrome arguments
100
+ - `remote_url`: Use remote Selenium server if provided
101
+
102
+ ### Methods
103
+ - `get_driver()`: Returns a Selenium WebDriver instance
104
+ - `quit()`: Quits the driver and cleans up user data
105
+
106
+ ## Running Tests
107
+
108
+ ```bash
109
+ python -m unittest discover tests
110
+ ```
111
+
112
+ ## License
113
+ MIT
@@ -0,0 +1,79 @@
1
+ [![PyPI version](https://badge.fury.io/py/headless-driver.svg)](https://badge.fury.io/py/headless-driver)
2
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
3
+ [![Build Status](https://github.com/nuhmanpk/headless-driver/actions/workflows/python-package.yml/badge.svg)](https://github.com/nuhmanpk/headless-driver/actions)
4
+
5
+ # headless-driver
6
+
7
+ A simple Python package for managing Selenium Chrome drivers in headless mode.
8
+
9
+ ## Features
10
+ - Headless Chrome driver management
11
+ - Temporary user data directory
12
+ - Custom window size and user agent
13
+ - Easy cleanup and context manager support
14
+ - Remote and local driver support
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ pip install headless-driver
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ ```python
25
+ from headless import Headless
26
+
27
+ hl = Headless()
28
+ driver = hl.get_driver()
29
+ driver.get("https://example.com")
30
+ print(driver.title)
31
+ hl.quit()
32
+ ```
33
+
34
+ Or use as a context manager:
35
+
36
+ ```python
37
+ from headless import Headless
38
+
39
+ with Headless() as driver:
40
+ driver.get("https://example.com")
41
+ print(driver.title)
42
+ ```
43
+
44
+ ## API Documentation
45
+
46
+ ### Headless class
47
+
48
+ ```python
49
+ Headless(
50
+ user_data_dir: Optional[str] = None,
51
+ window_size: Tuple[int, int] = (1920, 1080),
52
+ user_agent: Optional[str] = None,
53
+ headless: bool = True,
54
+ chrome_driver_path: Optional[str] = '/opt/homebrew/bin/chromedriver',
55
+ additional_args: Optional[List[str]] = None,
56
+ remote_url: Optional[str] = None,
57
+ )
58
+ ```
59
+
60
+ - `user_data_dir`: Path for Chrome user data (temporary if not provided)
61
+ - `window_size`: Browser window size (default: 1920x1080)
62
+ - `user_agent`: Custom user agent string
63
+ - `headless`: Run Chrome in headless mode (default: True)
64
+ - `chrome_driver_path`: Path to chromedriver executable
65
+ - `additional_args`: List of extra Chrome arguments
66
+ - `remote_url`: Use remote Selenium server if provided
67
+
68
+ ### Methods
69
+ - `get_driver()`: Returns a Selenium WebDriver instance
70
+ - `quit()`: Quits the driver and cleans up user data
71
+
72
+ ## Running Tests
73
+
74
+ ```bash
75
+ python -m unittest discover tests
76
+ ```
77
+
78
+ ## License
79
+ MIT
@@ -0,0 +1 @@
1
+ # headless package init
@@ -0,0 +1,98 @@
1
+ import os
2
+ import uuid
3
+ import shutil
4
+ import tempfile
5
+ from typing import List, Optional, Tuple
6
+
7
+ from selenium import webdriver
8
+ from selenium.webdriver.chrome.options import Options
9
+ from selenium.webdriver.chrome.service import Service
10
+ from selenium.webdriver.remote.webdriver import WebDriver
11
+
12
+ class Headless:
13
+ def __init__(
14
+ self,
15
+ user_data_dir: Optional[str] = None,
16
+ window_size: Tuple[int, int] = (1920, 1080),
17
+ user_agent: Optional[str] = None,
18
+ headless: bool = True,
19
+ chrome_driver_path: Optional[str] = '/opt/homebrew/bin/chromedriver',
20
+ additional_args: Optional[List[str]] = None,
21
+ remote_url: Optional[str] = None,
22
+ ):
23
+ self.id = uuid.uuid4().hex
24
+ if user_data_dir:
25
+ self.user_data_dir = user_data_dir
26
+ self._cleanup_dir = False
27
+ else:
28
+ prefix = f"chrome-user-data-{self.id}-"
29
+ self.user_data_dir = tempfile.mkdtemp(prefix=prefix)
30
+ self._cleanup_dir = True
31
+
32
+ self.window_size = window_size
33
+ self.user_agent = (
34
+ user_agent
35
+ or "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
36
+ "(KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
37
+ )
38
+ self.headless = headless
39
+ self.additional_args = additional_args or []
40
+ self.chrome_driver_path = chrome_driver_path
41
+ self.remote_url = remote_url
42
+ self._driver: Optional[WebDriver] = None
43
+
44
+ def _build_options(self) -> Options:
45
+ opts = Options()
46
+ opts.add_argument(f"--user-data-dir={self.user_data_dir}")
47
+ if self.headless:
48
+ opts.add_argument("--headless=new")
49
+ opts.add_argument(f"--window-size={self.window_size[0]},{self.window_size[1]}")
50
+ opts.add_argument("--disable-gpu")
51
+ opts.add_argument("--no-sandbox")
52
+ opts.add_argument("--disable-dev-shm-usage")
53
+ opts.add_argument(f"user-agent={self.user_agent}")
54
+ for arg in self.additional_args:
55
+ opts.add_argument(arg)
56
+ return opts
57
+
58
+ def get_driver(self) -> WebDriver:
59
+ if self._driver:
60
+ return self._driver
61
+
62
+ opts = self._build_options()
63
+
64
+ if self.remote_url:
65
+ self._driver = webdriver.Remote(
66
+ command_executor=self.remote_url,
67
+ options=opts
68
+ )
69
+ else:
70
+ if self.chrome_driver_path:
71
+ service = Service(executable_path=self.chrome_driver_path)
72
+ self._driver = webdriver.Chrome(
73
+ service=service,
74
+ options=opts
75
+ )
76
+ else:
77
+ self._driver = webdriver.Chrome(
78
+ options=opts
79
+ )
80
+
81
+ return self._driver
82
+
83
+ def quit(self) -> None:
84
+ if self._driver:
85
+ try:
86
+ self._driver.quit()
87
+ except Exception:
88
+ pass
89
+ self._driver = None
90
+
91
+ if self._cleanup_dir and os.path.isdir(self.user_data_dir):
92
+ shutil.rmtree(self.user_data_dir, ignore_errors=True)
93
+
94
+ def __enter__(self) -> WebDriver:
95
+ return self.get_driver()
96
+
97
+ def __exit__(self) -> None:
98
+ self.quit()
@@ -0,0 +1,113 @@
1
+ Metadata-Version: 2.4
2
+ Name: headless-driver
3
+ Version: 0.0.1
4
+ Summary: A simple Python package for managing Selenium Chrome drivers in headless mode.
5
+ Author-email: nuhmanpk <nuhmanpk7@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Nuhman Pk
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/nuhmanpk/headless-driver
29
+ Requires-Python: >=3.7
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: selenium>=4.0.0
33
+ Dynamic: license-file
34
+
35
+ [![PyPI version](https://badge.fury.io/py/headless-driver.svg)](https://badge.fury.io/py/headless-driver)
36
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
37
+ [![Build Status](https://github.com/nuhmanpk/headless-driver/actions/workflows/python-package.yml/badge.svg)](https://github.com/nuhmanpk/headless-driver/actions)
38
+
39
+ # headless-driver
40
+
41
+ A simple Python package for managing Selenium Chrome drivers in headless mode.
42
+
43
+ ## Features
44
+ - Headless Chrome driver management
45
+ - Temporary user data directory
46
+ - Custom window size and user agent
47
+ - Easy cleanup and context manager support
48
+ - Remote and local driver support
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ pip install headless-driver
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ ```python
59
+ from headless import Headless
60
+
61
+ hl = Headless()
62
+ driver = hl.get_driver()
63
+ driver.get("https://example.com")
64
+ print(driver.title)
65
+ hl.quit()
66
+ ```
67
+
68
+ Or use as a context manager:
69
+
70
+ ```python
71
+ from headless import Headless
72
+
73
+ with Headless() as driver:
74
+ driver.get("https://example.com")
75
+ print(driver.title)
76
+ ```
77
+
78
+ ## API Documentation
79
+
80
+ ### Headless class
81
+
82
+ ```python
83
+ Headless(
84
+ user_data_dir: Optional[str] = None,
85
+ window_size: Tuple[int, int] = (1920, 1080),
86
+ user_agent: Optional[str] = None,
87
+ headless: bool = True,
88
+ chrome_driver_path: Optional[str] = '/opt/homebrew/bin/chromedriver',
89
+ additional_args: Optional[List[str]] = None,
90
+ remote_url: Optional[str] = None,
91
+ )
92
+ ```
93
+
94
+ - `user_data_dir`: Path for Chrome user data (temporary if not provided)
95
+ - `window_size`: Browser window size (default: 1920x1080)
96
+ - `user_agent`: Custom user agent string
97
+ - `headless`: Run Chrome in headless mode (default: True)
98
+ - `chrome_driver_path`: Path to chromedriver executable
99
+ - `additional_args`: List of extra Chrome arguments
100
+ - `remote_url`: Use remote Selenium server if provided
101
+
102
+ ### Methods
103
+ - `get_driver()`: Returns a Selenium WebDriver instance
104
+ - `quit()`: Quits the driver and cleans up user data
105
+
106
+ ## Running Tests
107
+
108
+ ```bash
109
+ python -m unittest discover tests
110
+ ```
111
+
112
+ ## License
113
+ MIT
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ headless/__init__.py
5
+ headless/core.py
6
+ headless_driver.egg-info/PKG-INFO
7
+ headless_driver.egg-info/SOURCES.txt
8
+ headless_driver.egg-info/dependency_links.txt
9
+ headless_driver.egg-info/requires.txt
10
+ headless_driver.egg-info/top_level.txt
11
+ tests/test_core.py
@@ -0,0 +1 @@
1
+ selenium>=4.0.0
@@ -0,0 +1,20 @@
1
+ [build-system]
2
+ requires = ["setuptools>=42", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "headless-driver"
7
+ version = "0.0.1"
8
+ description = "A simple Python package for managing Selenium Chrome drivers in headless mode."
9
+ authors = [
10
+ { name="nuhmanpk", email="nuhmanpk7@gmail.com" }
11
+ ]
12
+ license = { file = "LICENSE" }
13
+ readme = "README.md"
14
+ requires-python = ">=3.7"
15
+ dependencies = [
16
+ "selenium>=4.0.0"
17
+ ]
18
+
19
+ [project.urls]
20
+ Homepage = "https://github.com/nuhmanpk/headless-driver"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,13 @@
1
+ import unittest
2
+ from headless.core import Headless
3
+
4
+ class TestHeadless(unittest.TestCase):
5
+ def test_driver_creation_and_quit(self):
6
+ hl = Headless(headless=True)
7
+ driver = hl.get_driver()
8
+ self.assertIsNotNone(driver)
9
+ hl.quit()
10
+ self.assertIsNone(hl._driver)
11
+
12
+ if __name__ == "__main__":
13
+ unittest.main()