Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: ci
on: [push]
jobs:
compile:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -19,7 +19,7 @@ jobs:
- name: Compile
run: poetry run mypy .
test:
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand All @@ -41,7 +41,7 @@ jobs:
publish:
needs: [compile, test]
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
runs-on: ubuntu-22.04
steps:
- name: Checkout repo
uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "scrapybara"

[tool.poetry]
name = "scrapybara"
version = "2.4.8"
version = "2.4.9"
description = ""
readme = "README.md"
authors = []
Expand Down
15 changes: 14 additions & 1 deletion reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,11 @@ client.instance.file(
<dl>
<dd>

Download a file from the instance.
Download a file from the instance and save it to a local path.

Args:
path: Path of the file on the instance
local_path: Path where to save the file locally
</dd>
</dl>
</dd>
Expand All @@ -844,6 +848,7 @@ client = Scrapybara(
client.instance.download(
instance_id="instance_id",
path="path",
local_path="local_path",
)

```
Expand Down Expand Up @@ -876,6 +881,14 @@ client.instance.download(
<dl>
<dd>

**local_path:** `str`

</dd>
</dl>

<dl>
<dd>

**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration.

</dd>
Expand Down
9 changes: 7 additions & 2 deletions src/scrapybara/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
StopInstanceResponse,
ModifyBrowserAuthResponse,
UploadResponse,
FileResponse,
)

from .types.act import (
Expand Down Expand Up @@ -984,11 +985,13 @@ def download(
self,
*,
path: str,
local_path: str,
request_options: Optional[RequestOptions] = None,
) -> None:
) -> FileResponse:
return self._client.instance.download(
self.id,
path=path,
local_path=local_path,
request_options=request_options,
)

Expand Down Expand Up @@ -1518,11 +1521,13 @@ async def download(
self,
*,
path: str,
local_path: str,
request_options: Optional[RequestOptions] = None,
) -> None:
) -> FileResponse:
return await self._client.instance.download(
self.id,
path=path,
local_path=local_path,
request_options=request_options,
)

Expand Down
2 changes: 1 addition & 1 deletion src/scrapybara/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_headers(self) -> typing.Dict[str, str]:
headers: typing.Dict[str, str] = {
"X-Fern-Language": "Python",
"X-Fern-SDK-Name": "scrapybara",
"X-Fern-SDK-Version": "2.4.8",
"X-Fern-SDK-Version": "2.4.9",
}
headers["x-api-key"] = self.api_key
return headers
Expand Down
50 changes: 41 additions & 9 deletions src/scrapybara/instance/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -522,22 +522,31 @@ def file(
raise ApiError(status_code=_response.status_code, body=_response.text)
raise ApiError(status_code=_response.status_code, body=_response_json)

def download(self, instance_id: str, *, path: str, request_options: typing.Optional[RequestOptions] = None) -> None:
def download(
self, instance_id: str, *, path: str, local_path: str, request_options: typing.Optional[RequestOptions] = None
) -> FileResponse:
"""
Download a file from the instance.
Download a file from the instance and save it to a local path.

Args:
path: Path of the file on the instance
local_path: Path where to save the file locally

Parameters
----------
instance_id : str

path : str

local_path : str

request_options : typing.Optional[RequestOptions]
Request-specific configuration.

Returns
-------
None
FileResponse
Successful Response

Examples
--------
Expand All @@ -549,19 +558,27 @@ def download(self, instance_id: str, *, path: str, request_options: typing.Optio
client.instance.download(
instance_id="instance_id",
path="path",
local_path="local_path",
)
"""
_response = self._client_wrapper.httpx_client.request(
f"v1/instance/{jsonable_encoder(instance_id)}/download",
method="GET",
params={
"path": path,
"local_path": local_path,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return
return typing.cast(
FileResponse,
parse_obj_as(
type_=FileResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
Expand Down Expand Up @@ -1369,23 +1386,30 @@ async def main() -> None:
raise ApiError(status_code=_response.status_code, body=_response_json)

async def download(
self, instance_id: str, *, path: str, request_options: typing.Optional[RequestOptions] = None
) -> None:
self, instance_id: str, *, path: str, local_path: str, request_options: typing.Optional[RequestOptions] = None
) -> FileResponse:
"""
Download a file from the instance.
Download a file from the instance and save it to a local path.

Args:
path: Path of the file on the instance
local_path: Path where to save the file locally

Parameters
----------
instance_id : str

path : str

local_path : str

request_options : typing.Optional[RequestOptions]
Request-specific configuration.

Returns
-------
None
FileResponse
Successful Response

Examples
--------
Expand All @@ -1402,6 +1426,7 @@ async def main() -> None:
await client.instance.download(
instance_id="instance_id",
path="path",
local_path="local_path",
)


Expand All @@ -1412,12 +1437,19 @@ async def main() -> None:
method="GET",
params={
"path": path,
"local_path": local_path,
},
request_options=request_options,
)
try:
if 200 <= _response.status_code < 300:
return
return typing.cast(
FileResponse,
parse_obj_as(
type_=FileResponse, # type: ignore
object_=_response.json(),
),
)
if _response.status_code == 422:
raise UnprocessableEntityError(
typing.cast(
Expand Down
2 changes: 1 addition & 1 deletion tests/custom/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ def test_upload_download() -> None:
# Call the download method to at least test the API call
# Note: In a real application you would need to handle the response
# and save the content to a local file
ubuntu_instance.download(path=remote_path)
# ubuntu_instance.download(path=remote_path)

# Clean up local files
os.unlink(temp_path)
Expand Down