Skip to content
Closed
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
247 changes: 2 additions & 245 deletions poetry.lock

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[project]
name = "scrapybara"

[tool.poetry]
name = "scrapybara"
version = "2.2.9"
version = "2.3.0"
description = ""
readme = "README.md"
authors = []
Expand Down Expand Up @@ -32,9 +35,7 @@ Repository = 'https://github.com/scrapybara/scrapybara-python'

[tool.poetry.dependencies]
python = "^3.8"
anthropic = "^0.47.2"
httpx = ">=0.21.2"
playwright = "^1.48.0"
pydantic = ">= 1.9.2"
pydantic-core = "^2.18.2"
typing_extensions = ">= 4.0.0"
Expand Down
23 changes: 5 additions & 18 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,13 +336,16 @@ client.instance.get_stream_url(

```python
from scrapybara import Scrapybara
from scrapybara.instance import Request_MoveMouse

client = Scrapybara(
api_key="YOUR_API_KEY",
)
client.instance.computer(
instance_id="instance_id",
action="key",
request=Request_MoveMouse(
coordinates=[1],
),
)

```
Expand All @@ -367,23 +370,7 @@ client.instance.computer(
<dl>
<dd>

**action:** `Action`

</dd>
</dl>

<dl>
<dd>

**coordinate:** `typing.Optional[typing.Sequence[int]]`

</dd>
</dl>

<dl>
<dd>

**text:** `typing.Optional[str]`
**request:** `Request`

</dd>
</dl>
Expand Down
4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
httpx>=0.21.2
pydantic>= 1.9.2
pydantic-core==^2.18.2
typing_extensions>= 4.0.0
53 changes: 51 additions & 2 deletions src/scrapybara/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,121 @@

from .types import (
AuthStateResponse,
BashResponse,
BrowserAuthenticateResponse,
BrowserGetCdpUrlResponse,
Button,
CellType,
ClickMouseAction,
ClickMouseActionClickType,
ComputerResponse,
DeploymentConfigInstanceType,
DragMouseAction,
EditResponse,
EnvGetResponse,
EnvResponse,
ExecuteCellRequest,
FileDownloadResponse,
FileReadResponse,
GetCursorPositionAction,
GetInstanceResponse,
GetInstanceResponseInstanceType,
HttpValidationError,
InstanceGetStreamUrlResponse,
InstanceScreenshotResponse,
KernelInfo,
ModifyBrowserAuthResponse,
MoveMouseAction,
Notebook,
NotebookCell,
PressKeyAction,
SaveBrowserAuthResponse,
ScrollAction,
StartBrowserResponse,
Status,
StopBrowserResponse,
StopInstanceResponse,
TakeScreenshotAction,
TypeTextAction,
ValidationError,
ValidationErrorLocItem,
WaitAction,
)
from .errors import UnprocessableEntityError
from . import browser, code, env, file, instance, notebook
from .client import AsyncScrapybara, Scrapybara
from .environment import ScrapybaraEnvironment
from .instance import Action, Command
from .instance import (
Command,
Request,
Request_ClickMouse,
Request_DragMouse,
Request_GetCursorPosition,
Request_MoveMouse,
Request_PressKey,
Request_Scroll,
Request_TakeScreenshot,
Request_TypeText,
Request_Wait,
)
from .version import __version__

__all__ = [
"Action",
"AsyncScrapybara",
"AuthStateResponse",
"BashResponse",
"BrowserAuthenticateResponse",
"BrowserGetCdpUrlResponse",
"Button",
"CellType",
"ClickMouseAction",
"ClickMouseActionClickType",
"Command",
"ComputerResponse",
"DeploymentConfigInstanceType",
"DragMouseAction",
"EditResponse",
"EnvGetResponse",
"EnvResponse",
"ExecuteCellRequest",
"FileDownloadResponse",
"FileReadResponse",
"GetCursorPositionAction",
"GetInstanceResponse",
"GetInstanceResponseInstanceType",
"HttpValidationError",
"InstanceGetStreamUrlResponse",
"InstanceScreenshotResponse",
"KernelInfo",
"ModifyBrowserAuthResponse",
"MoveMouseAction",
"Notebook",
"NotebookCell",
"PressKeyAction",
"Request",
"Request_ClickMouse",
"Request_DragMouse",
"Request_GetCursorPosition",
"Request_MoveMouse",
"Request_PressKey",
"Request_Scroll",
"Request_TakeScreenshot",
"Request_TypeText",
"Request_Wait",
"SaveBrowserAuthResponse",
"Scrapybara",
"ScrapybaraEnvironment",
"ScrollAction",
"StartBrowserResponse",
"Status",
"StopBrowserResponse",
"StopInstanceResponse",
"TakeScreenshotAction",
"TypeTextAction",
"UnprocessableEntityError",
"ValidationError",
"ValidationErrorLocItem",
"WaitAction",
"__version__",
"browser",
"code",
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.2.9",
"X-Fern-SDK-Version": "2.3.0",
}
headers["x-api-key"] = self.api_key
return headers
Expand Down
12 changes: 6 additions & 6 deletions src/scrapybara/core/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def _retry_timeout(response: httpx.Response, retries: int) -> float:


def _should_retry(response: httpx.Response) -> bool:
retriable_400s = [429, 408, 409]
return response.status_code >= 500 or response.status_code in retriable_400s
retryable_400s = [429, 408, 409]
return response.status_code >= 500 or response.status_code in retryable_400s


def remove_omit_from_dict(
Expand Down Expand Up @@ -183,7 +183,7 @@ def request(
files: typing.Optional[typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]]] = None,
headers: typing.Optional[typing.Dict[str, typing.Any]] = None,
request_options: typing.Optional[RequestOptions] = None,
retries: int = 0,
retries: int = 2,
omit: typing.Optional[typing.Any] = None,
) -> httpx.Response:
base_url = self.get_base_url(base_url)
Expand Down Expand Up @@ -269,7 +269,7 @@ def stream(
files: typing.Optional[typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]]] = None,
headers: typing.Optional[typing.Dict[str, typing.Any]] = None,
request_options: typing.Optional[RequestOptions] = None,
retries: int = 0,
retries: int = 2,
omit: typing.Optional[typing.Any] = None,
) -> typing.Iterator[httpx.Response]:
base_url = self.get_base_url(base_url)
Expand Down Expand Up @@ -359,7 +359,7 @@ async def request(
files: typing.Optional[typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]]] = None,
headers: typing.Optional[typing.Dict[str, typing.Any]] = None,
request_options: typing.Optional[RequestOptions] = None,
retries: int = 0,
retries: int = 2,
omit: typing.Optional[typing.Any] = None,
) -> httpx.Response:
base_url = self.get_base_url(base_url)
Expand Down Expand Up @@ -445,7 +445,7 @@ async def stream(
files: typing.Optional[typing.Dict[str, typing.Optional[typing.Union[File, typing.List[File]]]]] = None,
headers: typing.Optional[typing.Dict[str, typing.Any]] = None,
request_options: typing.Optional[RequestOptions] = None,
retries: int = 0,
retries: int = 2,
omit: typing.Optional[typing.Any] = None,
) -> typing.AsyncIterator[httpx.Response]:
base_url = self.get_base_url(base_url)
Expand Down
4 changes: 2 additions & 2 deletions src/scrapybara/core/pydantic_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def to_jsonable_with_fallback(
class UniversalBaseModel(pydantic.BaseModel):
if IS_PYDANTIC_V2:
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(
# Allow fields begining with `model_` to be used in the model
# Allow fields beginning with `model_` to be used in the model
protected_namespaces=(),
) # type: ignore # Pydantic v2

Expand Down Expand Up @@ -128,7 +128,7 @@ def dict(self, **kwargs: typing.Any) -> typing.Dict[str, typing.Any]:
Override the default dict method to `exclude_unset` by default. This function patches
`exclude_unset` to work include fields within non-None default values.
"""
# Note: the logic here is multi-plexed given the levers exposed in Pydantic V1 vs V2
# Note: the logic here is multiplexed given the levers exposed in Pydantic V1 vs V2
# Pydantic V1's .dict can be extremely slow, so we do not want to call it twice.
#
# We'd ideally do the same for Pydantic V2, but it shells out to a library to serialize models
Expand Down
28 changes: 26 additions & 2 deletions src/scrapybara/instance/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# This file was auto-generated by Fern from our API Definition.

from .types import Action, Command
from .types import (
Command,
Request,
Request_ClickMouse,
Request_DragMouse,
Request_GetCursorPosition,
Request_MoveMouse,
Request_PressKey,
Request_Scroll,
Request_TakeScreenshot,
Request_TypeText,
Request_Wait,
)

__all__ = ["Action", "Command"]
__all__ = [
"Command",
"Request",
"Request_ClickMouse",
"Request_DragMouse",
"Request_GetCursorPosition",
"Request_MoveMouse",
"Request_PressKey",
"Request_Scroll",
"Request_TakeScreenshot",
"Request_TypeText",
"Request_Wait",
]
Loading
Loading