vercel-internal-core-bundle 0.1.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.
Files changed (32) hide show
  1. vercel_internal_core_bundle-0.1.0/LICENSE +21 -0
  2. vercel_internal_core_bundle-0.1.0/PKG-INFO +28 -0
  3. vercel_internal_core_bundle-0.1.0/README.md +18 -0
  4. vercel_internal_core_bundle-0.1.0/_vercel_hatch_build.py +116 -0
  5. vercel_internal_core_bundle-0.1.0/hatch_build.py +29 -0
  6. vercel_internal_core_bundle-0.1.0/pyproject.toml +88 -0
  7. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/__init__.py +1 -0
  8. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/_vendor/__init__.py +1 -0
  9. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/_vendor/vendor.txt +1 -0
  10. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/byte_stream.py +258 -0
  11. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/errors.py +17 -0
  12. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/http/__init__.py +46 -0
  13. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/http/config.py +9 -0
  14. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/http/httpx.py +48 -0
  15. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/http/retry.py +20 -0
  16. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/http/transport.py +896 -0
  17. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/iter_coroutine.py +20 -0
  18. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/options.py +48 -0
  19. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/polyfills/__init__.py +9 -0
  20. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/polyfills/_datetime.py +5 -0
  21. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/polyfills/_strenum.py +10 -0
  22. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/polyfills/_strenum_impl.py +14 -0
  23. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/polyfills/_typing.py +8 -0
  24. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/py.typed +1 -0
  25. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/session.py +433 -0
  26. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/time.py +49 -0
  27. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/url.py +18 -0
  28. vercel_internal_core_bundle-0.1.0/vercel/_internal/core/version.py +1 -0
  29. vercel_internal_core_bundle-0.1.0/vercel/api/__init__.py +5 -0
  30. vercel_internal_core_bundle-0.1.0/vercel/api/py.typed +1 -0
  31. vercel_internal_core_bundle-0.1.0/vercel/errors/__init__.py +15 -0
  32. vercel_internal_core_bundle-0.1.0/vercel/errors/py.typed +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Vercel, Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,28 @@
1
+ Metadata-Version: 2.4
2
+ Name: vercel-internal-core-bundle
3
+ Version: 0.1.0
4
+ Summary: Shared internal runtime for Vercel Python packages
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: vercel-internal-shared-vendored-deps>=0.1.0
9
+ Description-Content-Type: text/markdown
10
+
11
+ # vercel-internal-core-bundle
12
+
13
+ This is a version of `vercel-internal-core` with third-party dependencies bundled. For normal use, install the unbundled `vercel-internal-core` package instead: https://pypi.org/project/vercel-internal-core/
14
+
15
+ # Internal Core
16
+
17
+ `vercel._internal.core` provides the shared runtime used by Vercel Python service
18
+ packages. It is installed as their dependency and is not intended for direct
19
+ installation or direct end-user imports.
20
+
21
+ The distribution contributes service-neutral namespace portions. Import the
22
+ public session context from `vercel.api` and shared exceptions from
23
+ `vercel.errors`:
24
+
25
+ ```python
26
+ from vercel.api import session
27
+ from vercel.errors import VercelError
28
+ ```
@@ -0,0 +1,18 @@
1
+ # vercel-internal-core-bundle
2
+
3
+ This is a version of `vercel-internal-core` with third-party dependencies bundled. For normal use, install the unbundled `vercel-internal-core` package instead: https://pypi.org/project/vercel-internal-core/
4
+
5
+ # Internal Core
6
+
7
+ `vercel._internal.core` provides the shared runtime used by Vercel Python service
8
+ packages. It is installed as their dependency and is not intended for direct
9
+ installation or direct end-user imports.
10
+
11
+ The distribution contributes service-neutral namespace portions. Import the
12
+ public session context from `vercel.api` and shared exceptions from
13
+ `vercel.errors`:
14
+
15
+ ```python
16
+ from vercel.api import session
17
+ from vercel.errors import VercelError
18
+ ```
@@ -0,0 +1,116 @@
1
+ """Hatch metadata hook for publish-time workspace dependency bounds."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import ast
6
+ from pathlib import Path
7
+ from typing import Any
8
+
9
+ from hatchling.metadata.plugin.interface import MetadataHookInterface
10
+ from packaging.requirements import Requirement
11
+
12
+ try:
13
+ import tomllib
14
+ except ModuleNotFoundError: # pragma: no cover - Python < 3.11
15
+ import tomli as tomllib # type: ignore[no-redef]
16
+
17
+
18
+ class WorkspaceDependenciesMetadataHook(MetadataHookInterface):
19
+ """Generate package dependencies from the repo-owned dependency table."""
20
+
21
+ def update(self, metadata: dict[str, Any]) -> None:
22
+ """Populate dynamic dependencies for Hatchling metadata generation."""
23
+ pyproject = _load_pyproject(Path(self.root))
24
+ release = pyproject.get("tool", {}).get("vercel", {}).get("release", {})
25
+ dependency_table = release.get("dependencies", {})
26
+ workspace_sources = pyproject.get("tool", {}).get("uv", {}).get("sources", {})
27
+ workspace_names = {
28
+ name for name, source in workspace_sources.items() if source.get("workspace") is True
29
+ }
30
+ workspace_root = _find_workspace_root(Path(self.root))
31
+
32
+ metadata["dependencies"] = [
33
+ _rewrite_dependency(requirement, workspace_names, workspace_root)
34
+ for requirement in dependency_table.get("dependencies", [])
35
+ ]
36
+
37
+
38
+ def _load_pyproject(path: Path) -> dict[str, Any]:
39
+ with (path / "pyproject.toml").open("rb") as fp:
40
+ return tomllib.load(fp)
41
+
42
+
43
+ def _find_workspace_root(start: Path) -> Path | None:
44
+ for path in [start, *start.parents]:
45
+ pyproject = path / "pyproject.toml"
46
+ if not pyproject.exists():
47
+ continue
48
+ data = _load_pyproject(path)
49
+ if "workspace" in data.get("tool", {}).get("uv", {}):
50
+ return path
51
+ return None
52
+
53
+
54
+ def _rewrite_dependency(
55
+ requirement: str,
56
+ workspace_names: set[str],
57
+ workspace_root: Path | None,
58
+ ) -> str:
59
+ parsed = Requirement(requirement)
60
+ normalized = parsed.name.lower().replace("_", "-")
61
+ if normalized not in workspace_names or workspace_root is None:
62
+ return requirement
63
+ return _with_lower_bound(parsed, _read_workspace_version(workspace_root, normalized))
64
+
65
+
66
+ def _with_lower_bound(requirement: Requirement, version: str) -> str:
67
+ extras = f"[{','.join(sorted(requirement.extras))}]" if requirement.extras else ""
68
+ specifiers = [
69
+ str(specifier) for specifier in requirement.specifier if specifier.operator != ">="
70
+ ]
71
+ specifier_text = ",".join([f">={version}", *specifiers])
72
+ marker = f" ; {requirement.marker}" if requirement.marker else ""
73
+ return f"{requirement.name}{extras}{specifier_text}{marker}"
74
+
75
+
76
+ def _read_workspace_version(workspace_root: Path, package_name: str) -> str:
77
+ for pattern in ("src/*/pyproject.toml", "integrations/*/pyproject.toml"):
78
+ for pyproject_path in workspace_root.glob(pattern):
79
+ version = _version_from_pyproject(pyproject_path, package_name)
80
+ if version is not None:
81
+ return version
82
+ raise RuntimeError(f"unknown workspace dependency {package_name!r}")
83
+
84
+
85
+ def _version_from_pyproject(pyproject_path: Path, package_name: str) -> str | None:
86
+ data = _load_pyproject(pyproject_path.parent)
87
+ if data.get("project", {}).get("name") != package_name:
88
+ return None
89
+ version_path = pyproject_path.parent / data["tool"]["hatch"]["version"]["path"]
90
+ module = ast.parse(version_path.read_text(encoding="utf-8"), filename=str(version_path))
91
+ for node in module.body:
92
+ value = _version_value(node)
93
+ if value is None:
94
+ continue
95
+ if isinstance(value, ast.Constant) and isinstance(value.value, str):
96
+ return value.value
97
+ raise RuntimeError(f"could not find __version__ in {version_path}")
98
+
99
+
100
+ def _version_value(node: ast.stmt) -> ast.expr | None:
101
+ if isinstance(node, ast.Assign) and any(
102
+ isinstance(target, ast.Name) and target.id == "__version__" for target in node.targets
103
+ ):
104
+ return node.value
105
+ if (
106
+ isinstance(node, ast.AnnAssign)
107
+ and isinstance(node.target, ast.Name)
108
+ and node.target.id == "__version__"
109
+ ):
110
+ return node.value
111
+ return None
112
+
113
+
114
+ def get_metadata_hook() -> type[MetadataHookInterface]:
115
+ """Return the hook class used by Hatchling's custom hook loader."""
116
+ return WorkspaceDependenciesMetadataHook
@@ -0,0 +1,29 @@
1
+ """Load the shared Vercel Hatch metadata hook."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from importlib.util import module_from_spec, spec_from_file_location
6
+ from pathlib import Path
7
+ from types import ModuleType
8
+
9
+ from hatchling.metadata.plugin.interface import MetadataHookInterface
10
+
11
+
12
+ def get_metadata_hook() -> type[MetadataHookInterface]:
13
+ """Return the shared workspace dependency metadata hook."""
14
+ return _load_shared_hook().get_metadata_hook()
15
+
16
+
17
+ def _load_shared_hook() -> ModuleType:
18
+ root = Path(__file__).resolve().parent
19
+ candidates = [root / "../../scripts/hatch_build.py", root / "_vercel_hatch_build.py"]
20
+ for candidate in candidates:
21
+ path = candidate.resolve()
22
+ if path.exists():
23
+ spec = spec_from_file_location("_vercel_hatch_build", path)
24
+ if spec is None or spec.loader is None:
25
+ raise RuntimeError(f"could not load Hatch hook from {path}")
26
+ module = module_from_spec(spec)
27
+ spec.loader.exec_module(module)
28
+ return module
29
+ raise RuntimeError("could not find shared Vercel Hatch metadata hook")
@@ -0,0 +1,88 @@
1
+ [build-system]
2
+ requires = ["hatchling>=1.27.0,<2"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "vercel-internal-core-bundle"
7
+ dynamic = ["version", "dependencies"]
8
+ description = "Shared internal runtime for Vercel Python packages"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = "MIT"
12
+ license-files = [
13
+ "LICENSE",
14
+ "LICENSE.*",
15
+ "vercel/_internal/core/_vendor/LICEN[CS]E*",
16
+ ]
17
+
18
+ [tool.hatch.metadata.hooks.custom]
19
+ path = "hatch_build.py"
20
+
21
+ [tool.vercel.release.dependencies]
22
+ dependencies = [
23
+ "vercel-internal-shared-vendored-deps>=0.1.0",
24
+ ]
25
+
26
+ [tool.hatch.version]
27
+ path = "vercel/_internal/core/version.py"
28
+
29
+ [tool.hatch.build.targets.sdist]
30
+ force-include = { "_vercel_hatch_build.py" = "/_vercel_hatch_build.py" }
31
+ include = [
32
+ "/vercel/api/**",
33
+ "/vercel/errors/**",
34
+ "/vercel/_internal/core/**",
35
+ "/README.md",
36
+ "/pyproject.toml",
37
+ "/hatch_build.py",
38
+ "/LICENSE",
39
+ "/vercel/_internal/core/_vendor/LICEN[CS]E*",
40
+ ]
41
+ exclude = [
42
+ "/**/__pycache__",
43
+ ]
44
+
45
+ [tool.hatch.build.targets.wheel]
46
+ dev-mode-dirs = ["."]
47
+ only-include = [
48
+ "/vercel/api",
49
+ "/vercel/errors",
50
+ "/vercel/_internal/core",
51
+ ]
52
+ exclude = [
53
+ "/**/__pycache__",
54
+ ]
55
+
56
+ [tool.pytest.ini_options]
57
+ testpaths = ["tests"]
58
+ pythonpath = ["."]
59
+ addopts = "--no-header --capture=tee-sys"
60
+ asyncio_mode = "auto"
61
+
62
+ [tool.poe]
63
+ include = "../../scripts/poe/poe.toml"
64
+ verbosity = -1
65
+
66
+ [tool.mypy]
67
+ cache_dir = "../../.mypy_cache/vercel-internal-core"
68
+ explicit_package_bases = true
69
+ packages = ["vercel._internal.core"]
70
+
71
+ [tool.poe.tasks.typecheck]
72
+ cmd = "$MYPY"
73
+
74
+ [tool.vendoring]
75
+ destination = "vercel/_internal/core/_vendor/"
76
+ requirements = "vercel/_internal/core/_vendor/vendor.txt"
77
+ namespace = "vercel._internal.core._vendor"
78
+ protected-files = [
79
+ "__init__.py",
80
+ "vendor.txt",
81
+ ]
82
+
83
+ [tool.vendoring.transformations]
84
+ drop = [
85
+ "*.so",
86
+ "*/tests/",
87
+ "*/__pycache__/",
88
+ ]
@@ -0,0 +1 @@
1
+ """Shared internal runtime for Vercel-owned Python packages."""
@@ -0,0 +1 @@
1
+ """Generated vendored dependencies for vercel-internal-core-bundle."""
@@ -0,0 +1,258 @@
1
+ """Adapt byte sources for business logic shared by sync and async APIs.
2
+
3
+ Shared code consumes the async-shaped ``ReadableByteStream`` and
4
+ ``StagingByteFile`` protocols. Callers select the runtime matching their public
5
+ API, then use its factories instead of constructing the private adapters directly.
6
+ The sync runtime never suspends, while the async runtime awaits or offloads I/O as
7
+ appropriate.
8
+ """
9
+
10
+ import inspect
11
+ import io
12
+ import sys
13
+ import tempfile
14
+ from collections.abc import AsyncIterator
15
+ from contextlib import AbstractAsyncContextManager, asynccontextmanager
16
+ from typing import Protocol, TypeAlias, cast
17
+
18
+ from vercel.internal._vendor import anyio
19
+
20
+ if sys.version_info >= (3, 12):
21
+ from collections.abc import Buffer
22
+ else:
23
+ from vercel.internal._vendor.typing_extensions import Buffer
24
+
25
+
26
+ class SyncByteReader(Protocol):
27
+ """Caller-provided byte source with a blocking ``read`` method."""
28
+
29
+ def read(self, size: int = -1, /) -> bytes: ...
30
+
31
+
32
+ class AsyncByteReader(Protocol):
33
+ """Caller-provided byte source with an asynchronous ``read`` method.
34
+
35
+ This is structurally identical to ``ReadableByteStream`` but describes an
36
+ input that has not yet been normalized by a byte-stream runtime.
37
+ """
38
+
39
+ async def read(self, size: int = -1, /) -> bytes: ...
40
+
41
+
42
+ BytesLike: TypeAlias = bytes | bytearray | memoryview
43
+ SyncByteSource: TypeAlias = BytesLike | SyncByteReader
44
+ AsyncByteSource: TypeAlias = AsyncByteReader
45
+ RawByteSource: TypeAlias = SyncByteSource | AsyncByteSource
46
+
47
+
48
+ class ReadableByteStream(Protocol):
49
+ """Normalized readable stream consumed by shared internal workflows.
50
+
51
+ Its async shape hides whether a runtime performs the read inline, awaits an
52
+ async source, or moves a blocking read to a worker thread.
53
+ """
54
+
55
+ async def read(self, size: int = -1, /) -> bytes: ...
56
+
57
+
58
+ class StagingByteFile(ReadableByteStream, Protocol):
59
+ """SDK-owned temporary byte file used by shared staging workflows.
60
+
61
+ The runtime's temporary-file context manager owns the lifetime of streams
62
+ implementing this protocol.
63
+ """
64
+
65
+ async def write(self, data: bytes, /) -> int: ...
66
+
67
+ async def readinto(self, buffer: Buffer, /) -> int:
68
+ """Read bytes into a writable buffer.
69
+
70
+ ``Buffer`` cannot express mutability, so read-only buffers are rejected
71
+ at runtime.
72
+ """
73
+ ...
74
+
75
+ async def flush(self) -> None: ...
76
+
77
+ async def tell(self) -> int: ...
78
+
79
+ async def seek(self, offset: int, whence: int = 0, /) -> int: ...
80
+
81
+ async def truncate(self, size: int | None = None, /) -> int: ...
82
+
83
+
84
+ class StagingFileRuntime(Protocol):
85
+ """Runtime-specific temporary-file capability for shared business logic."""
86
+
87
+ def temporary_file(self) -> AbstractAsyncContextManager[StagingByteFile]: ...
88
+
89
+
90
+ def _bytes_result(value: object) -> bytes:
91
+ if isinstance(value, bytes):
92
+ return value
93
+ raise TypeError(f"byte stream returned {type(value).__name__}, expected bytes")
94
+
95
+
96
+ class _SyncReader:
97
+ """Expose a blocking reader through an async-shaped, non-suspending method."""
98
+
99
+ def __init__(self, source: SyncByteReader) -> None:
100
+ self._source = source
101
+
102
+ async def read(self, size: int = -1, /) -> bytes:
103
+ return _bytes_result(self._source.read(size))
104
+
105
+
106
+ class _MemoryReader:
107
+ """Give an immutable bytes snapshot a stateful, non-suspending read cursor."""
108
+
109
+ def __init__(self, data: BytesLike) -> None:
110
+ self._data = memoryview(bytes(data))
111
+ self._offset = 0
112
+
113
+ async def read(self, size: int = -1, /) -> bytes:
114
+ remaining = self._data[self._offset :]
115
+ if size < 0:
116
+ self._offset = len(self._data)
117
+ return bytes(remaining)
118
+ chunk = bytes(remaining[:size])
119
+ self._offset += len(chunk)
120
+ return chunk
121
+
122
+
123
+ class _AsyncReader:
124
+ """Normalize a genuinely asynchronous reader and validate its results."""
125
+
126
+ def __init__(self, source: AsyncByteReader) -> None:
127
+ self._source = source
128
+
129
+ async def read(self, size: int = -1, /) -> bytes:
130
+ return _bytes_result(await self._source.read(size))
131
+
132
+
133
+ class _ThreadedSyncReader:
134
+ """Run a blocking reader on a worker thread for use by async workflows."""
135
+
136
+ def __init__(self, source: SyncByteReader) -> None:
137
+ self._source = source
138
+
139
+ async def read(self, size: int = -1, /) -> bytes:
140
+ return _bytes_result(await anyio.to_thread.run_sync(self._source.read, size))
141
+
142
+
143
+ class _SyncTemporaryFile:
144
+ """Expose a blocking temporary file through non-suspending async methods."""
145
+
146
+ def __init__(self) -> None:
147
+ self._file = cast(io.BufferedRandom, tempfile.TemporaryFile("w+b"))
148
+
149
+ def _ensure_open(self) -> None:
150
+ if self._file.closed:
151
+ raise anyio.ClosedResourceError
152
+
153
+ async def read(self, size: int = -1, /) -> bytes:
154
+ self._ensure_open()
155
+ return self._file.read(size)
156
+
157
+ async def write(self, data: bytes, /) -> int:
158
+ self._ensure_open()
159
+ return self._file.write(data)
160
+
161
+ async def readinto(self, buffer: Buffer, /) -> int:
162
+ """Read bytes into a writable buffer.
163
+
164
+ ``Buffer`` cannot express mutability, so read-only buffers are rejected
165
+ at runtime.
166
+ """
167
+ self._ensure_open()
168
+ return self._file.readinto(buffer)
169
+
170
+ async def flush(self) -> None:
171
+ self._ensure_open()
172
+ self._file.flush()
173
+
174
+ async def tell(self) -> int:
175
+ self._ensure_open()
176
+ return self._file.tell()
177
+
178
+ async def seek(self, offset: int, whence: int = 0, /) -> int:
179
+ self._ensure_open()
180
+ return self._file.seek(offset, whence)
181
+
182
+ async def truncate(self, size: int | None = None, /) -> int:
183
+ self._ensure_open()
184
+ return self._file.truncate(size)
185
+
186
+ def close(self) -> None:
187
+ self._file.close()
188
+
189
+
190
+ @asynccontextmanager
191
+ async def _sync_temporary_file() -> AsyncIterator[StagingByteFile]:
192
+ file = _SyncTemporaryFile()
193
+ try:
194
+ yield file
195
+ finally:
196
+ file.close()
197
+
198
+
199
+ class SyncByteStreamRuntime:
200
+ """Adapt blocking byte primitives for shared async-shaped workflows.
201
+
202
+ Every operation completes without suspending so sync entry points can drive
203
+ the shared coroutine with ``iter_coroutine`` and no event loop.
204
+ """
205
+
206
+ @staticmethod
207
+ def reader(source: SyncByteSource) -> ReadableByteStream:
208
+ if isinstance(source, (bytes, bytearray, memoryview)):
209
+ return _MemoryReader(source)
210
+ read = getattr(source, "read", None)
211
+ if not callable(read):
212
+ raise TypeError("byte source must provide a callable read method")
213
+ if inspect.iscoroutinefunction(read):
214
+ raise TypeError("sync byte stream runtime does not support async readers")
215
+ return _SyncReader(cast(SyncByteReader, source))
216
+
217
+ def temporary_file(self) -> AbstractAsyncContextManager[StagingByteFile]:
218
+ return _sync_temporary_file()
219
+
220
+
221
+ class AsyncByteStreamRuntime:
222
+ """Adapt byte primitives for execution under AnyIO.
223
+
224
+ Async readers are awaited directly, while blocking readers run on a worker
225
+ thread so they do not block the event loop.
226
+ """
227
+
228
+ @staticmethod
229
+ def reader(source: RawByteSource) -> ReadableByteStream:
230
+ if isinstance(source, (bytes, bytearray, memoryview)):
231
+ return _MemoryReader(source)
232
+ read = getattr(source, "read", None)
233
+ if not callable(read):
234
+ raise TypeError("byte source must provide a callable read method")
235
+ if inspect.iscoroutinefunction(read):
236
+ return _AsyncReader(cast(AsyncByteReader, source))
237
+ return _ThreadedSyncReader(cast(SyncByteReader, source))
238
+
239
+ def temporary_file(self) -> AbstractAsyncContextManager[StagingByteFile]:
240
+ return cast(
241
+ AbstractAsyncContextManager[StagingByteFile],
242
+ anyio.TemporaryFile("w+b"),
243
+ )
244
+
245
+
246
+ __all__ = [
247
+ "AsyncByteReader",
248
+ "AsyncByteSource",
249
+ "AsyncByteStreamRuntime",
250
+ "BytesLike",
251
+ "RawByteSource",
252
+ "ReadableByteStream",
253
+ "StagingByteFile",
254
+ "StagingFileRuntime",
255
+ "SyncByteReader",
256
+ "SyncByteSource",
257
+ "SyncByteStreamRuntime",
258
+ ]
@@ -0,0 +1,17 @@
1
+ """Shared errors for Vercel Python services."""
2
+
3
+
4
+ class VercelError(Exception):
5
+ """Base error for Vercel Python SDK failures."""
6
+
7
+
8
+ class VercelSessionError(VercelError):
9
+ """Base error for SDK session failures."""
10
+
11
+
12
+ class VercelSessionClosedError(VercelSessionError):
13
+ """Raised when code uses an SDK session after it has been closed."""
14
+
15
+
16
+ class VercelServiceOptionsError(VercelSessionError):
17
+ """Raised when SDK session service options are invalid."""
@@ -0,0 +1,46 @@
1
+ """Shared HTTP infrastructure for Vercel API clients."""
2
+
3
+ from vercel._internal.core.http.config import DEFAULT_API_BASE_URL, DEFAULT_TIMEOUT
4
+ from vercel._internal.core.http.httpx import (
5
+ create_base_async_client,
6
+ create_base_client,
7
+ )
8
+ from vercel._internal.core.http.retry import (
9
+ RetryPolicy,
10
+ SleepFn,
11
+ )
12
+ from vercel._internal.core.http.transport import (
13
+ AsyncTransport,
14
+ BaseTransport,
15
+ BytesBody,
16
+ JSONBody,
17
+ RawBody,
18
+ ReadResponsePolicy,
19
+ RequestBody,
20
+ StreamingRequest,
21
+ StreamingResponse,
22
+ SyncTransport,
23
+ TransportOptions,
24
+ extract_structured_error,
25
+ )
26
+
27
+ __all__ = [
28
+ "DEFAULT_API_BASE_URL",
29
+ "DEFAULT_TIMEOUT",
30
+ "BaseTransport",
31
+ "SyncTransport",
32
+ "AsyncTransport",
33
+ "TransportOptions",
34
+ "JSONBody",
35
+ "BytesBody",
36
+ "RawBody",
37
+ "ReadResponsePolicy",
38
+ "RequestBody",
39
+ "StreamingRequest",
40
+ "StreamingResponse",
41
+ "RetryPolicy",
42
+ "SleepFn",
43
+ "create_base_client",
44
+ "create_base_async_client",
45
+ "extract_structured_error",
46
+ ]
@@ -0,0 +1,9 @@
1
+ """HTTP configuration constants shared by Vercel API clients."""
2
+
3
+ from datetime import timedelta
4
+
5
+ DEFAULT_API_BASE_URL = "https://api.vercel.com"
6
+ DEFAULT_TIMEOUT = timedelta(seconds=60)
7
+
8
+
9
+ __all__ = ["DEFAULT_API_BASE_URL", "DEFAULT_TIMEOUT"]