firecrawl 1.2.4__tar.gz → 1.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of firecrawl might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: firecrawl
3
- Version: 1.2.4
3
+ Version: 1.3.0
4
4
  Summary: Python SDK for Firecrawl API
5
5
  Home-page: https://github.com/mendableai/firecrawl
6
6
  Author: Mendable.ai
@@ -13,7 +13,7 @@ import os
13
13
 
14
14
  from .firecrawl import FirecrawlApp
15
15
 
16
- __version__ = "1.2.4"
16
+ __version__ = "1.3.0"
17
17
 
18
18
  # Define the logger for the Firecrawl project
19
19
  logger: logging.Logger = logging.getLogger("firecrawl")
@@ -191,6 +191,23 @@ class FirecrawlApp:
191
191
  }
192
192
  else:
193
193
  self._handle_error(response, 'check crawl status')
194
+
195
+ def cancel_crawl(self, id: str) -> Dict[str, Any]:
196
+ """
197
+ Cancel an asynchronous crawl job using the Firecrawl API.
198
+
199
+ Args:
200
+ id (str): The ID of the crawl job to cancel.
201
+
202
+ Returns:
203
+ Dict[str, Any]: The response from the cancel crawl request.
204
+ """
205
+ headers = self._prepare_headers()
206
+ response = self._delete_request(f'{self.api_url}/v1/crawl/{id}', headers)
207
+ if response.status_code == 200:
208
+ return response.json()
209
+ else:
210
+ self._handle_error(response, "cancel crawl job")
194
211
 
195
212
  def crawl_url_and_watch(self, url: str, params: Optional[Dict[str, Any]] = None, idempotency_key: Optional[str] = None) -> 'CrawlWatcher':
196
213
  """
@@ -228,7 +245,7 @@ class FirecrawlApp:
228
245
  json_data = {'url': url}
229
246
  if params:
230
247
  json_data.update(params)
231
-
248
+
232
249
  # Make the POST request with the prepared headers and JSON data
233
250
  response = requests.post(
234
251
  f'{self.api_url}{endpoint}',
@@ -238,7 +255,7 @@ class FirecrawlApp:
238
255
  if response.status_code == 200:
239
256
  response = response.json()
240
257
  if response['success'] and 'links' in response:
241
- return response['links']
258
+ return response
242
259
  else:
243
260
  raise Exception(f'Failed to map URL. Error: {response["error"]}')
244
261
  else:
@@ -321,6 +338,33 @@ class FirecrawlApp:
321
338
  else:
322
339
  return response
323
340
  return response
341
+
342
+ def _delete_request(self, url: str,
343
+ headers: Dict[str, str],
344
+ retries: int = 3,
345
+ backoff_factor: float = 0.5) -> requests.Response:
346
+ """
347
+ Make a DELETE request with retries.
348
+
349
+ Args:
350
+ url (str): The URL to send the DELETE request to.
351
+ headers (Dict[str, str]): The headers to include in the DELETE request.
352
+ retries (int): Number of retries for the request.
353
+ backoff_factor (float): Backoff factor for retries.
354
+
355
+ Returns:
356
+ requests.Response: The response from the DELETE request.
357
+
358
+ Raises:
359
+ requests.RequestException: If the request fails after the specified retries.
360
+ """
361
+ for attempt in range(retries):
362
+ response = requests.delete(url, headers=headers)
363
+ if response.status_code == 502:
364
+ time.sleep(backoff_factor * (2 ** attempt))
365
+ else:
366
+ return response
367
+ return response
324
368
 
325
369
  def _monitor_job_status(self, id: str, headers: Dict[str, str], poll_interval: int) -> Any:
326
370
  """
@@ -434,4 +478,4 @@ class CrawlWatcher:
434
478
  self.dispatch_event('document', doc)
435
479
  elif msg['type'] == 'document':
436
480
  self.data.append(msg['data'])
437
- self.dispatch_event('document', msg['data'])
481
+ self.dispatch_event('document', msg['data'])
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: firecrawl
3
- Version: 1.2.4
3
+ Version: 1.3.0
4
4
  Summary: Python SDK for Firecrawl API
5
5
  Home-page: https://github.com/mendableai/firecrawl
6
6
  Author: Mendable.ai
File without changes
File without changes
File without changes
File without changes
File without changes