snaprender 0.2.4__tar.gz → 0.3.0__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: snaprender
3
- Version: 0.2.4
3
+ Version: 0.3.0
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
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "snaprender"
7
- version = "0.2.4"
7
+ version = "0.3.0"
8
8
  description = "Official Python SDK for SnapRender Screenshot API"
9
9
  readme = "README.md"
10
10
  license = {text = "MIT"}
@@ -3,4 +3,4 @@
3
3
  from .client import SnapRender, SnapRenderError
4
4
 
5
5
  __all__ = ["SnapRender", "SnapRenderError"]
6
- __version__ = "0.2.4"
6
+ __version__ = "0.3.0"
@@ -44,8 +44,10 @@ class SnapRender:
44
44
 
45
45
  def capture(
46
46
  self,
47
- url: str,
47
+ url: Optional[str] = None,
48
48
  *,
49
+ html: Optional[str] = None,
50
+ markdown: Optional[str] = None,
49
51
  format: str = "png",
50
52
  width: Optional[int] = None,
51
53
  height: Optional[int] = None,
@@ -63,40 +65,91 @@ class SnapRender:
63
65
  cache_ttl: Optional[int] = None,
64
66
  response_type: Optional[str] = None,
65
67
  ) -> "bytes | dict[str, Any]":
66
- """Capture a screenshot. Returns bytes by default, or a dict when response_type='json'."""
67
- params: dict[str, Any] = {"url": url, "format": format}
68
- if width is not None:
69
- params["width"] = width
70
- if height is not None:
71
- params["height"] = height
72
- if full_page is not None:
73
- params["full_page"] = str(full_page).lower()
74
- if quality is not None:
75
- params["quality"] = quality
76
- if delay is not None:
77
- params["delay"] = delay
78
- if dark_mode is not None:
79
- params["dark_mode"] = str(dark_mode).lower()
80
- if block_ads is not None:
81
- params["block_ads"] = str(block_ads).lower()
82
- if block_cookie_banners is not None:
83
- params["block_cookie_banners"] = str(block_cookie_banners).lower()
84
- if hide_selectors is not None:
85
- params["hide_selectors"] = hide_selectors
86
- if click_selector is not None:
87
- params["click_selector"] = click_selector
88
- if device is not None:
89
- params["device"] = device
90
- if user_agent is not None:
91
- params["user_agent"] = user_agent
92
- if cache is not None:
93
- params["cache"] = str(cache).lower()
94
- if cache_ttl is not None:
95
- params["cache_ttl"] = cache_ttl
96
- if response_type is not None:
97
- params["response_type"] = response_type
98
-
99
- resp = self._client.get("/v1/screenshot", params=params)
68
+ """Capture a screenshot. Provide exactly one of: url, html, or markdown.
69
+
70
+ When html or markdown is provided, uses POST with JSON body.
71
+ When url is provided, uses GET with query parameters (backward compatible).
72
+ Returns bytes by default, or a dict when response_type='json'.
73
+ """
74
+ use_post = bool(html or markdown)
75
+
76
+ if use_post:
77
+ body: dict[str, Any] = {"format": format}
78
+ if url is not None:
79
+ body["url"] = url
80
+ if html is not None:
81
+ body["html"] = html
82
+ if markdown is not None:
83
+ body["markdown"] = markdown
84
+ if width is not None:
85
+ body["width"] = width
86
+ if height is not None:
87
+ body["height"] = height
88
+ if full_page is not None:
89
+ body["full_page"] = full_page
90
+ if quality is not None:
91
+ body["quality"] = quality
92
+ if delay is not None:
93
+ body["delay"] = delay
94
+ if dark_mode is not None:
95
+ body["dark_mode"] = dark_mode
96
+ if block_ads is not None:
97
+ body["block_ads"] = block_ads
98
+ if block_cookie_banners is not None:
99
+ body["block_cookie_banners"] = block_cookie_banners
100
+ if hide_selectors is not None:
101
+ body["hide_selectors"] = hide_selectors
102
+ if click_selector is not None:
103
+ body["click_selector"] = click_selector
104
+ if device is not None:
105
+ body["device"] = device
106
+ if user_agent is not None:
107
+ body["user_agent"] = user_agent
108
+ if cache is not None:
109
+ body["cache"] = cache
110
+ if cache_ttl is not None:
111
+ body["cache_ttl"] = cache_ttl
112
+ if response_type is not None:
113
+ body["response_type"] = response_type
114
+
115
+ resp = self._client.post("/v1/screenshot", json=body)
116
+ else:
117
+ if not url:
118
+ raise ValueError("One of url, html, or markdown is required")
119
+ params: dict[str, Any] = {"url": url, "format": format}
120
+ if width is not None:
121
+ params["width"] = width
122
+ if height is not None:
123
+ params["height"] = height
124
+ if full_page is not None:
125
+ params["full_page"] = str(full_page).lower()
126
+ if quality is not None:
127
+ params["quality"] = quality
128
+ if delay is not None:
129
+ params["delay"] = delay
130
+ if dark_mode is not None:
131
+ params["dark_mode"] = str(dark_mode).lower()
132
+ if block_ads is not None:
133
+ params["block_ads"] = str(block_ads).lower()
134
+ if block_cookie_banners is not None:
135
+ params["block_cookie_banners"] = str(block_cookie_banners).lower()
136
+ if hide_selectors is not None:
137
+ params["hide_selectors"] = hide_selectors
138
+ if click_selector is not None:
139
+ params["click_selector"] = click_selector
140
+ if device is not None:
141
+ params["device"] = device
142
+ if user_agent is not None:
143
+ params["user_agent"] = user_agent
144
+ if cache is not None:
145
+ params["cache"] = str(cache).lower()
146
+ if cache_ttl is not None:
147
+ params["cache_ttl"] = cache_ttl
148
+ if response_type is not None:
149
+ params["response_type"] = response_type
150
+
151
+ resp = self._client.get("/v1/screenshot", params=params)
152
+
100
153
  if resp.status_code != 200:
101
154
  self._raise_error(resp)
102
155
  if response_type == "json":
File without changes
File without changes
File without changes