web-capture-python-examples 0.1.0__py3-none-any.whl

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,5 @@
1
+ """HTTP client examples for a running web-capture service."""
2
+
3
+ from .capture_client import capture, download_text
4
+
5
+ __all__ = ["capture", "download_text"]
@@ -0,0 +1,20 @@
1
+ """Shared request policy for the capture-service examples."""
2
+ import os
3
+ from pathlib import Path
4
+ import sys
5
+ import requests
6
+
7
+
8
+ def capture(kind, url=None, **options):
9
+ if url is None:
10
+ url = sys.argv[1] if len(sys.argv) > 1 else 'https://example.com'
11
+ endpoint = os.environ.get('WEB_CAPTURE_URL', 'http://localhost:3000').rstrip('/')
12
+ response = requests.get(f'{endpoint}/{kind}', params={'url': url, **options}, timeout=30)
13
+ response.raise_for_status()
14
+ return response
15
+
16
+
17
+ def download_text(kind, filename):
18
+ output = Path.cwd() / filename if __package__ else Path(__file__).with_name(filename)
19
+ output.write_text(capture(kind).text, encoding='utf-8')
20
+ print(f'{kind.title()} saved to {output}')
@@ -0,0 +1,6 @@
1
+ if __package__:
2
+ from .capture_client import download_text
3
+ else:
4
+ from capture_client import download_text
5
+
6
+ download_text('html', 'downloaded.html')
@@ -0,0 +1,19 @@
1
+ if __package__:
2
+ from .capture_client import capture
3
+ else:
4
+ from capture_client import capture
5
+ import os
6
+
7
+ response = capture('image')
8
+ print('Status:', response.status_code)
9
+ print('Content-Type:', response.headers.get('content-type'))
10
+
11
+ # PNG signature: first 8 bytes
12
+ png_signature = b'\x89PNG\r\n\x1a\n'
13
+ if response.content[:8] == png_signature:
14
+ output_path = 'downloaded.png' if __package__ else os.path.join(os.path.dirname(__file__), 'downloaded.png')
15
+ with open(output_path, 'wb') as f:
16
+ f.write(response.content)
17
+ print(f'Image saved to {output_path} (valid PNG)')
18
+ else:
19
+ print('Response is not a valid PNG! First bytes:', response.content[:16])
@@ -0,0 +1,6 @@
1
+ if __package__:
2
+ from .capture_client import download_text
3
+ else:
4
+ from capture_client import download_text
5
+
6
+ download_text('markdown', 'downloaded.md')
@@ -0,0 +1,25 @@
1
+ import sys
2
+ if __package__:
3
+ from .capture_client import capture
4
+ else:
5
+ from capture_client import capture
6
+ import os
7
+
8
+ target_url = sys.argv[1] if len(sys.argv) > 1 else 'https://example.com'
9
+
10
+ # Create output directory if it doesn't exist
11
+ os.makedirs('output', exist_ok=True)
12
+
13
+ print('Fetching HTML using Playwright engine...')
14
+ html_response = capture('html', target_url, engine='playwright')
15
+ with open('output/playwright_html.html', 'w', encoding='utf-8') as f:
16
+ f.write(html_response.text)
17
+ print('HTML saved to output/playwright_html.html')
18
+
19
+ print('Fetching screenshot using Playwright engine...')
20
+ image_response = capture('image', target_url, engine='playwright')
21
+ with open('output/playwright_screenshot.png', 'wb') as f:
22
+ f.write(image_response.content)
23
+ print('Screenshot saved to output/playwright_screenshot.png')
24
+
25
+ print('Done! Both requests used Playwright engine.')
@@ -0,0 +1,52 @@
1
+ Metadata-Version: 2.4
2
+ Name: web-capture-python-examples
3
+ Version: 0.1.0
4
+ Summary: Python HTTP client examples for the web-capture service
5
+ License-Expression: Unlicense
6
+ Project-URL: Homepage, https://github.com/link-assistant/web-capture
7
+ Project-URL: Repository, https://github.com/link-assistant/web-capture
8
+ Project-URL: Issues, https://github.com/link-assistant/web-capture/issues
9
+ Project-URL: Documentation, https://github.com/link-assistant/web-capture/blob/main/docs/python-examples.md
10
+ Requires-Python: >=3.14
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: requests>=2.34.2
14
+ Dynamic: license-file
15
+
16
+ # web-capture-python-examples
17
+
18
+ Python HTTP client examples for [web-capture](https://github.com/link-assistant/web-capture).
19
+ Python 3.14 or later is required. The first public version is **0.1.0**;
20
+ `0.0.0` was a development placeholder.
21
+
22
+ The package connects to a running JavaScript or Rust web-capture HTTP service.
23
+ Start that service separately using the [repository quick start](https://github.com/link-assistant/web-capture#quick-start).
24
+
25
+ After the first release is published:
26
+
27
+ ```bash
28
+ python -m pip install web-capture-python-examples
29
+ python -m web_capture_python_examples.html_download https://example.com
30
+ python -m web_capture_python_examples.markdown_download https://example.com
31
+ python -m web_capture_python_examples.image_download https://example.com
32
+ python -m web_capture_python_examples.playwright_example https://example.com
33
+ ```
34
+
35
+ Set `WEB_CAPTURE_URL` to override `http://localhost:3000`. Downloads are saved
36
+ in the current directory (`downloaded.html`, `downloaded.md`, `downloaded.png`,
37
+ or `output/` for the Playwright example), so the installed package need not be writable.
38
+ The Playwright example selects the server's browser engine; it needs no local browser.
39
+ The source scripts in `js/examples/python/` remain directly runnable.
40
+
41
+ The shared client is also importable:
42
+
43
+ ```python
44
+ from web_capture_python_examples import capture
45
+
46
+ response = capture('markdown', 'https://example.com')
47
+ print(response.text)
48
+ ```
49
+
50
+ Requests have a 30-second timeout and propagate HTTP and connection errors.
51
+ See [the release instructions](https://github.com/link-assistant/web-capture/blob/main/docs/releases/python-trusted-publishing.md)
52
+ for pending-publisher configuration and publication status.
@@ -0,0 +1,11 @@
1
+ web_capture_python_examples/__init__.py,sha256=7uuXCq_wsyMYuoqFsDfz53tPdmRGmpr4mJTFKi9HKcc,154
2
+ web_capture_python_examples/capture_client.py,sha256=mOUIUdCRuW2a_uP96Qh3llMOow2xvmPEPWUhp-9xzNs,726
3
+ web_capture_python_examples/html_download.py,sha256=VzE8EiflGJ_4ep16782k7EcfrnNuEz6V5myPekzU91k,155
4
+ web_capture_python_examples/image_download.py,sha256=jnuRu-QOQ-IDkaJ48avpwVjWDEYGz0ambjH1Oem0KsA,676
5
+ web_capture_python_examples/markdown_download.py,sha256=jwXGfowPJB5Q0hdmtIota84rqDn2GO4bUg4dZS6ranE,157
6
+ web_capture_python_examples/playwright_example.py,sha256=EBTn0kjeCkCJS-16Xy4a3vHx-khRa02NOiKOUPwvAjI,883
7
+ web_capture_python_examples-0.1.0.dist-info/licenses/LICENSE,sha256=awOCsWJ58m_2kBQwBUGWejVqZm6wuRtCL2hi9rfa0X4,1211
8
+ web_capture_python_examples-0.1.0.dist-info/METADATA,sha256=tHiTKFN5UcxKUS05_Sh-GofihHmtAZA5fTobPgroCZM,2323
9
+ web_capture_python_examples-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
10
+ web_capture_python_examples-0.1.0.dist-info/top_level.txt,sha256=tlN4ifHs1Z05itAPHf4ya8PwthAWIz6fiegSPttt9C8,28
11
+ web_capture_python_examples-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org>
@@ -0,0 +1 @@
1
+ web_capture_python_examples