workers-runtime-sdk 1.5.0__tar.gz → 1.5.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.
Files changed (17) hide show
  1. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/CHANGELOG.md +13 -0
  2. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/PKG-INFO +1 -1
  3. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/pyproject.toml +1 -1
  4. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/workers/__init__.py +2 -1
  5. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/workers/_workers.py +44 -32
  6. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/uv.lock +1 -1
  7. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/.gitignore +0 -0
  8. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/AGENTS.md +0 -0
  9. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/README.md +0 -0
  10. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/_cloudflare_compat_flags.pyi +0 -0
  11. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/_pyodide_entrypoint_helper.pyi +0 -0
  12. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/_workers_sdk_entropy_import_context.pth +0 -0
  13. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/_workers_sdk_entropy_import_context.py +0 -0
  14. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/_workers_sdk_entropy_import_context_loader.py +0 -0
  15. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/asgi.py +0 -0
  16. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/workers/py.typed +0 -0
  17. {workers_runtime_sdk-1.5.0 → workers_runtime_sdk-1.5.1}/src/workers/workflows.py +0 -0
@@ -2,6 +2,19 @@
2
2
 
3
3
  <!-- version list -->
4
4
 
5
+ ## v1.5.1 (2026-06-29)
6
+
7
+ ### Bug Fixes
8
+
9
+ - Ensure self.env and top-level env uses a same class
10
+ ([#136](https://github.com/cloudflare/workers-py/pull/136),
11
+ [`e627c11`](https://github.com/cloudflare/workers-py/commit/e627c11f58c572f6ee5df97e423928ee4423d2e9))
12
+
13
+ - Update FetchResponse.headers to return HTTPMessage
14
+ ([#136](https://github.com/cloudflare/workers-py/pull/136),
15
+ [`e627c11`](https://github.com/cloudflare/workers-py/commit/e627c11f58c572f6ee5df97e423928ee4423d2e9))
16
+
17
+
5
18
  ## v1.5.0 (2026-06-23)
6
19
 
7
20
  ### Features
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: workers-runtime-sdk
3
- Version: 1.5.0
3
+ Version: 1.5.1
4
4
  Summary: Python SDK for Cloudflare Workers
5
5
  Project-URL: Homepage, https://github.com/cloudflare/workers-py
6
6
  Project-URL: Bug Tracker, https://github.com/cloudflare/workers-py/issues
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "workers-runtime-sdk"
7
- version = "1.5.0"
7
+ version = "1.5.1"
8
8
  description = "Python SDK for Cloudflare Workers"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -17,6 +17,7 @@ from ._workers import (
17
17
  Response,
18
18
  WorkerEntrypoint,
19
19
  WorkflowEntrypoint,
20
+ _EnvWrapper,
20
21
  fetch,
21
22
  handler,
22
23
  import_from_javascript,
@@ -59,7 +60,7 @@ __all__ = [
59
60
  def __getattr__(key):
60
61
  if key == "env":
61
62
  cloudflare_workers = import_from_javascript("cloudflare:workers")
62
- return cloudflare_workers.env
63
+ return _EnvWrapper(cloudflare_workers.env)
63
64
  if key in ("wait_until", "waitUntil"):
64
65
  cloudflare_workers = import_from_javascript("cloudflare:workers")
65
66
  return cloudflare_workers.waitUntil
@@ -153,8 +153,45 @@ class FetchKwargs(TypedDict, total=False):
153
153
  fetcher: type[pyfetch] | None
154
154
 
155
155
 
156
- # TODO: Pyodide's FetchResponse.headers returns a dict[str, str] which means
157
- # duplicates are lost, we should fix that so it returns a http.client.HTTPMessage
156
+ def _js_headers_to_http_message(
157
+ js_headers: dict[str, str],
158
+ ):
159
+ # `http.client` is imported here because it costs a lot of CPU time when imported at the
160
+ # top-level. At least it does when we do so in our validator tests, doesn't seem to cause
161
+ # trouble in production. So as a workaround we do the import here.
162
+ #
163
+ # TODO(later): when dedicated snapshots are default we can move this import to the top-level.
164
+ import http.client
165
+
166
+ # Newer Pyodide versions already expose headers as an http.client.HTTPMessage,
167
+ # in which case there is nothing to convert.
168
+ if isinstance(js_headers, http.client.HTTPMessage):
169
+ return js_headers
170
+
171
+ result = http.client.HTTPMessage()
172
+ if not get_compat_flag("python_request_headers_preserve_commas"):
173
+ for key, val in js_headers:
174
+ result[key] = val.strip()
175
+
176
+ return result
177
+
178
+ # With the exception of Set-Cookie, duplicate headers can and are combined with a comma
179
+ # in the JS Headers API. We do the same when returning the headers to Python.
180
+ #
181
+ # See https://httpwg.org/specs/rfc9110.html#rfc.section.5.3.
182
+ set_cookie_headers = js_headers.getSetCookie()
183
+ if set_cookie_headers:
184
+ for value in set_cookie_headers:
185
+ result.add_header("Set-Cookie", value.strip())
186
+
187
+ for key, val in js_headers:
188
+ if key.lower() == "set-cookie":
189
+ continue
190
+ result.add_header(key, val.strip())
191
+
192
+ return result
193
+
194
+
158
195
  class FetchResponse(pyodide.http.FetchResponse):
159
196
  # TODO: Consider upstreaming the `body` attribute
160
197
  # TODO: Behind a compat flag make this return a native stream (StreamReader?), or perhaps
@@ -170,6 +207,10 @@ class FetchResponse(pyodide.http.FetchResponse):
170
207
  def js_object(self) -> "js.Response":
171
208
  return self.js_response
172
209
 
210
+ @property
211
+ def headers(self):
212
+ return _js_headers_to_http_message(self.js_object.headers)
213
+
173
214
  """
174
215
  Instance methods defined below.
175
216
 
@@ -813,36 +854,7 @@ class Request:
813
854
 
814
855
  @property
815
856
  def headers(self):
816
- # This is imported here because it costs a lot of CPU time when imported at the top-level.
817
- # At least it does when we do so in our validator tests, doesn't seem to cause trouble in
818
- # production. So as a workaround we do the import here.
819
- #
820
- # TODO(later): when dedicated snapshots are default we can move this import to the top-level.
821
- import http.client
822
-
823
- result = http.client.HTTPMessage()
824
- if not get_compat_flag("python_request_headers_preserve_commas"):
825
- for key, val in self.js_object.headers:
826
- result[key] = val.strip()
827
-
828
- return result
829
-
830
- # With the exception of Set-Cookie, duplicate headers can and are combined with a comma
831
- # in the JS Headers API. We do the same when returning the headers to Python.
832
- #
833
- # See https://httpwg.org/specs/rfc9110.html#rfc.section.5.3.
834
- js_headers = self.js_object.headers
835
- set_cookie_headers = js_headers.getSetCookie()
836
- if set_cookie_headers:
837
- for value in set_cookie_headers:
838
- result.add_header("Set-Cookie", value.strip())
839
-
840
- for key, val in js_headers:
841
- if key.lower() == "set-cookie":
842
- continue
843
- result.add_header(key, val.strip())
844
-
845
- return result
857
+ return _js_headers_to_http_message(self.js_object.headers)
846
858
 
847
859
  @property
848
860
  def integrity(self) -> str:
@@ -210,7 +210,7 @@ wheels = [
210
210
 
211
211
  [[package]]
212
212
  name = "workers-runtime-sdk"
213
- version = "1.1.2"
213
+ version = "1.4.3"
214
214
  source = { editable = "." }
215
215
 
216
216
  [package.dev-dependencies]