snaprender 0.2.0__tar.gz → 0.2.2__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.
@@ -10,6 +10,9 @@ coverage/
10
10
  *.tsbuildinfo
11
11
  .DS_Store
12
12
  tmp/
13
+ backups/
13
14
  site/.astro/
14
15
  site/dist/
15
16
  claude-instructions/sdk-tokens.md
17
+ claude-instructions/stripe-live.txt
18
+ .mcpregistry_*
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: snaprender
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Official Python SDK for SnapRender Screenshot API
5
5
  Project-URL: Homepage, https://snap-render.com
6
6
  Project-URL: Documentation, https://snap-render.com/docs
@@ -14,7 +14,23 @@ Description-Content-Type: text/markdown
14
14
 
15
15
  # snaprender
16
16
 
17
- Official Python SDK for the [SnapRender](https://snap-render.com) Screenshot API.
17
+ [![PyPI version](https://img.shields.io/pypi/v/snaprender)](https://pypi.org/project/snaprender/)
18
+ [![PyPI downloads](https://img.shields.io/pypi/dm/snaprender)](https://pypi.org/project/snaprender/)
19
+ [![license](https://img.shields.io/pypi/l/snaprender)](https://github.com/User0856/snaprender/blob/main/LICENSE)
20
+
21
+ Official Python SDK for the [SnapRender](https://snap-render.com) Screenshot API — capture pixel-perfect screenshots of any webpage with a single API call.
22
+
23
+ **50 free screenshots/month — [Get your API key](https://app.snap-render.com/auth/signup?ref=pypi)**
24
+
25
+ ## Features
26
+
27
+ - **Multiple output formats** — PNG, JPEG, WebP, and PDF
28
+ - **Device emulation** — iPhone, iPad, Pixel, and more presets
29
+ - **Dark mode** — Capture pages with `prefers-color-scheme: dark`
30
+ - **Ad blocking** — Remove ads automatically before capture
31
+ - **Cookie banner removal** — Clean screenshots without consent popups
32
+ - **Smart caching** — Configurable CDN cache with TTL control
33
+ - **Full-page captures** — Screenshot the entire scrollable page
18
34
 
19
35
  ## Install
20
36
 
@@ -61,21 +77,6 @@ with SnapRender(api_key="sk_live_...") as snap:
61
77
  image = snap.capture("https://example.com")
62
78
  ```
63
79
 
64
- ## Error Handling
65
-
66
- ```python
67
- from snaprender import SnapRender, SnapRenderError
68
-
69
- snap = SnapRender(api_key="sk_live_...")
70
-
71
- try:
72
- snap.capture("https://example.com")
73
- except SnapRenderError as e:
74
- print(e.code) # "QUOTA_EXCEEDED"
75
- print(e.status) # 429
76
- print(e) # "Monthly quota exceeded"
77
- ```
78
-
79
80
  ## API
80
81
 
81
82
  ### `SnapRender(api_key, base_url="https://app.snap-render.com", timeout=60.0)`
@@ -94,10 +95,71 @@ except SnapRenderError as e:
94
95
  | `dark_mode` | bool | `False` | Emulate dark mode |
95
96
  | `block_ads` | bool | `True` | Block ad networks |
96
97
  | `block_cookie_banners` | bool | `True` | Remove cookie banners |
97
- | `device` | str | — | Device preset (e.g. `"iPhone 15"`) |
98
+ | `device` | str | — | Device preset (`"iphone_14"`, `"iphone_15_pro"`, `"pixel_7"`, `"ipad_pro"`, `"macbook_pro"`) |
99
+ | `hide_selectors` | str | — | Comma-separated CSS selectors to hide |
100
+ | `click_selector` | str | — | CSS selector to click before capture |
101
+ | `user_agent` | str | — | Custom user agent string |
98
102
  | `cache` | bool | `True` | Use cache |
99
103
  | `cache_ttl` | int | `86400` | Cache TTL in seconds |
104
+ | `response_type` | str | — | `"json"` returns metadata + base64 data URI |
100
105
 
101
106
  ### `snap.info(url)` -> `dict`
107
+
108
+ Check if a screenshot is cached without capturing.
109
+
102
110
  ### `snap.usage()` -> `dict`
111
+
112
+ Get current month's usage.
113
+
103
114
  ### `snap.usage_daily(days=30)` -> `dict`
115
+
116
+ Get daily usage breakdown (default 30 days).
117
+
118
+ ## LangChain Integration
119
+
120
+ Use SnapRender as a [LangChain](https://python.langchain.com/) tool for AI agents:
121
+
122
+ ```python
123
+ import os
124
+ from langchain_core.tools import tool
125
+ from snaprender import SnapRender
126
+
127
+ client = SnapRender(api_key=os.environ["SNAPRENDER_API_KEY"])
128
+
129
+ @tool
130
+ def take_screenshot(url: str, format: str = "png", dark_mode: bool = False) -> str:
131
+ """Capture a screenshot of any website URL. Returns base64 data URI."""
132
+ result = client.capture(
133
+ url, format=format, dark_mode=dark_mode, response_type="json"
134
+ )
135
+ return result["image"]
136
+ ```
137
+
138
+ Works with LangGraph, CrewAI, and any framework that supports LangChain tools.
139
+
140
+ ## Error Handling
141
+
142
+ ```python
143
+ from snaprender import SnapRender, SnapRenderError
144
+
145
+ snap = SnapRender(api_key="sk_live_...")
146
+
147
+ try:
148
+ snap.capture("https://example.com")
149
+ except SnapRenderError as e:
150
+ print(e.code) # "QUOTA_EXCEEDED"
151
+ print(e.status) # 429
152
+ print(e) # "Monthly quota exceeded"
153
+ ```
154
+
155
+ ## Links
156
+
157
+ - [Documentation](https://app.snap-render.com/#docs)
158
+ - [Pricing](https://app.snap-render.com/pricing)
159
+ - [Dashboard](https://app.snap-render.com/dashboard)
160
+ - [Blog](https://app.snap-render.com/blog)
161
+ - [GitHub](https://github.com/User0856/snaprender)
162
+
163
+ ## License
164
+
165
+ MIT
@@ -0,0 +1,151 @@
1
+ # snaprender
2
+
3
+ [![PyPI version](https://img.shields.io/pypi/v/snaprender)](https://pypi.org/project/snaprender/)
4
+ [![PyPI downloads](https://img.shields.io/pypi/dm/snaprender)](https://pypi.org/project/snaprender/)
5
+ [![license](https://img.shields.io/pypi/l/snaprender)](https://github.com/User0856/snaprender/blob/main/LICENSE)
6
+
7
+ Official Python SDK for the [SnapRender](https://snap-render.com) Screenshot API — capture pixel-perfect screenshots of any webpage with a single API call.
8
+
9
+ **50 free screenshots/month — [Get your API key](https://app.snap-render.com/auth/signup?ref=pypi)**
10
+
11
+ ## Features
12
+
13
+ - **Multiple output formats** — PNG, JPEG, WebP, and PDF
14
+ - **Device emulation** — iPhone, iPad, Pixel, and more presets
15
+ - **Dark mode** — Capture pages with `prefers-color-scheme: dark`
16
+ - **Ad blocking** — Remove ads automatically before capture
17
+ - **Cookie banner removal** — Clean screenshots without consent popups
18
+ - **Smart caching** — Configurable CDN cache with TTL control
19
+ - **Full-page captures** — Screenshot the entire scrollable page
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ pip install snaprender
25
+ ```
26
+
27
+ ## Quick Start
28
+
29
+ ```python
30
+ from snaprender import SnapRender
31
+
32
+ snap = SnapRender(api_key="sk_live_...")
33
+
34
+ # Capture a screenshot
35
+ image = snap.capture("https://example.com")
36
+ with open("screenshot.png", "wb") as f:
37
+ f.write(image)
38
+
39
+ # Capture with options
40
+ jpg = snap.capture(
41
+ "https://example.com",
42
+ format="jpeg",
43
+ width=1920,
44
+ height=1080,
45
+ full_page=True,
46
+ dark_mode=True,
47
+ quality=95,
48
+ )
49
+
50
+ # Check cache status
51
+ info = snap.info("https://example.com")
52
+ print(info["cached"]) # True/False
53
+
54
+ # Get usage
55
+ usage = snap.usage()
56
+ print(f"{usage['used']}/{usage['limit']} screenshots used")
57
+ ```
58
+
59
+ ## Context Manager
60
+
61
+ ```python
62
+ with SnapRender(api_key="sk_live_...") as snap:
63
+ image = snap.capture("https://example.com")
64
+ ```
65
+
66
+ ## API
67
+
68
+ ### `SnapRender(api_key, base_url="https://app.snap-render.com", timeout=60.0)`
69
+
70
+ ### `snap.capture(url, **options)` -> `bytes`
71
+
72
+ | Option | Type | Default | Description |
73
+ |--------|------|---------|-------------|
74
+ | `url` | str | — | URL to capture (required) |
75
+ | `format` | str | `"png"` | `"png"`, `"jpeg"`, `"webp"`, or `"pdf"` |
76
+ | `width` | int | `1280` | Viewport width |
77
+ | `height` | int | `800` | Viewport height |
78
+ | `full_page` | bool | `False` | Capture full scrollable page |
79
+ | `quality` | int | `90` | JPEG/WebP quality (1-100) |
80
+ | `delay` | int | `0` | Wait ms after page load |
81
+ | `dark_mode` | bool | `False` | Emulate dark mode |
82
+ | `block_ads` | bool | `True` | Block ad networks |
83
+ | `block_cookie_banners` | bool | `True` | Remove cookie banners |
84
+ | `device` | str | — | Device preset (`"iphone_14"`, `"iphone_15_pro"`, `"pixel_7"`, `"ipad_pro"`, `"macbook_pro"`) |
85
+ | `hide_selectors` | str | — | Comma-separated CSS selectors to hide |
86
+ | `click_selector` | str | — | CSS selector to click before capture |
87
+ | `user_agent` | str | — | Custom user agent string |
88
+ | `cache` | bool | `True` | Use cache |
89
+ | `cache_ttl` | int | `86400` | Cache TTL in seconds |
90
+ | `response_type` | str | — | `"json"` returns metadata + base64 data URI |
91
+
92
+ ### `snap.info(url)` -> `dict`
93
+
94
+ Check if a screenshot is cached without capturing.
95
+
96
+ ### `snap.usage()` -> `dict`
97
+
98
+ Get current month's usage.
99
+
100
+ ### `snap.usage_daily(days=30)` -> `dict`
101
+
102
+ Get daily usage breakdown (default 30 days).
103
+
104
+ ## LangChain Integration
105
+
106
+ Use SnapRender as a [LangChain](https://python.langchain.com/) tool for AI agents:
107
+
108
+ ```python
109
+ import os
110
+ from langchain_core.tools import tool
111
+ from snaprender import SnapRender
112
+
113
+ client = SnapRender(api_key=os.environ["SNAPRENDER_API_KEY"])
114
+
115
+ @tool
116
+ def take_screenshot(url: str, format: str = "png", dark_mode: bool = False) -> str:
117
+ """Capture a screenshot of any website URL. Returns base64 data URI."""
118
+ result = client.capture(
119
+ url, format=format, dark_mode=dark_mode, response_type="json"
120
+ )
121
+ return result["image"]
122
+ ```
123
+
124
+ Works with LangGraph, CrewAI, and any framework that supports LangChain tools.
125
+
126
+ ## Error Handling
127
+
128
+ ```python
129
+ from snaprender import SnapRender, SnapRenderError
130
+
131
+ snap = SnapRender(api_key="sk_live_...")
132
+
133
+ try:
134
+ snap.capture("https://example.com")
135
+ except SnapRenderError as e:
136
+ print(e.code) # "QUOTA_EXCEEDED"
137
+ print(e.status) # 429
138
+ print(e) # "Monthly quota exceeded"
139
+ ```
140
+
141
+ ## Links
142
+
143
+ - [Documentation](https://app.snap-render.com/#docs)
144
+ - [Pricing](https://app.snap-render.com/pricing)
145
+ - [Dashboard](https://app.snap-render.com/dashboard)
146
+ - [Blog](https://app.snap-render.com/blog)
147
+ - [GitHub](https://github.com/User0856/snaprender)
148
+
149
+ ## License
150
+
151
+ MIT
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "snaprender"
7
- version = "0.2.0"
7
+ version = "0.2.2"
8
8
  description = "Official Python SDK for SnapRender Screenshot API"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -61,8 +61,9 @@ class SnapRender:
61
61
  user_agent: Optional[str] = None,
62
62
  cache: Optional[bool] = None,
63
63
  cache_ttl: Optional[int] = None,
64
- ) -> bytes:
65
- """Capture a screenshot and return the image bytes."""
64
+ response_type: Optional[str] = None,
65
+ ) -> "bytes | dict[str, Any]":
66
+ """Capture a screenshot. Returns bytes by default, or a dict when response_type='json'."""
66
67
  params: dict[str, Any] = {"url": url, "format": format}
67
68
  if width is not None:
68
69
  params["width"] = width
@@ -92,10 +93,14 @@ class SnapRender:
92
93
  params["cache"] = str(cache).lower()
93
94
  if cache_ttl is not None:
94
95
  params["cache_ttl"] = cache_ttl
96
+ if response_type is not None:
97
+ params["response_type"] = response_type
95
98
 
96
99
  resp = self._client.get("/v1/screenshot", params=params)
97
100
  if resp.status_code != 200:
98
101
  self._raise_error(resp)
102
+ if response_type == "json":
103
+ return resp.json()
99
104
  return resp.content
100
105
 
101
106
  def info(self, url: str, **kwargs: Any) -> dict[str, Any]:
@@ -107,11 +112,21 @@ class SnapRender:
107
112
  return resp.json()
108
113
 
109
114
  def usage(self) -> dict[str, Any]:
110
- """Get current month's usage."""
115
+ """Get current month's usage.
116
+
117
+ Returns a dict with keys: plan, used, limit, remaining, period.
118
+ """
111
119
  resp = self._client.get("/v1/usage")
112
120
  if resp.status_code != 200:
113
121
  self._raise_error(resp)
114
- return resp.json()
122
+ data = resp.json()
123
+ return {
124
+ "plan": data["plan"],
125
+ "used": data["usage"]["screenshots_used"],
126
+ "limit": data["usage"]["screenshots_limit"],
127
+ "remaining": data["usage"]["screenshots_remaining"],
128
+ "period": data["period"],
129
+ }
115
130
 
116
131
  def usage_daily(self, days: int = 30) -> dict[str, Any]:
117
132
  """Get daily usage breakdown."""
@@ -1,89 +0,0 @@
1
- # snaprender
2
-
3
- Official Python SDK for the [SnapRender](https://snap-render.com) Screenshot API.
4
-
5
- ## Install
6
-
7
- ```bash
8
- pip install snaprender
9
- ```
10
-
11
- ## Quick Start
12
-
13
- ```python
14
- from snaprender import SnapRender
15
-
16
- snap = SnapRender(api_key="sk_live_...")
17
-
18
- # Capture a screenshot
19
- image = snap.capture("https://example.com")
20
- with open("screenshot.png", "wb") as f:
21
- f.write(image)
22
-
23
- # Capture with options
24
- jpg = snap.capture(
25
- "https://example.com",
26
- format="jpeg",
27
- width=1920,
28
- height=1080,
29
- full_page=True,
30
- dark_mode=True,
31
- quality=95,
32
- )
33
-
34
- # Check cache status
35
- info = snap.info("https://example.com")
36
- print(info["cached"]) # True/False
37
-
38
- # Get usage
39
- usage = snap.usage()
40
- print(f"{usage['used']}/{usage['limit']} screenshots used")
41
- ```
42
-
43
- ## Context Manager
44
-
45
- ```python
46
- with SnapRender(api_key="sk_live_...") as snap:
47
- image = snap.capture("https://example.com")
48
- ```
49
-
50
- ## Error Handling
51
-
52
- ```python
53
- from snaprender import SnapRender, SnapRenderError
54
-
55
- snap = SnapRender(api_key="sk_live_...")
56
-
57
- try:
58
- snap.capture("https://example.com")
59
- except SnapRenderError as e:
60
- print(e.code) # "QUOTA_EXCEEDED"
61
- print(e.status) # 429
62
- print(e) # "Monthly quota exceeded"
63
- ```
64
-
65
- ## API
66
-
67
- ### `SnapRender(api_key, base_url="https://app.snap-render.com", timeout=60.0)`
68
-
69
- ### `snap.capture(url, **options)` -> `bytes`
70
-
71
- | Option | Type | Default | Description |
72
- |--------|------|---------|-------------|
73
- | `url` | str | — | URL to capture (required) |
74
- | `format` | str | `"png"` | `"png"`, `"jpeg"`, `"webp"`, or `"pdf"` |
75
- | `width` | int | `1280` | Viewport width |
76
- | `height` | int | `800` | Viewport height |
77
- | `full_page` | bool | `False` | Capture full scrollable page |
78
- | `quality` | int | `90` | JPEG/WebP quality (1-100) |
79
- | `delay` | int | `0` | Wait ms after page load |
80
- | `dark_mode` | bool | `False` | Emulate dark mode |
81
- | `block_ads` | bool | `True` | Block ad networks |
82
- | `block_cookie_banners` | bool | `True` | Remove cookie banners |
83
- | `device` | str | — | Device preset (e.g. `"iPhone 15"`) |
84
- | `cache` | bool | `True` | Use cache |
85
- | `cache_ttl` | int | `86400` | Cache TTL in seconds |
86
-
87
- ### `snap.info(url)` -> `dict`
88
- ### `snap.usage()` -> `dict`
89
- ### `snap.usage_daily(days=30)` -> `dict`
File without changes