Skip to content

Commit 1663641

Browse files
chore(internal): codegen related update (#52)
1 parent 9a1d74d commit 1663641

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,24 @@ for document in first_page.items:
150150
# Remove `await` for non-async usage.
151151
```
152152

153+
## File uploads
154+
155+
Request parameters that correspond to file uploads can be passed as `bytes`, a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
156+
157+
```python
158+
from pathlib import Path
159+
from hyperspell import Hyperspell
160+
161+
client = Hyperspell()
162+
163+
client.documents.upload(
164+
collection="collection",
165+
file=Path("/path/to/file"),
166+
)
167+
```
168+
169+
The async client uses the exact same interface. If you pass a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance, the file contents will be read asynchronously automatically.
170+
153171
## Handling errors
154172

155173
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `hyperspell.APIConnectionError` is raised.

src/hyperspell/_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def assert_is_file_content(obj: object, *, key: str | None = None) -> None:
3434
if not is_file_content(obj):
3535
prefix = f"Expected entry at `{key}`" if key is not None else f"Expected file input `{obj!r}`"
3636
raise RuntimeError(
37-
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead."
37+
f"{prefix} to be bytes, an io.IOBase instance, PathLike or a tuple but received {type(obj)} instead. See https://github.com/hyperspell/python-sdk/tree/main#file-uploads"
3838
) from None
3939

4040

0 commit comments

Comments
 (0)