diff --git a/pyproject.toml b/pyproject.toml index cc6428b..c209cf5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ name = "scrapybara" [tool.poetry] name = "scrapybara" -version = "2.4.5" +version = "2.4.6" description = "" readme = "README.md" authors = [] diff --git a/reference.md b/reference.md index 051386b..3e91211 100644 --- a/reference.md +++ b/reference.md @@ -608,7 +608,7 @@ client.instance.edit( -
client.instance.filesystem(...) +
client.instance.file(...)
@@ -626,7 +626,7 @@ from scrapybara import Scrapybara client = Scrapybara( api_key="YOUR_API_KEY", ) -client.instance.filesystem( +client.instance.file( instance_id="instance_id", command="command", ) @@ -1996,301 +1996,6 @@ client.notebook.execute(
- - -
- -## File -
client.file.read(...) -
-
- -#### 🔌 Usage - -
-
- -
-
- -```python -from scrapybara import Scrapybara - -client = Scrapybara( - api_key="YOUR_API_KEY", -) -client.file.read( - instance_id="instance_id", - path="path", -) - -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**instance_id:** `str` - -
-
- -
-
- -**path:** `str` - -
-
- -
-
- -**encoding:** `typing.Optional[str]` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.file.write(...) -
-
- -#### 🔌 Usage - -
-
- -
-
- -```python -from scrapybara import Scrapybara - -client = Scrapybara( - api_key="YOUR_API_KEY", -) -client.file.write( - instance_id="instance_id", - path="path", - content="content", -) - -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**instance_id:** `str` - -
-
- -
-
- -**path:** `str` - -
-
- -
-
- -**content:** `str` - -
-
- -
-
- -**encoding:** `typing.Optional[str]` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.file.upload(...) -
-
- -#### 🔌 Usage - -
-
- -
-
- -```python -from scrapybara import Scrapybara - -client = Scrapybara( - api_key="YOUR_API_KEY", -) -client.file.upload( - instance_id="instance_id", - path="path", - content="content", -) - -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**instance_id:** `str` - -
-
- -
-
- -**path:** `str` - -
-
- -
-
- -**content:** `str` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration. - -
-
-
-
- - -
-
-
- -
client.file.download(...) -
-
- -#### 🔌 Usage - -
-
- -
-
- -```python -from scrapybara import Scrapybara - -client = Scrapybara( - api_key="YOUR_API_KEY", -) -client.file.download( - instance_id="instance_id", - path="path", -) - -``` -
-
-
-
- -#### ⚙️ Parameters - -
-
- -
-
- -**instance_id:** `str` - -
-
- -
-
- -**path:** `str` - -
-
- -
-
- -**request_options:** `typing.Optional[RequestOptions]` — Request-specific configuration. - -
-
-
-
- -
diff --git a/src/scrapybara/__init__.py b/src/scrapybara/__init__.py index 02e6e49..4cbd33f 100644 --- a/src/scrapybara/__init__.py +++ b/src/scrapybara/__init__.py @@ -17,9 +17,7 @@ EnvGetResponse, EnvResponse, ExecuteCellRequest, - FileDownloadResponse, - FileReadResponse, - FilesystemResponse, + FileResponse, GetCursorPositionAction, GetInstanceResponse, GetInstanceResponseInstanceType, @@ -45,7 +43,7 @@ WaitAction, ) from .errors import UnprocessableEntityError -from . import browser, code, env, file, instance, notebook +from . import browser, code, env, instance, notebook from .client import AsyncScrapybara, Scrapybara from .environment import ScrapybaraEnvironment from .instance import ( @@ -82,9 +80,7 @@ "EnvGetResponse", "EnvResponse", "ExecuteCellRequest", - "FileDownloadResponse", - "FileReadResponse", - "FilesystemResponse", + "FileResponse", "GetCursorPositionAction", "GetInstanceResponse", "GetInstanceResponseInstanceType", @@ -125,7 +121,6 @@ "browser", "code", "env", - "file", "instance", "notebook", ] diff --git a/src/scrapybara/base_client.py b/src/scrapybara/base_client.py index 29e6ec6..9661a10 100644 --- a/src/scrapybara/base_client.py +++ b/src/scrapybara/base_client.py @@ -10,7 +10,6 @@ from .browser.client import BrowserClient from .code.client import CodeClient from .notebook.client import NotebookClient -from .file.client import FileClient from .env.client import EnvClient from .types.deployment_config_instance_type import DeploymentConfigInstanceType from .core.request_options import RequestOptions @@ -26,7 +25,6 @@ from .browser.client import AsyncBrowserClient from .code.client import AsyncCodeClient from .notebook.client import AsyncNotebookClient -from .file.client import AsyncFileClient from .env.client import AsyncEnvClient # this is used as the default value for optional parameters @@ -99,7 +97,6 @@ def __init__( self.browser = BrowserClient(client_wrapper=self._client_wrapper) self.code = CodeClient(client_wrapper=self._client_wrapper) self.notebook = NotebookClient(client_wrapper=self._client_wrapper) - self.file = FileClient(client_wrapper=self._client_wrapper) self.env = EnvClient(client_wrapper=self._client_wrapper) def start( @@ -383,7 +380,6 @@ def __init__( self.browser = AsyncBrowserClient(client_wrapper=self._client_wrapper) self.code = AsyncCodeClient(client_wrapper=self._client_wrapper) self.notebook = AsyncNotebookClient(client_wrapper=self._client_wrapper) - self.file = AsyncFileClient(client_wrapper=self._client_wrapper) self.env = AsyncEnvClient(client_wrapper=self._client_wrapper) async def start( diff --git a/src/scrapybara/client.py b/src/scrapybara/client.py index f65c338..b449a1b 100644 --- a/src/scrapybara/client.py +++ b/src/scrapybara/client.py @@ -38,8 +38,6 @@ CellType, EnvGetResponse, EnvResponse, - FileDownloadResponse, - FileReadResponse, GetInstanceResponse, InstanceGetStreamUrlResponse, InstanceScreenshotResponse, @@ -475,120 +473,6 @@ async def execute( ) -class File: - def __init__(self, instance_id: str, client: BaseClient): - self.instance_id = instance_id - self._client = client - - def read( - self, - *, - path: str, - encoding: Optional[str] = OMIT, - request_options: Optional[RequestOptions] = None, - ) -> FileReadResponse: - return self._client.file.read( - self.instance_id, - path=path, - encoding=encoding, - request_options=request_options, - ) - - def write( - self, - *, - path: str, - content: str, - encoding: Optional[str] = OMIT, - request_options: Optional[RequestOptions] = None, - ) -> Dict[str, Optional[Any]]: - return self._client.file.write( - self.instance_id, - path=path, - content=content, - encoding=encoding, - request_options=request_options, - ) - - def upload( - self, - *, - path: str, - content: str, - request_options: Optional[RequestOptions] = None, - ) -> Dict[str, Optional[Any]]: - return self._client.file.upload( - self.instance_id, - path=path, - content=content, - request_options=request_options, - ) - - def download( - self, *, path: str, request_options: Optional[RequestOptions] = None - ) -> FileDownloadResponse: - return self._client.file.download( - self.instance_id, path=path, request_options=request_options - ) - - -class AsyncFile: - def __init__(self, instance_id: str, client: AsyncBaseClient): - self.instance_id = instance_id - self._client = client - - async def read( - self, - *, - path: str, - encoding: Optional[str] = OMIT, - request_options: Optional[RequestOptions] = None, - ) -> FileReadResponse: - return await self._client.file.read( - self.instance_id, - path=path, - encoding=encoding, - request_options=request_options, - ) - - async def write( - self, - *, - path: str, - content: str, - encoding: Optional[str] = OMIT, - request_options: Optional[RequestOptions] = None, - ) -> Dict[str, Optional[Any]]: - return await self._client.file.write( - self.instance_id, - path=path, - content=content, - encoding=encoding, - request_options=request_options, - ) - - async def upload( - self, - *, - path: str, - content: str, - request_options: Optional[RequestOptions] = None, - ) -> Dict[str, Optional[Any]]: - return await self._client.file.upload( - self.instance_id, - path=path, - content=content, - request_options=request_options, - ) - - async def download( - self, *, path: str, request_options: Optional[RequestOptions] = None - ) -> FileDownloadResponse: - return await self._client.file.download( - self.instance_id, path=path, request_options=request_options - ) - - class Env: def __init__(self, instance_id: str, client: BaseClient): self.instance_id = instance_id @@ -990,7 +874,6 @@ def __init__( self.browser = Browser(self.id, self._client) self.code = Code(self.id, self._client) self.notebook = Notebook(self.id, self._client) - self.file = File(self.id, self._client) self.env = Env(self.id, self._client) def bash( @@ -1035,7 +918,7 @@ def edit( request_options=request_options, ) - async def filesystem( + async def file( self, *, command: str, @@ -1058,7 +941,7 @@ async def filesystem( line_numbers: Optional[bool] = OMIT, request_options: Optional[RequestOptions] = None, ) -> Optional[Any]: - return self._client.instance.filesystem( + return self._client.instance.file( self.id, command=command, path=path, @@ -1499,7 +1382,6 @@ def __init__( self.browser = AsyncBrowser(self.id, self._client) self.code = AsyncCode(self.id, self._client) self.notebook = AsyncNotebook(self.id, self._client) - self.file = AsyncFile(self.id, self._client) self.env = AsyncEnv(self.id, self._client) async def bash( @@ -1544,7 +1426,7 @@ async def edit( request_options=request_options, ) - async def filesystem( + async def file( self, *, command: str, @@ -1567,7 +1449,7 @@ async def filesystem( line_numbers: Optional[bool] = OMIT, request_options: Optional[RequestOptions] = None, ) -> Optional[Any]: - return await self._client.instance.filesystem( + return await self._client.instance.file( self.id, command=command, path=path, diff --git a/src/scrapybara/core/client_wrapper.py b/src/scrapybara/core/client_wrapper.py index 7f61153..014b963 100644 --- a/src/scrapybara/core/client_wrapper.py +++ b/src/scrapybara/core/client_wrapper.py @@ -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.5", + "X-Fern-SDK-Version": "2.4.6", } headers["x-api-key"] = self.api_key return headers diff --git a/src/scrapybara/file/__init__.py b/src/scrapybara/file/__init__.py deleted file mode 100644 index f3ea265..0000000 --- a/src/scrapybara/file/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - diff --git a/src/scrapybara/file/client.py b/src/scrapybara/file/client.py deleted file mode 100644 index 1178b3b..0000000 --- a/src/scrapybara/file/client.py +++ /dev/null @@ -1,621 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -import typing -from ..core.client_wrapper import SyncClientWrapper -from ..core.request_options import RequestOptions -from ..types.file_read_response import FileReadResponse -from ..core.jsonable_encoder import jsonable_encoder -from ..core.pydantic_utilities import parse_obj_as -from ..errors.unprocessable_entity_error import UnprocessableEntityError -from ..types.http_validation_error import HttpValidationError -from json.decoder import JSONDecodeError -from ..core.api_error import ApiError -from ..types.file_download_response import FileDownloadResponse -from ..core.client_wrapper import AsyncClientWrapper - -# this is used as the default value for optional parameters -OMIT = typing.cast(typing.Any, ...) - - -class FileClient: - def __init__(self, *, client_wrapper: SyncClientWrapper): - self._client_wrapper = client_wrapper - - def read( - self, - instance_id: str, - *, - path: str, - encoding: typing.Optional[str] = None, - request_options: typing.Optional[RequestOptions] = None, - ) -> FileReadResponse: - """ - Parameters - ---------- - instance_id : str - - path : str - - encoding : typing.Optional[str] - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - FileReadResponse - Successful Response - - Examples - -------- - from scrapybara import Scrapybara - - client = Scrapybara( - api_key="YOUR_API_KEY", - ) - client.file.read( - instance_id="instance_id", - path="path", - ) - """ - _response = self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/file/read", - method="GET", - params={ - "path": path, - "encoding": encoding, - }, - request_options=request_options, - ) - try: - if 200 <= _response.status_code < 300: - return typing.cast( - FileReadResponse, - parse_obj_as( - type_=FileReadResponse, # type: ignore - object_=_response.json(), - ), - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast( - HttpValidationError, - parse_obj_as( - type_=HttpValidationError, # type: ignore - object_=_response.json(), - ), - ) - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, body=_response.text) - raise ApiError(status_code=_response.status_code, body=_response_json) - - def write( - self, - instance_id: str, - *, - path: str, - content: str, - encoding: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, - ) -> typing.Dict[str, typing.Optional[typing.Any]]: - """ - Parameters - ---------- - instance_id : str - - path : str - - content : str - - encoding : typing.Optional[str] - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - typing.Dict[str, typing.Optional[typing.Any]] - Successful Response - - Examples - -------- - from scrapybara import Scrapybara - - client = Scrapybara( - api_key="YOUR_API_KEY", - ) - client.file.write( - instance_id="instance_id", - path="path", - content="content", - ) - """ - _response = self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/file/write", - method="POST", - json={ - "path": path, - "content": content, - "encoding": encoding, - }, - headers={ - "content-type": "application/json", - }, - request_options=request_options, - omit=OMIT, - ) - try: - if 200 <= _response.status_code < 300: - return typing.cast( - typing.Dict[str, typing.Optional[typing.Any]], - parse_obj_as( - type_=typing.Dict[str, typing.Optional[typing.Any]], # type: ignore - object_=_response.json(), - ), - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast( - HttpValidationError, - parse_obj_as( - type_=HttpValidationError, # type: ignore - object_=_response.json(), - ), - ) - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, body=_response.text) - raise ApiError(status_code=_response.status_code, body=_response_json) - - def upload( - self, instance_id: str, *, path: str, content: str, request_options: typing.Optional[RequestOptions] = None - ) -> typing.Dict[str, typing.Optional[typing.Any]]: - """ - Parameters - ---------- - instance_id : str - - path : str - - content : str - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - typing.Dict[str, typing.Optional[typing.Any]] - Successful Response - - Examples - -------- - from scrapybara import Scrapybara - - client = Scrapybara( - api_key="YOUR_API_KEY", - ) - client.file.upload( - instance_id="instance_id", - path="path", - content="content", - ) - """ - _response = self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/file/upload", - method="POST", - json={ - "path": path, - "content": content, - }, - headers={ - "content-type": "application/json", - }, - request_options=request_options, - omit=OMIT, - ) - try: - if 200 <= _response.status_code < 300: - return typing.cast( - typing.Dict[str, typing.Optional[typing.Any]], - parse_obj_as( - type_=typing.Dict[str, typing.Optional[typing.Any]], # type: ignore - object_=_response.json(), - ), - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast( - HttpValidationError, - parse_obj_as( - type_=HttpValidationError, # type: ignore - object_=_response.json(), - ), - ) - ) - _response_json = _response.json() - except JSONDecodeError: - 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 - ) -> FileDownloadResponse: - """ - Parameters - ---------- - instance_id : str - - path : str - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - FileDownloadResponse - Successful Response - - Examples - -------- - from scrapybara import Scrapybara - - client = Scrapybara( - api_key="YOUR_API_KEY", - ) - client.file.download( - instance_id="instance_id", - path="path", - ) - """ - _response = self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/file/download", - method="GET", - params={ - "path": path, - }, - request_options=request_options, - ) - try: - if 200 <= _response.status_code < 300: - return typing.cast( - FileDownloadResponse, - parse_obj_as( - type_=FileDownloadResponse, # type: ignore - object_=_response.json(), - ), - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast( - HttpValidationError, - parse_obj_as( - type_=HttpValidationError, # type: ignore - object_=_response.json(), - ), - ) - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, body=_response.text) - raise ApiError(status_code=_response.status_code, body=_response_json) - - -class AsyncFileClient: - def __init__(self, *, client_wrapper: AsyncClientWrapper): - self._client_wrapper = client_wrapper - - async def read( - self, - instance_id: str, - *, - path: str, - encoding: typing.Optional[str] = None, - request_options: typing.Optional[RequestOptions] = None, - ) -> FileReadResponse: - """ - Parameters - ---------- - instance_id : str - - path : str - - encoding : typing.Optional[str] - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - FileReadResponse - Successful Response - - Examples - -------- - import asyncio - - from scrapybara import AsyncScrapybara - - client = AsyncScrapybara( - api_key="YOUR_API_KEY", - ) - - - async def main() -> None: - await client.file.read( - instance_id="instance_id", - path="path", - ) - - - asyncio.run(main()) - """ - _response = await self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/file/read", - method="GET", - params={ - "path": path, - "encoding": encoding, - }, - request_options=request_options, - ) - try: - if 200 <= _response.status_code < 300: - return typing.cast( - FileReadResponse, - parse_obj_as( - type_=FileReadResponse, # type: ignore - object_=_response.json(), - ), - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast( - HttpValidationError, - parse_obj_as( - type_=HttpValidationError, # type: ignore - object_=_response.json(), - ), - ) - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, body=_response.text) - raise ApiError(status_code=_response.status_code, body=_response_json) - - async def write( - self, - instance_id: str, - *, - path: str, - content: str, - encoding: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, - ) -> typing.Dict[str, typing.Optional[typing.Any]]: - """ - Parameters - ---------- - instance_id : str - - path : str - - content : str - - encoding : typing.Optional[str] - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - typing.Dict[str, typing.Optional[typing.Any]] - Successful Response - - Examples - -------- - import asyncio - - from scrapybara import AsyncScrapybara - - client = AsyncScrapybara( - api_key="YOUR_API_KEY", - ) - - - async def main() -> None: - await client.file.write( - instance_id="instance_id", - path="path", - content="content", - ) - - - asyncio.run(main()) - """ - _response = await self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/file/write", - method="POST", - json={ - "path": path, - "content": content, - "encoding": encoding, - }, - headers={ - "content-type": "application/json", - }, - request_options=request_options, - omit=OMIT, - ) - try: - if 200 <= _response.status_code < 300: - return typing.cast( - typing.Dict[str, typing.Optional[typing.Any]], - parse_obj_as( - type_=typing.Dict[str, typing.Optional[typing.Any]], # type: ignore - object_=_response.json(), - ), - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast( - HttpValidationError, - parse_obj_as( - type_=HttpValidationError, # type: ignore - object_=_response.json(), - ), - ) - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, body=_response.text) - raise ApiError(status_code=_response.status_code, body=_response_json) - - async def upload( - self, instance_id: str, *, path: str, content: str, request_options: typing.Optional[RequestOptions] = None - ) -> typing.Dict[str, typing.Optional[typing.Any]]: - """ - Parameters - ---------- - instance_id : str - - path : str - - content : str - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - typing.Dict[str, typing.Optional[typing.Any]] - Successful Response - - Examples - -------- - import asyncio - - from scrapybara import AsyncScrapybara - - client = AsyncScrapybara( - api_key="YOUR_API_KEY", - ) - - - async def main() -> None: - await client.file.upload( - instance_id="instance_id", - path="path", - content="content", - ) - - - asyncio.run(main()) - """ - _response = await self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/file/upload", - method="POST", - json={ - "path": path, - "content": content, - }, - headers={ - "content-type": "application/json", - }, - request_options=request_options, - omit=OMIT, - ) - try: - if 200 <= _response.status_code < 300: - return typing.cast( - typing.Dict[str, typing.Optional[typing.Any]], - parse_obj_as( - type_=typing.Dict[str, typing.Optional[typing.Any]], # type: ignore - object_=_response.json(), - ), - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast( - HttpValidationError, - parse_obj_as( - type_=HttpValidationError, # type: ignore - object_=_response.json(), - ), - ) - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, body=_response.text) - 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 - ) -> FileDownloadResponse: - """ - Parameters - ---------- - instance_id : str - - path : str - - request_options : typing.Optional[RequestOptions] - Request-specific configuration. - - Returns - ------- - FileDownloadResponse - Successful Response - - Examples - -------- - import asyncio - - from scrapybara import AsyncScrapybara - - client = AsyncScrapybara( - api_key="YOUR_API_KEY", - ) - - - async def main() -> None: - await client.file.download( - instance_id="instance_id", - path="path", - ) - - - asyncio.run(main()) - """ - _response = await self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/file/download", - method="GET", - params={ - "path": path, - }, - request_options=request_options, - ) - try: - if 200 <= _response.status_code < 300: - return typing.cast( - FileDownloadResponse, - parse_obj_as( - type_=FileDownloadResponse, # type: ignore - object_=_response.json(), - ), - ) - if _response.status_code == 422: - raise UnprocessableEntityError( - typing.cast( - HttpValidationError, - parse_obj_as( - type_=HttpValidationError, # type: ignore - object_=_response.json(), - ), - ) - ) - _response_json = _response.json() - except JSONDecodeError: - raise ApiError(status_code=_response.status_code, body=_response.text) - raise ApiError(status_code=_response.status_code, body=_response_json) diff --git a/src/scrapybara/instance/client.py b/src/scrapybara/instance/client.py index 3ef7a22..2ea47ac 100644 --- a/src/scrapybara/instance/client.py +++ b/src/scrapybara/instance/client.py @@ -17,7 +17,7 @@ from ..types.bash_response import BashResponse from .types.command import Command from ..types.edit_response import EditResponse -from ..types.filesystem_response import FilesystemResponse +from ..types.file_response import FileResponse from ..types.stop_instance_response import StopInstanceResponse from ..types.get_instance_response import GetInstanceResponse from ..core.client_wrapper import AsyncClientWrapper @@ -382,7 +382,7 @@ def edit( raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) - def filesystem( + def file( self, instance_id: str, *, @@ -405,7 +405,7 @@ def filesystem( case_sensitive: typing.Optional[bool] = OMIT, line_numbers: typing.Optional[bool] = OMIT, request_options: typing.Optional[RequestOptions] = None, - ) -> FilesystemResponse: + ) -> FileResponse: """ Parameters ---------- @@ -452,7 +452,7 @@ def filesystem( Returns ------- - FilesystemResponse + FileResponse Successful Response Examples @@ -462,13 +462,13 @@ def filesystem( client = Scrapybara( api_key="YOUR_API_KEY", ) - client.instance.filesystem( + client.instance.file( instance_id="instance_id", command="command", ) """ _response = self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/filesystem", + f"v1/instance/{jsonable_encoder(instance_id)}/file", method="POST", json={ "command": command, @@ -499,9 +499,9 @@ def filesystem( try: if 200 <= _response.status_code < 300: return typing.cast( - FilesystemResponse, + FileResponse, parse_obj_as( - type_=FilesystemResponse, # type: ignore + type_=FileResponse, # type: ignore object_=_response.json(), ), ) @@ -1094,7 +1094,7 @@ async def main() -> None: raise ApiError(status_code=_response.status_code, body=_response.text) raise ApiError(status_code=_response.status_code, body=_response_json) - async def filesystem( + async def file( self, instance_id: str, *, @@ -1117,7 +1117,7 @@ async def filesystem( case_sensitive: typing.Optional[bool] = OMIT, line_numbers: typing.Optional[bool] = OMIT, request_options: typing.Optional[RequestOptions] = None, - ) -> FilesystemResponse: + ) -> FileResponse: """ Parameters ---------- @@ -1164,7 +1164,7 @@ async def filesystem( Returns ------- - FilesystemResponse + FileResponse Successful Response Examples @@ -1179,7 +1179,7 @@ async def filesystem( async def main() -> None: - await client.instance.filesystem( + await client.instance.file( instance_id="instance_id", command="command", ) @@ -1188,7 +1188,7 @@ async def main() -> None: asyncio.run(main()) """ _response = await self._client_wrapper.httpx_client.request( - f"v1/instance/{jsonable_encoder(instance_id)}/filesystem", + f"v1/instance/{jsonable_encoder(instance_id)}/file", method="POST", json={ "command": command, @@ -1219,9 +1219,9 @@ async def main() -> None: try: if 200 <= _response.status_code < 300: return typing.cast( - FilesystemResponse, + FileResponse, parse_obj_as( - type_=FilesystemResponse, # type: ignore + type_=FileResponse, # type: ignore object_=_response.json(), ), ) diff --git a/src/scrapybara/types/__init__.py b/src/scrapybara/types/__init__.py index 8221f74..40c71b8 100644 --- a/src/scrapybara/types/__init__.py +++ b/src/scrapybara/types/__init__.py @@ -15,9 +15,7 @@ from .env_get_response import EnvGetResponse from .env_response import EnvResponse from .execute_cell_request import ExecuteCellRequest -from .file_download_response import FileDownloadResponse -from .file_read_response import FileReadResponse -from .filesystem_response import FilesystemResponse +from .file_response import FileResponse from .get_cursor_position_action import GetCursorPositionAction from .get_instance_response import GetInstanceResponse from .get_instance_response_instance_type import GetInstanceResponseInstanceType @@ -92,9 +90,7 @@ "EnvGetResponse", "EnvResponse", "ExecuteCellRequest", - "FileDownloadResponse", - "FileReadResponse", - "FilesystemResponse", + "FileResponse", "GetCursorPositionAction", "GetInstanceResponse", "GetInstanceResponseInstanceType", diff --git a/src/scrapybara/types/file_download_response.py b/src/scrapybara/types/file_download_response.py deleted file mode 100644 index 34e48bf..0000000 --- a/src/scrapybara/types/file_download_response.py +++ /dev/null @@ -1,19 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -from ..core.pydantic_utilities import UniversalBaseModel -from ..core.pydantic_utilities import IS_PYDANTIC_V2 -import typing -import pydantic - - -class FileDownloadResponse(UniversalBaseModel): - content: str - - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow diff --git a/src/scrapybara/types/file_read_response.py b/src/scrapybara/types/file_read_response.py deleted file mode 100644 index 53f78f4..0000000 --- a/src/scrapybara/types/file_read_response.py +++ /dev/null @@ -1,19 +0,0 @@ -# This file was auto-generated by Fern from our API Definition. - -from ..core.pydantic_utilities import UniversalBaseModel -from ..core.pydantic_utilities import IS_PYDANTIC_V2 -import typing -import pydantic - - -class FileReadResponse(UniversalBaseModel): - content: str - - if IS_PYDANTIC_V2: - model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow", frozen=True) # type: ignore # Pydantic v2 - else: - - class Config: - frozen = True - smart_union = True - extra = pydantic.Extra.allow diff --git a/src/scrapybara/types/filesystem_response.py b/src/scrapybara/types/file_response.py similarity index 90% rename from src/scrapybara/types/filesystem_response.py rename to src/scrapybara/types/file_response.py index a9d9f8b..3ded716 100644 --- a/src/scrapybara/types/filesystem_response.py +++ b/src/scrapybara/types/file_response.py @@ -8,9 +8,9 @@ import pydantic -class FilesystemResponse(UniversalBaseModel): +class FileResponse(UniversalBaseModel): """ - Response model for filesystem actions. + Response model for file actions. """ output: typing.Optional[str] = None