firecrawl 0.0.16__py3-none-any.whl → 0.0.19__py3-none-any.whl

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.

firecrawl/__init__.py CHANGED
@@ -13,7 +13,7 @@ import os
13
13
 
14
14
  from .firecrawl import FirecrawlApp
15
15
 
16
- __version__ = "0.0.16"
16
+ __version__ = "0.0.19"
17
17
 
18
18
  # Define the logger for the Firecrawl project
19
19
  logger: logging.Logger = logging.getLogger("firecrawl")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: firecrawl
3
- Version: 0.0.16
3
+ Version: 0.0.19
4
4
  Summary: Python SDK for Firecrawl API
5
5
  Home-page: https://github.com/mendableai/firecrawl
6
6
  Author: Mendable.ai
@@ -30,7 +30,7 @@ Classifier: Topic :: Software Development :: Libraries
30
30
  Classifier: Topic :: Software Development :: Libraries :: Python Modules
31
31
  Classifier: Topic :: Text Processing
32
32
  Classifier: Topic :: Text Processing :: Indexing
33
- Requires-Python: >=3.8
33
+ Requires-Python: >=3.7
34
34
  Description-Content-Type: text/markdown
35
35
  Requires-Dist: requests
36
36
 
@@ -0,0 +1,8 @@
1
+ firecrawl/__init__.py,sha256=ixdimo55Kkf1ccxo31pemLUm16hBOG5GvgEen9S3qNc,1683
2
+ firecrawl/firecrawl.py,sha256=wfy2KXSrLoGlj8HKEP3VKG_u38kRbUbcmRQsMgza5I0,12767
3
+ firecrawl/__tests__/e2e_withAuth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ firecrawl/__tests__/e2e_withAuth/test.py,sha256=vZlhdURkMXY1-2_FBrKwT6D4WbH7HEf_xMEd0X63krQ,7665
5
+ firecrawl-0.0.19.dist-info/METADATA,sha256=M92W_xzUtd6k5-789ti_yyfC88ZXZAdXq7Beqqx6iqc,6264
6
+ firecrawl-0.0.19.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
7
+ firecrawl-0.0.19.dist-info/top_level.txt,sha256=jTvz79zWhiyAezfmmHe4FQ-hR60C59UU5FrjMjijLu8,10
8
+ firecrawl-0.0.19.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.38.4)
2
+ Generator: setuptools (70.2.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -0,0 +1 @@
1
+ firecrawl
@@ -1,57 +0,0 @@
1
- """
2
- This is the Firecrawl package.
3
-
4
- This package provides a Python SDK for interacting with the Firecrawl API.
5
- It includes methods to scrape URLs, perform searches, initiate and monitor crawl jobs,
6
- and check the status of these jobs.
7
-
8
- For more information visit https://github.com/firecrawl/
9
- """
10
-
11
- import logging
12
- import os
13
-
14
- from .firecrawl import FirecrawlApp
15
-
16
- __version__ = "0.0.16"
17
-
18
- # Define the logger for the Firecrawl project
19
- logger: logging.Logger = logging.getLogger("firecrawl")
20
-
21
-
22
- def _basic_config() -> None:
23
- """Set up basic configuration for logging with a specific format and date format."""
24
- try:
25
- logging.basicConfig(
26
- format="[%(asctime)s - %(name)s:%(lineno)d - %(levelname)s] %(message)s",
27
- datefmt="%Y-%m-%d %H:%M:%S",
28
- )
29
- except Exception as e:
30
- logger.error("Failed to configure logging: %s", e)
31
-
32
-
33
- def setup_logging() -> None:
34
- """Set up logging based on the FIRECRAWL_LOGGING_LEVEL environment variable."""
35
- env = os.environ.get(
36
- "FIRECRAWL_LOGGING_LEVEL", "INFO"
37
- ).upper() # Default to 'INFO' level
38
- _basic_config()
39
-
40
- if env == "DEBUG":
41
- logger.setLevel(logging.DEBUG)
42
- elif env == "INFO":
43
- logger.setLevel(logging.INFO)
44
- elif env == "WARNING":
45
- logger.setLevel(logging.WARNING)
46
- elif env == "ERROR":
47
- logger.setLevel(logging.ERROR)
48
- elif env == "CRITICAL":
49
- logger.setLevel(logging.CRITICAL)
50
- else:
51
- logger.setLevel(logging.INFO)
52
- logger.warning("Unknown logging level: %s, defaulting to INFO", env)
53
-
54
-
55
- # Initialize logging configuration when the module is imported
56
- setup_logging()
57
- logger.debug("Debugging logger setup")
@@ -1,318 +0,0 @@
1
- """
2
- FirecrawlApp Module
3
-
4
- This module provides a class `FirecrawlApp` for interacting with the Firecrawl API.
5
- It includes methods to scrape URLs, perform searches, initiate and monitor crawl jobs,
6
- and check the status of these jobs. The module uses requests for HTTP communication
7
- and handles retries for certain HTTP status codes.
8
-
9
- Classes:
10
- - FirecrawlApp: Main class for interacting with the Firecrawl API.
11
- """
12
- import logging
13
- import os
14
- import time
15
- from typing import Any, Dict, Optional
16
-
17
- import requests
18
-
19
- logger : logging.Logger = logging.getLogger("firecrawl")
20
-
21
- class FirecrawlApp:
22
- """
23
- Initialize the FirecrawlApp instance.
24
-
25
- Args:
26
- api_key (Optional[str]): API key for authenticating with the Firecrawl API.
27
- api_url (Optional[str]): Base URL for the Firecrawl API.
28
- """
29
- def __init__(self, api_key: Optional[str] = None, api_url: Optional[str] = None) -> None:
30
- self.api_key = api_key or os.getenv('FIRECRAWL_API_KEY')
31
- if self.api_key is None:
32
- logger.warning("No API key provided")
33
- raise ValueError('No API key provided')
34
- else:
35
- logger.debug("Initialized FirecrawlApp with API key: %s", self.api_key)
36
-
37
- self.api_url = api_url or os.getenv('FIRECRAWL_API_URL', 'https://api.firecrawl.dev')
38
- if self.api_url != 'https://api.firecrawl.dev':
39
- logger.debug("Initialized FirecrawlApp with API URL: %s", self.api_url)
40
-
41
- def scrape_url(self, url: str, params: Optional[Dict[str, Any]] = None) -> Any:
42
- """
43
- Scrape the specified URL using the Firecrawl API.
44
-
45
- Args:
46
- url (str): The URL to scrape.
47
- params (Optional[Dict[str, Any]]): Additional parameters for the scrape request.
48
-
49
- Returns:
50
- Any: The scraped data if the request is successful.
51
-
52
- Raises:
53
- Exception: If the scrape request fails.
54
- """
55
-
56
- headers = self._prepare_headers()
57
-
58
- # Prepare the base scrape parameters with the URL
59
- scrape_params = {'url': url}
60
-
61
- # If there are additional params, process them
62
- if params:
63
- # Initialize extractorOptions if present
64
- extractor_options = params.get('extractorOptions', {})
65
- # Check and convert the extractionSchema if it's a Pydantic model
66
- if 'extractionSchema' in extractor_options:
67
- if hasattr(extractor_options['extractionSchema'], 'schema'):
68
- extractor_options['extractionSchema'] = extractor_options['extractionSchema'].schema()
69
- # Ensure 'mode' is set, defaulting to 'llm-extraction' if not explicitly provided
70
- extractor_options['mode'] = extractor_options.get('mode', 'llm-extraction')
71
- # Update the scrape_params with the processed extractorOptions
72
- scrape_params['extractorOptions'] = extractor_options
73
-
74
- # Include any other params directly at the top level of scrape_params
75
- for key, value in params.items():
76
- if key != 'extractorOptions':
77
- scrape_params[key] = value
78
- # Make the POST request with the prepared headers and JSON data
79
- response = requests.post(
80
- f'{self.api_url}/v0/scrape',
81
- headers=headers,
82
- json=scrape_params,
83
- )
84
- if response.status_code == 200:
85
- response = response.json()
86
- if response['success'] and 'data' in response:
87
- return response['data']
88
- else:
89
- raise Exception(f'Failed to scrape URL. Error: {response["error"]}')
90
- else:
91
- self._handle_error(response, 'scrape URL')
92
-
93
- def search(self, query: str, params: Optional[Dict[str, Any]] = None) -> Any:
94
- """
95
- Perform a search using the Firecrawl API.
96
-
97
- Args:
98
- query (str): The search query.
99
- params (Optional[Dict[str, Any]]): Additional parameters for the search request.
100
-
101
- Returns:
102
- Any: The search results if the request is successful.
103
-
104
- Raises:
105
- Exception: If the search request fails.
106
- """
107
- headers = self._prepare_headers()
108
- json_data = {'query': query}
109
- if params:
110
- json_data.update(params)
111
- response = requests.post(
112
- f'{self.api_url}/v0/search',
113
- headers=headers,
114
- json=json_data
115
- )
116
- if response.status_code == 200:
117
- response = response.json()
118
-
119
- if response['success'] and 'data' in response:
120
- return response['data']
121
- else:
122
- raise Exception(f'Failed to search. Error: {response["error"]}')
123
-
124
- else:
125
- self._handle_error(response, 'search')
126
-
127
- def crawl_url(self, url: str,
128
- params: Optional[Dict[str, Any]] = None,
129
- wait_until_done: bool = True,
130
- poll_interval: int = 2,
131
- idempotency_key: Optional[str] = None) -> Any:
132
- """
133
- Initiate a crawl job for the specified URL using the Firecrawl API.
134
-
135
- Args:
136
- url (str): The URL to crawl.
137
- params (Optional[Dict[str, Any]]): Additional parameters for the crawl request.
138
- wait_until_done (bool): Whether to wait until the crawl job is completed.
139
- poll_interval (int): Time in seconds between status checks when waiting for job completion.
140
- idempotency_key (Optional[str]): A unique uuid key to ensure idempotency of requests.
141
-
142
- Returns:
143
- Any: The crawl job ID or the crawl results if waiting until completion.
144
-
145
- Raises:
146
- Exception: If the crawl job initiation or monitoring fails.
147
- """
148
- headers = self._prepare_headers(idempotency_key)
149
- json_data = {'url': url}
150
- if params:
151
- json_data.update(params)
152
- response = self._post_request(f'{self.api_url}/v0/crawl', json_data, headers)
153
- if response.status_code == 200:
154
- job_id = response.json().get('jobId')
155
- if wait_until_done:
156
- return self._monitor_job_status(job_id, headers, poll_interval)
157
- else:
158
- return {'jobId': job_id}
159
- else:
160
- self._handle_error(response, 'start crawl job')
161
-
162
- def check_crawl_status(self, job_id: str) -> Any:
163
- """
164
- Check the status of a crawl job using the Firecrawl API.
165
-
166
- Args:
167
- job_id (str): The ID of the crawl job.
168
-
169
- Returns:
170
- Any: The status of the crawl job.
171
-
172
- Raises:
173
- Exception: If the status check request fails.
174
- """
175
- headers = self._prepare_headers()
176
- response = self._get_request(f'{self.api_url}/v0/crawl/status/{job_id}', headers)
177
- if response.status_code == 200:
178
- return response.json()
179
- else:
180
- self._handle_error(response, 'check crawl status')
181
-
182
- def _prepare_headers(self, idempotency_key: Optional[str] = None) -> Dict[str, str]:
183
- """
184
- Prepare the headers for API requests.
185
-
186
- Args:
187
- idempotency_key (Optional[str]): A unique key to ensure idempotency of requests.
188
-
189
- Returns:
190
- Dict[str, str]: The headers including content type, authorization, and optionally idempotency key.
191
- """
192
- if idempotency_key:
193
- return {
194
- 'Content-Type': 'application/json',
195
- 'Authorization': f'Bearer {self.api_key}',
196
- 'x-idempotency-key': idempotency_key
197
- }
198
-
199
- return {
200
- 'Content-Type': 'application/json',
201
- 'Authorization': f'Bearer {self.api_key}',
202
- }
203
-
204
- def _post_request(self, url: str,
205
- data: Dict[str, Any],
206
- headers: Dict[str, str],
207
- retries: int = 3,
208
- backoff_factor: float = 0.5) -> requests.Response:
209
- """
210
- Make a POST request with retries.
211
-
212
- Args:
213
- url (str): The URL to send the POST request to.
214
- data (Dict[str, Any]): The JSON data to include in the POST request.
215
- headers (Dict[str, str]): The headers to include in the POST request.
216
- retries (int): Number of retries for the request.
217
- backoff_factor (float): Backoff factor for retries.
218
-
219
- Returns:
220
- requests.Response: The response from the POST request.
221
-
222
- Raises:
223
- requests.RequestException: If the request fails after the specified retries.
224
- """
225
- for attempt in range(retries):
226
- response = requests.post(url, headers=headers, json=data)
227
- if response.status_code == 502:
228
- time.sleep(backoff_factor * (2 ** attempt))
229
- else:
230
- return response
231
- return response
232
-
233
- def _get_request(self, url: str,
234
- headers: Dict[str, str],
235
- retries: int = 3,
236
- backoff_factor: float = 0.5) -> requests.Response:
237
- """
238
- Make a GET request with retries.
239
-
240
- Args:
241
- url (str): The URL to send the GET request to.
242
- headers (Dict[str, str]): The headers to include in the GET request.
243
- retries (int): Number of retries for the request.
244
- backoff_factor (float): Backoff factor for retries.
245
-
246
- Returns:
247
- requests.Response: The response from the GET request.
248
-
249
- Raises:
250
- requests.RequestException: If the request fails after the specified retries.
251
- """
252
- for attempt in range(retries):
253
- response = requests.get(url, headers=headers)
254
- if response.status_code == 502:
255
- time.sleep(backoff_factor * (2 ** attempt))
256
- else:
257
- return response
258
- return response
259
-
260
- def _monitor_job_status(self, job_id: str, headers: Dict[str, str], poll_interval: int) -> Any:
261
- """
262
- Monitor the status of a crawl job until completion.
263
-
264
- Args:
265
- job_id (str): The ID of the crawl job.
266
- headers (Dict[str, str]): The headers to include in the status check requests.
267
- poll_interval (int): Secounds between status checks.
268
-
269
- Returns:
270
- Any: The crawl results if the job is completed successfully.
271
-
272
- Raises:
273
- Exception: If the job fails or an error occurs during status checks.
274
- """
275
- while True:
276
- status_response = self._get_request(f'{self.api_url}/v0/crawl/status/{job_id}', headers)
277
- if status_response.status_code == 200:
278
- status_data = status_response.json()
279
- if status_data['status'] == 'completed':
280
- if 'data' in status_data:
281
- return status_data['data']
282
- else:
283
- raise Exception('Crawl job completed but no data was returned')
284
- elif status_data['status'] in ['active', 'paused', 'pending', 'queued', 'waiting']:
285
- poll_interval=max(poll_interval,2)
286
- time.sleep(poll_interval) # Wait for the specified interval before checking again
287
- else:
288
- raise Exception(f'Crawl job failed or was stopped. Status: {status_data["status"]}')
289
- else:
290
- self._handle_error(status_response, 'check crawl status')
291
-
292
- def _handle_error(self, response: requests.Response, action: str) -> None:
293
- """
294
- Handle errors from API responses.
295
-
296
- Args:
297
- response (requests.Response): The response object from the API request.
298
- action (str): Description of the action that was being performed.
299
-
300
- Raises:
301
- Exception: An exception with a message containing the status code and error details from the response.
302
- """
303
- error_message = response.json().get('error', 'No additional error details provided.')
304
-
305
- if response.status_code == 402:
306
- message = f"Payment Required: Failed to {action}. {error_message}"
307
- elif response.status_code == 408:
308
- message = f"Request Timeout: Failed to {action} as the request timed out. {error_message}"
309
- elif response.status_code == 409:
310
- message = f"Conflict: Failed to {action} due to a conflict. {error_message}"
311
- elif response.status_code == 500:
312
- message = f"Internal Server Error: Failed to {action}. {error_message}"
313
- else:
314
- message = f"Unexpected error during {action}: Status code {response.status_code}. {error_message}"
315
-
316
- # Raise an HTTPError with the custom message and attach the response
317
- raise requests.exceptions.HTTPError(message, response=response)
318
-
@@ -1,10 +0,0 @@
1
- build/lib/firecrawl/__init__.py,sha256=QRMTTelCkQdvP5R8Z1k71Xo9FFORks1WqT0jW4HxAbg,1683
2
- build/lib/firecrawl/firecrawl.py,sha256=wfy2KXSrLoGlj8HKEP3VKG_u38kRbUbcmRQsMgza5I0,12767
3
- firecrawl/__init__.py,sha256=QRMTTelCkQdvP5R8Z1k71Xo9FFORks1WqT0jW4HxAbg,1683
4
- firecrawl/firecrawl.py,sha256=wfy2KXSrLoGlj8HKEP3VKG_u38kRbUbcmRQsMgza5I0,12767
5
- firecrawl/__tests__/e2e_withAuth/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
- firecrawl/__tests__/e2e_withAuth/test.py,sha256=vZlhdURkMXY1-2_FBrKwT6D4WbH7HEf_xMEd0X63krQ,7665
7
- firecrawl-0.0.16.dist-info/METADATA,sha256=xecqvrVvCCDsy5e53Uik80_tamWXrPoJlGHtZbDcVkU,6264
8
- firecrawl-0.0.16.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
9
- firecrawl-0.0.16.dist-info/top_level.txt,sha256=GglqAyOiUmWSqRivafO_tbV_rz2OdmRzMG9BRS3A6Zo,21
10
- firecrawl-0.0.16.dist-info/RECORD,,
@@ -1,3 +0,0 @@
1
- build
2
- dist
3
- firecrawl