camoufox 0.2.6__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,343 @@
1
+ Metadata-Version: 2.1
2
+ Name: camoufox
3
+ Version: 0.2.6
4
+ Summary: Wrapper around Playwright to help launch Camoufox
5
+ Home-page: https://github.com/daijro/camoufox
6
+ License: MIT
7
+ Keywords: client,fingerprint,browser,scraping,injector,firefox,playwright
8
+ Author: daijro
9
+ Author-email: daijro.dev@gmail.com
10
+ Requires-Python: >=3.8,<4.0
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3.8
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Topic :: Internet :: WWW/HTTP
19
+ Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
20
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
21
+ Provides-Extra: geoip
22
+ Requires-Dist: browserforge
23
+ Requires-Dist: click
24
+ Requires-Dist: geoip2 ; extra == "geoip"
25
+ Requires-Dist: language-tags
26
+ Requires-Dist: lxml
27
+ Requires-Dist: numpy
28
+ Requires-Dist: orjson
29
+ Requires-Dist: platformdirs
30
+ Requires-Dist: playwright
31
+ Requires-Dist: pyyaml
32
+ Requires-Dist: requests
33
+ Requires-Dist: screeninfo
34
+ Requires-Dist: tqdm
35
+ Requires-Dist: typing_extensions
36
+ Requires-Dist: ua_parser
37
+ Project-URL: Repository, https://github.com/daijro/camoufox
38
+ Description-Content-Type: text/markdown
39
+
40
+ <div align="center">
41
+
42
+ # Camoufox Python Interface
43
+
44
+ #### Lightweight wrapper around the Playwright API to help launch Camoufox.
45
+
46
+ </div>
47
+
48
+ ---
49
+
50
+ ## Installation
51
+
52
+ First, install the `camoufox` package:
53
+
54
+ ```bash
55
+ pip install -U camoufox[geoip]
56
+ ```
57
+
58
+ The `geoip` parameter is optional, but heavily recommended if you are using proxies. It will download an extra dataset to determine the user's longitude, latitude, timezone, country, & locale.
59
+
60
+ Next, download the Camoufox browser:
61
+
62
+ **Windows**
63
+
64
+ ```bash
65
+ camoufox fetch
66
+ ```
67
+
68
+ **MacOS & Linux**
69
+
70
+ ```bash
71
+ python3 -m camoufox fetch
72
+ ```
73
+
74
+ To uninstall, run `camoufox remove`.
75
+
76
+ <details>
77
+ <summary>CLI options</summary>
78
+
79
+ ```
80
+ Usage: python -m camoufox [OPTIONS] COMMAND [ARGS]...
81
+
82
+ Options:
83
+ --help Show this message and exit.
84
+
85
+ Commands:
86
+ fetch Fetch the latest version of Camoufox
87
+ path Display the path to the Camoufox executable
88
+ remove Remove all downloaded files
89
+ server Launch a Playwright server
90
+ test Open the Playwright inspector
91
+ version Display the current version
92
+ ```
93
+
94
+ </details>
95
+
96
+ <hr width=50>
97
+
98
+ ## Usage
99
+
100
+ Camoufox is fully compatible with your existing Playwright code. You only have to change your browser initialization:
101
+
102
+ #### Sync API
103
+
104
+ ```python
105
+ from camoufox.sync_api import Camoufox
106
+
107
+ with Camoufox(headless=False) as browser:
108
+ page = browser.new_page()
109
+ page.goto("https://example.com/")
110
+ ```
111
+
112
+ #### Async API
113
+
114
+ ```python
115
+ from camoufox.async_api import AsyncCamoufox
116
+
117
+ async with AsyncCamoufox(headless=False) as browser:
118
+ page = await browser.new_page()
119
+ await page.goto("https://example.com")
120
+ ```
121
+
122
+ <details>
123
+ <summary>Parameters</summary>
124
+
125
+ ```
126
+ Launches a new browser instance for Camoufox.
127
+ Accepts all Playwright Firefox launch options, along with the following:
128
+
129
+ Parameters:
130
+ config (Optional[Dict[str, Any]]):
131
+ Camoufox properties to use.
132
+ os (Optional[ListOrString]):
133
+ Operating system to use for the fingerprint generation.
134
+ Can be "windows", "macos", "linux", or a list to randomly choose from.
135
+ Default: ["windows", "macos", "linux"]
136
+ block_images (Optional[bool]):
137
+ Whether to block all images.
138
+ block_webrtc (Optional[bool]):
139
+ Whether to block WebRTC entirely.
140
+ allow_webgl (Optional[bool]):
141
+ Whether to allow WebGL. To prevent leaks, only use this for special cases.
142
+ geoip (Optional[Union[str, bool]]):
143
+ Calculate longitude, latitude, timezone, country, & locale based on the IP address.
144
+ Pass the target IP address to use, or `True` to find the IP address automatically.
145
+ humanize (Optional[Union[bool, float]]):
146
+ Humanize the cursor movement.
147
+ Takes either `True`, or the MAX duration in seconds of the cursor movement.
148
+ The cursor typically takes up to 1.5 seconds to move across the window.
149
+ locale (Optional[str]):
150
+ Locale to use in Camoufox.
151
+ addons (Optional[List[str]]):
152
+ List of Firefox addons to use.
153
+ fonts (Optional[List[str]]):
154
+ Fonts to load into Camoufox (in addition to the default fonts for the target `os`).
155
+ Takes a list of font family names that are installed on the system.
156
+ exclude_addons (Optional[List[DefaultAddons]]):
157
+ Default addons to exclude. Passed as a list of camoufox.DefaultAddons enums.
158
+ screen (Optional[Screen]):
159
+ Constrains the screen dimensions of the generated fingerprint.
160
+ Takes a browserforge.fingerprints.Screen instance.
161
+ fingerprint (Optional[Fingerprint]):
162
+ Use a custom BrowserForge fingerprint. Note: Not all values will be implemented.
163
+ If not provided, a random fingerprint will be generated based on the provided
164
+ `os` & `screen` constraints.
165
+ ff_version (Optional[int]):
166
+ Firefox version to use. Defaults to the current Camoufox version.
167
+ To prevent leaks, only use this for special cases.
168
+ headless (Optional[bool]):
169
+ Whether to run the browser in headless mode. Defaults to True.
170
+ executable_path (Optional[str]):
171
+ Custom Camoufox browser executable path.
172
+ firefox_user_prefs (Optional[Dict[str, Any]]):
173
+ Firefox user preferences to set.
174
+ proxy (Optional[Dict[str, str]]):
175
+ Proxy to use for the browser.
176
+ Note: If geoip is True, a request will be sent through this proxy to find the target IP.
177
+ args (Optional[List[str]]):
178
+ Arguments to pass to the browser.
179
+ env (Optional[Dict[str, Union[str, float, bool]]]):
180
+ Environment variables to set.
181
+ persistent_context (Optional[bool]):
182
+ Whether to use a persistent context.
183
+ debug (Optional[bool]):
184
+ Prints the config being sent to Camoufox.
185
+ **launch_options (Dict[str, Any]):
186
+ Additional Firefox launch options.
187
+ ```
188
+
189
+ </details>
190
+
191
+ ---
192
+
193
+ ### Config
194
+
195
+ Camoufox [config data](https://github.com/daijro/camoufox?tab=readme-ov-file#fingerprint-injection) can be passed as a dictionary to the `config` parameter:
196
+
197
+ ```python
198
+ from camoufox.sync_api import Camoufox
199
+
200
+ with Camoufox(
201
+ config={
202
+ 'webrtc:ipv4': '123.45.67.89',
203
+ 'webrtc:ipv6': 'e791:d37a:88f6:48d1:2cad:2667:4582:1d6d',
204
+ }
205
+ ) as browser:
206
+ page = browser.new_page()
207
+ page.goto("https://www.browserscan.net/webrtc")
208
+ ```
209
+
210
+ <hr width=50>
211
+
212
+ ### GeoIP & Proxy Support
213
+
214
+ By passing `geoip=True`, or passing in a target IP address, Camoufox will automatically use the target IP's longitude, latitude, timezone, country, locale, & spoof the WebRTC IP address.
215
+
216
+ It will also calculate and spoof the browser's language based on the distribution of language speakers in the target region.
217
+
218
+ #### Installation
219
+
220
+ Install Camoufox with the `geoip` extra:
221
+
222
+ ```bash
223
+ pip install -U camoufox[geoip]
224
+ ```
225
+
226
+ #### Usage
227
+
228
+ Pass in the proxy dictionary as you would with Playwright's `proxy` parameter:
229
+
230
+ ```python
231
+ with Camoufox(
232
+ geoip=True,
233
+ proxy={
234
+ 'server': 'http://example.com:8080',
235
+ 'username': 'username',
236
+ 'password': 'password'
237
+ }
238
+ ) as browser:
239
+ page = browser.new_page()
240
+ page.goto("https://www.browserscan.net")
241
+ ```
242
+
243
+ <hr width=50>
244
+
245
+ ### Remote Server (experimental)
246
+
247
+ > [!WARNING]
248
+ > This feature is experimental and not meant for production use. It uses a hacky workaround to gain access to undocumented Playwright methods.
249
+
250
+ #### Launching
251
+
252
+ To launch a remote server, run the following CLI command:
253
+
254
+ ```bash
255
+ python -m camoufox server
256
+ ```
257
+
258
+ Or, configure the server with a launch script:
259
+
260
+ ```python
261
+ from camoufox.server import launch_server
262
+
263
+ launch_server(
264
+ headless=True,
265
+ geoip=True,
266
+ proxy={
267
+ 'server': 'http://example.com:8080',
268
+ 'username': 'username',
269
+ 'password': 'password'
270
+ }
271
+ )
272
+ ```
273
+
274
+ #### Connecting
275
+
276
+ To connect to the remote server, use Playwright's `connect` method:
277
+
278
+ ```python
279
+ from playwright.sync_api import sync_playwright
280
+
281
+ with sync_playwright() as p:
282
+ # Example endpoint
283
+ browser = p.firefox.connect('ws://localhost:34091/8c7c6cdea3368d937ef7db2277d6647b')
284
+ page = browser.new_page()
285
+ ...
286
+ ```
287
+
288
+ **Note:** Because servers only use **one browser instance**, fingerprints will not rotate between sessions. If you plan on using Camoufox at scale, consider rotating the server between sessions.
289
+
290
+ <hr width=50>
291
+
292
+ ### BrowserForge Integration
293
+
294
+ Camoufox is compatible with [BrowserForge](https://github.com/daijro/browserforge) fingerprints.
295
+
296
+ By default, Camoufox will generate an use a random BrowserForge fingerprint based on the target `os` & `screen` constraints.
297
+
298
+ ```python
299
+ from camoufox.sync_api import Camoufox
300
+ from browserforge.fingerprints import Screen
301
+
302
+ with Camoufox(
303
+ os=('windows', 'macos', 'linux'),
304
+ screen=Screen(max_width=1920, max_height=1080),
305
+ ) as browser:
306
+ page = browser.new_page()
307
+ page.goto("https://example.com/")
308
+ ```
309
+
310
+ **Notes:**
311
+
312
+ - If Camoufox is being ran in headful mode, the max screen size will be generated based on your monitor's dimensions (+15%).
313
+
314
+ - To prevent UA-spoofing leaks, Camoufox only generates fingerprints with the same browser version as the current Camoufox version by default.
315
+
316
+ - If rotating the Firefox version is absolutely necessary, it would be more advisable to rotate between older versions of Camoufox instead.
317
+
318
+ <details>
319
+ <summary>Injecting custom Fingerprint objects...</summary>
320
+
321
+ > [!WARNING]
322
+ > It is recommended to pass `os` & `screen` constraints into Camoufox instead. Camoufox will handle fingerprint generation for you. This will be deprecated in the future.
323
+
324
+ You can also inject your own Firefox BrowserForge fingerprint into Camoufox.
325
+
326
+ ```python
327
+ from camoufox.sync_api import Camoufox
328
+ from browserforge.fingerprints import FingerprintGenerator
329
+
330
+ fg = FingerprintGenerator(browser='firefox')
331
+
332
+ # Launch Camoufox with a random Firefox fingerprint
333
+ with Camoufox(fingerprint=fg.generate()) as browser:
334
+ page = browser.new_page()
335
+ page.goto("https://example.com/")
336
+ ```
337
+
338
+ **Note:** As of now, some properties from BrowserForge fingerprints will not be passed to Camoufox. This is due to the outdated fingerprint dataset from Apify's fingerprint-suite (see [here](https://github.com/apify/fingerprint-suite/discussions/308)). Properties will be re-enabled as soon as an updated dataset is available.
339
+
340
+ </details>
341
+
342
+ ---
343
+
@@ -0,0 +1,303 @@
1
+ <div align="center">
2
+
3
+ # Camoufox Python Interface
4
+
5
+ #### Lightweight wrapper around the Playwright API to help launch Camoufox.
6
+
7
+ </div>
8
+
9
+ ---
10
+
11
+ ## Installation
12
+
13
+ First, install the `camoufox` package:
14
+
15
+ ```bash
16
+ pip install -U camoufox[geoip]
17
+ ```
18
+
19
+ The `geoip` parameter is optional, but heavily recommended if you are using proxies. It will download an extra dataset to determine the user's longitude, latitude, timezone, country, & locale.
20
+
21
+ Next, download the Camoufox browser:
22
+
23
+ **Windows**
24
+
25
+ ```bash
26
+ camoufox fetch
27
+ ```
28
+
29
+ **MacOS & Linux**
30
+
31
+ ```bash
32
+ python3 -m camoufox fetch
33
+ ```
34
+
35
+ To uninstall, run `camoufox remove`.
36
+
37
+ <details>
38
+ <summary>CLI options</summary>
39
+
40
+ ```
41
+ Usage: python -m camoufox [OPTIONS] COMMAND [ARGS]...
42
+
43
+ Options:
44
+ --help Show this message and exit.
45
+
46
+ Commands:
47
+ fetch Fetch the latest version of Camoufox
48
+ path Display the path to the Camoufox executable
49
+ remove Remove all downloaded files
50
+ server Launch a Playwright server
51
+ test Open the Playwright inspector
52
+ version Display the current version
53
+ ```
54
+
55
+ </details>
56
+
57
+ <hr width=50>
58
+
59
+ ## Usage
60
+
61
+ Camoufox is fully compatible with your existing Playwright code. You only have to change your browser initialization:
62
+
63
+ #### Sync API
64
+
65
+ ```python
66
+ from camoufox.sync_api import Camoufox
67
+
68
+ with Camoufox(headless=False) as browser:
69
+ page = browser.new_page()
70
+ page.goto("https://example.com/")
71
+ ```
72
+
73
+ #### Async API
74
+
75
+ ```python
76
+ from camoufox.async_api import AsyncCamoufox
77
+
78
+ async with AsyncCamoufox(headless=False) as browser:
79
+ page = await browser.new_page()
80
+ await page.goto("https://example.com")
81
+ ```
82
+
83
+ <details>
84
+ <summary>Parameters</summary>
85
+
86
+ ```
87
+ Launches a new browser instance for Camoufox.
88
+ Accepts all Playwright Firefox launch options, along with the following:
89
+
90
+ Parameters:
91
+ config (Optional[Dict[str, Any]]):
92
+ Camoufox properties to use.
93
+ os (Optional[ListOrString]):
94
+ Operating system to use for the fingerprint generation.
95
+ Can be "windows", "macos", "linux", or a list to randomly choose from.
96
+ Default: ["windows", "macos", "linux"]
97
+ block_images (Optional[bool]):
98
+ Whether to block all images.
99
+ block_webrtc (Optional[bool]):
100
+ Whether to block WebRTC entirely.
101
+ allow_webgl (Optional[bool]):
102
+ Whether to allow WebGL. To prevent leaks, only use this for special cases.
103
+ geoip (Optional[Union[str, bool]]):
104
+ Calculate longitude, latitude, timezone, country, & locale based on the IP address.
105
+ Pass the target IP address to use, or `True` to find the IP address automatically.
106
+ humanize (Optional[Union[bool, float]]):
107
+ Humanize the cursor movement.
108
+ Takes either `True`, or the MAX duration in seconds of the cursor movement.
109
+ The cursor typically takes up to 1.5 seconds to move across the window.
110
+ locale (Optional[str]):
111
+ Locale to use in Camoufox.
112
+ addons (Optional[List[str]]):
113
+ List of Firefox addons to use.
114
+ fonts (Optional[List[str]]):
115
+ Fonts to load into Camoufox (in addition to the default fonts for the target `os`).
116
+ Takes a list of font family names that are installed on the system.
117
+ exclude_addons (Optional[List[DefaultAddons]]):
118
+ Default addons to exclude. Passed as a list of camoufox.DefaultAddons enums.
119
+ screen (Optional[Screen]):
120
+ Constrains the screen dimensions of the generated fingerprint.
121
+ Takes a browserforge.fingerprints.Screen instance.
122
+ fingerprint (Optional[Fingerprint]):
123
+ Use a custom BrowserForge fingerprint. Note: Not all values will be implemented.
124
+ If not provided, a random fingerprint will be generated based on the provided
125
+ `os` & `screen` constraints.
126
+ ff_version (Optional[int]):
127
+ Firefox version to use. Defaults to the current Camoufox version.
128
+ To prevent leaks, only use this for special cases.
129
+ headless (Optional[bool]):
130
+ Whether to run the browser in headless mode. Defaults to True.
131
+ executable_path (Optional[str]):
132
+ Custom Camoufox browser executable path.
133
+ firefox_user_prefs (Optional[Dict[str, Any]]):
134
+ Firefox user preferences to set.
135
+ proxy (Optional[Dict[str, str]]):
136
+ Proxy to use for the browser.
137
+ Note: If geoip is True, a request will be sent through this proxy to find the target IP.
138
+ args (Optional[List[str]]):
139
+ Arguments to pass to the browser.
140
+ env (Optional[Dict[str, Union[str, float, bool]]]):
141
+ Environment variables to set.
142
+ persistent_context (Optional[bool]):
143
+ Whether to use a persistent context.
144
+ debug (Optional[bool]):
145
+ Prints the config being sent to Camoufox.
146
+ **launch_options (Dict[str, Any]):
147
+ Additional Firefox launch options.
148
+ ```
149
+
150
+ </details>
151
+
152
+ ---
153
+
154
+ ### Config
155
+
156
+ Camoufox [config data](https://github.com/daijro/camoufox?tab=readme-ov-file#fingerprint-injection) can be passed as a dictionary to the `config` parameter:
157
+
158
+ ```python
159
+ from camoufox.sync_api import Camoufox
160
+
161
+ with Camoufox(
162
+ config={
163
+ 'webrtc:ipv4': '123.45.67.89',
164
+ 'webrtc:ipv6': 'e791:d37a:88f6:48d1:2cad:2667:4582:1d6d',
165
+ }
166
+ ) as browser:
167
+ page = browser.new_page()
168
+ page.goto("https://www.browserscan.net/webrtc")
169
+ ```
170
+
171
+ <hr width=50>
172
+
173
+ ### GeoIP & Proxy Support
174
+
175
+ By passing `geoip=True`, or passing in a target IP address, Camoufox will automatically use the target IP's longitude, latitude, timezone, country, locale, & spoof the WebRTC IP address.
176
+
177
+ It will also calculate and spoof the browser's language based on the distribution of language speakers in the target region.
178
+
179
+ #### Installation
180
+
181
+ Install Camoufox with the `geoip` extra:
182
+
183
+ ```bash
184
+ pip install -U camoufox[geoip]
185
+ ```
186
+
187
+ #### Usage
188
+
189
+ Pass in the proxy dictionary as you would with Playwright's `proxy` parameter:
190
+
191
+ ```python
192
+ with Camoufox(
193
+ geoip=True,
194
+ proxy={
195
+ 'server': 'http://example.com:8080',
196
+ 'username': 'username',
197
+ 'password': 'password'
198
+ }
199
+ ) as browser:
200
+ page = browser.new_page()
201
+ page.goto("https://www.browserscan.net")
202
+ ```
203
+
204
+ <hr width=50>
205
+
206
+ ### Remote Server (experimental)
207
+
208
+ > [!WARNING]
209
+ > This feature is experimental and not meant for production use. It uses a hacky workaround to gain access to undocumented Playwright methods.
210
+
211
+ #### Launching
212
+
213
+ To launch a remote server, run the following CLI command:
214
+
215
+ ```bash
216
+ python -m camoufox server
217
+ ```
218
+
219
+ Or, configure the server with a launch script:
220
+
221
+ ```python
222
+ from camoufox.server import launch_server
223
+
224
+ launch_server(
225
+ headless=True,
226
+ geoip=True,
227
+ proxy={
228
+ 'server': 'http://example.com:8080',
229
+ 'username': 'username',
230
+ 'password': 'password'
231
+ }
232
+ )
233
+ ```
234
+
235
+ #### Connecting
236
+
237
+ To connect to the remote server, use Playwright's `connect` method:
238
+
239
+ ```python
240
+ from playwright.sync_api import sync_playwright
241
+
242
+ with sync_playwright() as p:
243
+ # Example endpoint
244
+ browser = p.firefox.connect('ws://localhost:34091/8c7c6cdea3368d937ef7db2277d6647b')
245
+ page = browser.new_page()
246
+ ...
247
+ ```
248
+
249
+ **Note:** Because servers only use **one browser instance**, fingerprints will not rotate between sessions. If you plan on using Camoufox at scale, consider rotating the server between sessions.
250
+
251
+ <hr width=50>
252
+
253
+ ### BrowserForge Integration
254
+
255
+ Camoufox is compatible with [BrowserForge](https://github.com/daijro/browserforge) fingerprints.
256
+
257
+ By default, Camoufox will generate an use a random BrowserForge fingerprint based on the target `os` & `screen` constraints.
258
+
259
+ ```python
260
+ from camoufox.sync_api import Camoufox
261
+ from browserforge.fingerprints import Screen
262
+
263
+ with Camoufox(
264
+ os=('windows', 'macos', 'linux'),
265
+ screen=Screen(max_width=1920, max_height=1080),
266
+ ) as browser:
267
+ page = browser.new_page()
268
+ page.goto("https://example.com/")
269
+ ```
270
+
271
+ **Notes:**
272
+
273
+ - If Camoufox is being ran in headful mode, the max screen size will be generated based on your monitor's dimensions (+15%).
274
+
275
+ - To prevent UA-spoofing leaks, Camoufox only generates fingerprints with the same browser version as the current Camoufox version by default.
276
+
277
+ - If rotating the Firefox version is absolutely necessary, it would be more advisable to rotate between older versions of Camoufox instead.
278
+
279
+ <details>
280
+ <summary>Injecting custom Fingerprint objects...</summary>
281
+
282
+ > [!WARNING]
283
+ > It is recommended to pass `os` & `screen` constraints into Camoufox instead. Camoufox will handle fingerprint generation for you. This will be deprecated in the future.
284
+
285
+ You can also inject your own Firefox BrowserForge fingerprint into Camoufox.
286
+
287
+ ```python
288
+ from camoufox.sync_api import Camoufox
289
+ from browserforge.fingerprints import FingerprintGenerator
290
+
291
+ fg = FingerprintGenerator(browser='firefox')
292
+
293
+ # Launch Camoufox with a random Firefox fingerprint
294
+ with Camoufox(fingerprint=fg.generate()) as browser:
295
+ page = browser.new_page()
296
+ page.goto("https://example.com/")
297
+ ```
298
+
299
+ **Note:** As of now, some properties from BrowserForge fingerprints will not be passed to Camoufox. This is due to the outdated fingerprint dataset from Apify's fingerprint-suite (see [here](https://github.com/apify/fingerprint-suite/discussions/308)). Properties will be re-enabled as soon as an updated dataset is available.
300
+
301
+ </details>
302
+
303
+ ---
@@ -0,0 +1,5 @@
1
+ from .addons import DefaultAddons
2
+ from .async_api import AsyncCamoufox, AsyncNewBrowser
3
+ from .sync_api import Camoufox, NewBrowser
4
+
5
+ __all__ = ["Camoufox", "NewBrowser", "AsyncCamoufox", "AsyncNewBrowser", "DefaultAddons"]