-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[python-SDK] improvs/async #1337
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
tomkosm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall, commented on a few minor mostly type related stuff
| blockAds: Optional[bool] = None | ||
| proxy: Optional[Literal["basic", "stealth"]] = None | ||
|
|
||
| class Action(pydantic.BaseModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should make a different type for each action, so its clear what the arguments for each action are?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You then can make action be a union ie Union[WaitAction, ClickAction, ScreenshotAction]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good idea!
| """ | ||
| crawl_response = self.async_crawl_url(url, params, idempotency_key) | ||
| if crawl_response['success'] and 'id' in crawl_response: | ||
| return CrawlWatcher(crawl_response['id'], self) | ||
| else: | ||
| raise Exception("Crawl job failed to start") | ||
|
|
||
| def map_url(self, url: str, params: Optional[Dict[str, Any]] = None) -> Any: | ||
| def map_url(self, url: str, params: Optional[Dict[str, Any]] = None) -> MapResponse: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, maybe we should use the type for params
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| await asyncio.sleep(backoff_factor * (2 ** attempt)) | ||
| continue | ||
| if response.status != 200: | ||
| await self._handle_error(response, "make POST request") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does this mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a retry for 502s
| for attempt in range(retries): | ||
| try: | ||
| async with session.post(url, headers=headers, json=data) as response: | ||
| if response.status == 502: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this rate limit?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope. It's retry
| for attempt in range(retries): | ||
| try: | ||
| async with session.get(url, headers=headers) as response: | ||
| if response.status == 502: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we have this twice, maybe abstract it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
first is get, second is post
| else: | ||
| raise Exception(f'Failed to start crawl. Error: {response.get("error")}') | ||
|
|
||
| async def async_crawl_url(self, url: str, params: Optional[Dict[str, Any]] = None, idempotency_key: Optional[str] = None) -> CrawlResponse: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
params type missing here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
| else: | ||
| raise Exception(f'Job failed or was stopped. Status: {status_data["status"]}') | ||
|
|
||
| async def map_url(self, url: str, params: Optional[Dict[str, Any]] = None) -> MapResponse: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
|
Add |
done |
|
@nickscamara can you take a look and publish this one pls? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Files not reviewed (1)
- apps/python-sdk/requirements.txt: Language not supported
| this.init(); | ||
| } | ||
|
|
Copilot
AI
Apr 8, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The async initialization in this.init() is not awaited, which might lead to requests using a default version before the SDK version is properly set. Consider ensuring that initialization is complete (for example, by awaiting the promise) before processing further operations that depend on the version.
| this.init(); | |
| } | |
| } | |
| static async create(config: FirecrawlAppConfig): Promise<FirecrawlApp> { | |
| const instance = new FirecrawlApp(config); | |
| await instance.init(); | |
| return instance; | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.