firecrawl-py 0.0.14__tar.gz → 4.10.5__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-py might be problematic. Click here for more details.

Files changed (102) hide show
  1. firecrawl_py-4.10.5/LICENSE +21 -0
  2. firecrawl_py-4.10.5/PKG-INFO +234 -0
  3. firecrawl_py-4.10.5/README.md +187 -0
  4. firecrawl_py-4.10.5/firecrawl/__init__.py +87 -0
  5. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/aio/conftest.py +62 -0
  6. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/aio/test_aio_batch_scrape.py +69 -0
  7. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/aio/test_aio_crawl.py +189 -0
  8. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/aio/test_aio_extract.py +39 -0
  9. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/aio/test_aio_map.py +41 -0
  10. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/aio/test_aio_scrape.py +138 -0
  11. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/aio/test_aio_search.py +249 -0
  12. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/aio/test_aio_usage.py +42 -0
  13. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/aio/test_aio_watcher.py +43 -0
  14. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/conftest.py +73 -0
  15. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/test_async.py +73 -0
  16. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/test_batch_scrape.py +106 -0
  17. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/test_crawl.py +278 -0
  18. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/test_extract.py +55 -0
  19. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/test_map.py +61 -0
  20. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/test_scrape.py +191 -0
  21. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/test_search.py +270 -0
  22. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/test_usage.py +26 -0
  23. firecrawl_py-4.10.5/firecrawl/__tests__/e2e/v2/test_watcher.py +65 -0
  24. firecrawl_py-4.10.5/firecrawl/__tests__/unit/test_recursive_schema_v1.py +1209 -0
  25. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/aio/test_aio_crawl_params.py +12 -0
  26. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/aio/test_aio_crawl_request_preparation.py +79 -0
  27. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/aio/test_aio_crawl_validation.py +12 -0
  28. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/aio/test_aio_map_request_preparation.py +20 -0
  29. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/aio/test_aio_scrape_request_preparation.py +50 -0
  30. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/aio/test_aio_search_request_preparation.py +64 -0
  31. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/aio/test_batch_request_preparation_async.py +28 -0
  32. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/aio/test_ensure_async.py +117 -0
  33. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_batch_request_preparation.py +90 -0
  34. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_branding.py +214 -0
  35. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_crawl_params.py +70 -0
  36. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_crawl_request_preparation.py +240 -0
  37. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_crawl_validation.py +107 -0
  38. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_map_request_preparation.py +54 -0
  39. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_pagination.py +671 -0
  40. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_scrape_request_preparation.py +109 -0
  41. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_search_request_preparation.py +169 -0
  42. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_search_validation.py +236 -0
  43. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_usage_types.py +18 -0
  44. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/methods/test_webhook.py +123 -0
  45. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/utils/test_metadata_extras.py +94 -0
  46. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/utils/test_metadata_extras_multivalue.py +22 -0
  47. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/utils/test_recursive_schema.py +1133 -0
  48. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/utils/test_validation.py +311 -0
  49. firecrawl_py-4.10.5/firecrawl/__tests__/unit/v2/watcher/test_ws_watcher.py +332 -0
  50. firecrawl_py-4.10.5/firecrawl/client.py +261 -0
  51. firecrawl_py-4.10.5/firecrawl/firecrawl.backup.py +4635 -0
  52. firecrawl_py-4.10.5/firecrawl/types.py +167 -0
  53. firecrawl_py-4.10.5/firecrawl/v1/__init__.py +14 -0
  54. firecrawl_py-4.10.5/firecrawl/v1/client.py +5164 -0
  55. firecrawl_py-4.10.5/firecrawl/v2/__init__.py +4 -0
  56. firecrawl_py-4.10.5/firecrawl/v2/client.py +876 -0
  57. firecrawl_py-4.10.5/firecrawl/v2/client_async.py +348 -0
  58. firecrawl_py-4.10.5/firecrawl/v2/methods/aio/__init__.py +1 -0
  59. firecrawl_py-4.10.5/firecrawl/v2/methods/aio/batch.py +188 -0
  60. firecrawl_py-4.10.5/firecrawl/v2/methods/aio/crawl.py +351 -0
  61. firecrawl_py-4.10.5/firecrawl/v2/methods/aio/extract.py +133 -0
  62. firecrawl_py-4.10.5/firecrawl/v2/methods/aio/map.py +65 -0
  63. firecrawl_py-4.10.5/firecrawl/v2/methods/aio/scrape.py +33 -0
  64. firecrawl_py-4.10.5/firecrawl/v2/methods/aio/search.py +176 -0
  65. firecrawl_py-4.10.5/firecrawl/v2/methods/aio/usage.py +89 -0
  66. firecrawl_py-4.10.5/firecrawl/v2/methods/batch.py +499 -0
  67. firecrawl_py-4.10.5/firecrawl/v2/methods/crawl.py +592 -0
  68. firecrawl_py-4.10.5/firecrawl/v2/methods/extract.py +161 -0
  69. firecrawl_py-4.10.5/firecrawl/v2/methods/map.py +83 -0
  70. firecrawl_py-4.10.5/firecrawl/v2/methods/scrape.py +64 -0
  71. firecrawl_py-4.10.5/firecrawl/v2/methods/search.py +215 -0
  72. firecrawl_py-4.10.5/firecrawl/v2/methods/usage.py +84 -0
  73. firecrawl_py-4.10.5/firecrawl/v2/types.py +1131 -0
  74. firecrawl_py-4.10.5/firecrawl/v2/utils/__init__.py +9 -0
  75. firecrawl_py-4.10.5/firecrawl/v2/utils/error_handler.py +107 -0
  76. firecrawl_py-4.10.5/firecrawl/v2/utils/get_version.py +15 -0
  77. firecrawl_py-4.10.5/firecrawl/v2/utils/http_client.py +178 -0
  78. firecrawl_py-4.10.5/firecrawl/v2/utils/http_client_async.py +69 -0
  79. firecrawl_py-4.10.5/firecrawl/v2/utils/normalize.py +125 -0
  80. firecrawl_py-4.10.5/firecrawl/v2/utils/validation.py +692 -0
  81. firecrawl_py-4.10.5/firecrawl/v2/watcher.py +301 -0
  82. firecrawl_py-4.10.5/firecrawl/v2/watcher_async.py +243 -0
  83. firecrawl_py-4.10.5/firecrawl_py.egg-info/PKG-INFO +234 -0
  84. firecrawl_py-4.10.5/firecrawl_py.egg-info/SOURCES.txt +91 -0
  85. firecrawl_py-4.10.5/firecrawl_py.egg-info/requires.txt +7 -0
  86. {firecrawl_py-0.0.14 → firecrawl_py-4.10.5}/firecrawl_py.egg-info/top_level.txt +1 -1
  87. {firecrawl_py-0.0.14 → firecrawl_py-4.10.5}/pyproject.toml +11 -5
  88. {firecrawl_py-0.0.14 → firecrawl_py-4.10.5}/setup.py +8 -3
  89. firecrawl_py-4.10.5/tests/test_api_key_handling.py +44 -0
  90. firecrawl_py-4.10.5/tests/test_change_tracking.py +98 -0
  91. firecrawl_py-4.10.5/tests/test_timeout_conversion.py +117 -0
  92. firecrawl_py-0.0.14/PKG-INFO +0 -181
  93. firecrawl_py-0.0.14/README.md +0 -145
  94. firecrawl_py-0.0.14/firecrawl/__init__.py +0 -3
  95. firecrawl_py-0.0.14/firecrawl/__tests__/e2e_withAuth/__init__.py +0 -0
  96. firecrawl_py-0.0.14/firecrawl/__tests__/e2e_withAuth/test.py +0 -168
  97. firecrawl_py-0.0.14/firecrawl/firecrawl.py +0 -299
  98. firecrawl_py-0.0.14/firecrawl_py.egg-info/PKG-INFO +0 -181
  99. firecrawl_py-0.0.14/firecrawl_py.egg-info/SOURCES.txt +0 -12
  100. firecrawl_py-0.0.14/firecrawl_py.egg-info/requires.txt +0 -1
  101. {firecrawl_py-0.0.14 → firecrawl_py-4.10.5}/firecrawl_py.egg-info/dependency_links.txt +0 -0
  102. {firecrawl_py-0.0.14 → firecrawl_py-4.10.5}/setup.cfg +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Sideguide Technologies Inc.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,234 @@
1
+ Metadata-Version: 2.4
2
+ Name: firecrawl-py
3
+ Version: 4.10.5
4
+ Summary: Python SDK for Firecrawl API
5
+ Home-page: https://github.com/firecrawl/firecrawl
6
+ Author: Mendable.ai
7
+ Author-email: "Mendable.ai" <nick@mendable.ai>
8
+ Maintainer-email: "Mendable.ai" <nick@mendable.ai>
9
+ License: MIT License
10
+ Project-URL: Documentation, https://docs.firecrawl.dev
11
+ Project-URL: Source, https://github.com/firecrawl/firecrawl
12
+ Project-URL: Tracker, https://github.com/firecrawl/firecrawl/issues
13
+ Keywords: SDK,API,firecrawl
14
+ Classifier: Development Status :: 5 - Production/Stable
15
+ Classifier: Environment :: Web Environment
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Natural Language :: English
19
+ Classifier: Operating System :: OS Independent
20
+ Classifier: Programming Language :: Python
21
+ Classifier: Programming Language :: Python :: 3
22
+ Classifier: Programming Language :: Python :: 3.8
23
+ Classifier: Programming Language :: Python :: 3.9
24
+ Classifier: Programming Language :: Python :: 3.10
25
+ Classifier: Topic :: Internet
26
+ Classifier: Topic :: Internet :: WWW/HTTP
27
+ Classifier: Topic :: Internet :: WWW/HTTP :: Indexing/Search
28
+ Classifier: Topic :: Software Development
29
+ Classifier: Topic :: Software Development :: Libraries
30
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
31
+ Classifier: Topic :: Text Processing
32
+ Classifier: Topic :: Text Processing :: Indexing
33
+ Requires-Python: >=3.8
34
+ Description-Content-Type: text/markdown
35
+ License-File: LICENSE
36
+ Requires-Dist: requests
37
+ Requires-Dist: httpx
38
+ Requires-Dist: python-dotenv
39
+ Requires-Dist: websockets
40
+ Requires-Dist: nest-asyncio
41
+ Requires-Dist: pydantic>=2.0
42
+ Requires-Dist: aiohttp
43
+ Dynamic: author
44
+ Dynamic: home-page
45
+ Dynamic: license-file
46
+ Dynamic: requires-python
47
+
48
+ # Firecrawl Python SDK
49
+
50
+ The Firecrawl Python SDK is a library that allows you to easily scrape and crawl websites, and output the data in a format ready for use with language models (LLMs). It provides a simple and intuitive interface for interacting with the Firecrawl API.
51
+
52
+ ## Installation
53
+
54
+ To install the Firecrawl Python SDK, you can use pip:
55
+
56
+ ```bash
57
+ pip install firecrawl-py
58
+ ```
59
+
60
+ ## Usage
61
+
62
+ 1. Get an API key from [firecrawl.dev](https://firecrawl.dev)
63
+ 2. Set the API key as an environment variable named `FIRECRAWL_API_KEY` or pass it as a parameter to the `Firecrawl` class.
64
+
65
+ Here's an example of how to use the SDK:
66
+
67
+ ```python
68
+ from firecrawl import Firecrawl
69
+ from firecrawl.types import ScrapeOptions
70
+
71
+ firecrawl = Firecrawl(api_key="fc-YOUR_API_KEY")
72
+
73
+ # Scrape a website (v2):
74
+ data = firecrawl.scrape(
75
+ 'https://firecrawl.dev',
76
+ formats=['markdown', 'html']
77
+ )
78
+ print(data)
79
+
80
+ # Crawl a website (v2 waiter):
81
+ crawl_status = firecrawl.crawl(
82
+ 'https://firecrawl.dev',
83
+ limit=100,
84
+ scrape_options=ScrapeOptions(formats=['markdown', 'html'])
85
+ )
86
+ print(crawl_status)
87
+ ```
88
+
89
+ ### Scraping a URL
90
+
91
+ To scrape a single URL, use the `scrape` method. It takes the URL as a parameter and returns a document with the requested formats.
92
+
93
+ ```python
94
+ # Scrape a website (v2):
95
+ scrape_result = firecrawl.scrape('https://firecrawl.dev', formats=['markdown', 'html'])
96
+ print(scrape_result)
97
+ ```
98
+
99
+ ### Crawling a Website
100
+
101
+ To crawl a website, use the `crawl` method. It takes the starting URL and optional parameters as arguments. You can control depth, limits, formats, and more.
102
+
103
+ ```python
104
+ crawl_status = firecrawl.crawl(
105
+ 'https://firecrawl.dev',
106
+ limit=100,
107
+ scrape_options=ScrapeOptions(formats=['markdown', 'html']),
108
+ poll_interval=30
109
+ )
110
+ print(crawl_status)
111
+ ```
112
+
113
+ ### Asynchronous Crawling
114
+
115
+ <Tip>Looking for async operations? Check out the [Async Class](#async-class) section below.</Tip>
116
+
117
+ To enqueue a crawl asynchronously, use `start_crawl`. It returns the crawl `ID` which you can use to check the status of the crawl job.
118
+
119
+ ```python
120
+ crawl_job = firecrawl.start_crawl(
121
+ 'https://firecrawl.dev',
122
+ limit=100,
123
+ scrape_options=ScrapeOptions(formats=['markdown', 'html']),
124
+ )
125
+ print(crawl_job)
126
+ ```
127
+
128
+ ### Checking Crawl Status
129
+
130
+ To check the status of a crawl job, use the `get_crawl_status` method. It takes the job ID as a parameter and returns the current status of the crawl job.
131
+
132
+ ```python
133
+ crawl_status = firecrawl.get_crawl_status("<crawl_id>")
134
+ print(crawl_status)
135
+ ```
136
+
137
+ ### Cancelling a Crawl
138
+
139
+ To cancel an asynchronous crawl job, use the `cancel_crawl` method. It takes the job ID of the asynchronous crawl as a parameter and returns the cancellation status.
140
+
141
+ ```python
142
+ cancel_crawl = firecrawl.cancel_crawl(id)
143
+ print(cancel_crawl)
144
+ ```
145
+
146
+ ### Map a Website
147
+
148
+ Use `map` to generate a list of URLs from a website. Options let you customize the mapping process, including whether to use the sitemap or include subdomains.
149
+
150
+ ```python
151
+ # Map a website (v2):
152
+ map_result = firecrawl.map('https://firecrawl.dev')
153
+ print(map_result)
154
+ ```
155
+
156
+ {/* ### Extracting Structured Data from Websites
157
+
158
+ To extract structured data from websites, use the `extract` method. It takes the URLs to extract data from, a prompt, and a schema as arguments. The schema is a Pydantic model that defines the structure of the extracted data.
159
+
160
+ <ExtractPythonShort /> */}
161
+
162
+ ### Crawling a Website with WebSockets
163
+
164
+ To crawl a website with WebSockets, use the `crawl_url_and_watch` method. It takes the starting URL and optional parameters as arguments. The `params` argument allows you to specify additional options for the crawl job, such as the maximum number of pages to crawl, allowed domains, and the output format.
165
+
166
+ ```python
167
+ # inside an async function...
168
+ nest_asyncio.apply()
169
+
170
+ # Define event handlers
171
+ def on_document(detail):
172
+ print("DOC", detail)
173
+
174
+ def on_error(detail):
175
+ print("ERR", detail['error'])
176
+
177
+ def on_done(detail):
178
+ print("DONE", detail['status'])
179
+
180
+ # Function to start the crawl and watch process
181
+ async def start_crawl_and_watch():
182
+ # Initiate the crawl job and get the watcher
183
+ watcher = app.crawl_url_and_watch('firecrawl.dev', exclude_paths=['blog/*'], limit=5)
184
+
185
+ # Add event listeners
186
+ watcher.add_event_listener("document", on_document)
187
+ watcher.add_event_listener("error", on_error)
188
+ watcher.add_event_listener("done", on_done)
189
+
190
+ # Start the watcher
191
+ await watcher.connect()
192
+
193
+ # Run the event loop
194
+ await start_crawl_and_watch()
195
+ ```
196
+
197
+ ## Error Handling
198
+
199
+ The SDK handles errors returned by the Firecrawl API and raises appropriate exceptions. If an error occurs during a request, an exception will be raised with a descriptive error message.
200
+
201
+ ## Async Class
202
+
203
+ For async operations, you can use the `AsyncFirecrawl` class. Its methods mirror the `Firecrawl` class, but you `await` them.
204
+
205
+ ```python
206
+ from firecrawl import AsyncFirecrawl
207
+
208
+ firecrawl = AsyncFirecrawl(api_key="YOUR_API_KEY")
209
+
210
+ # Async Scrape (v2)
211
+ async def example_scrape():
212
+ scrape_result = await firecrawl.scrape(url="https://example.com")
213
+ print(scrape_result)
214
+
215
+ # Async Crawl (v2)
216
+ async def example_crawl():
217
+ crawl_result = await firecrawl.crawl(url="https://example.com")
218
+ print(crawl_result)
219
+ ```
220
+
221
+ ## v1 compatibility
222
+
223
+ For legacy code paths, v1 remains available under `firecrawl.v1` with the original method names.
224
+
225
+ ```python
226
+ from firecrawl import Firecrawl
227
+
228
+ firecrawl = Firecrawl(api_key="YOUR_API_KEY")
229
+
230
+ # v1 methods (feature‑frozen)
231
+ doc_v1 = firecrawl.v1.scrape_url('https://firecrawl.dev', formats=['markdown', 'html'])
232
+ crawl_v1 = firecrawl.v1.crawl_url('https://firecrawl.dev', limit=100)
233
+ map_v1 = firecrawl.v1.map_url('https://firecrawl.dev')
234
+ ```
@@ -0,0 +1,187 @@
1
+ # Firecrawl Python SDK
2
+
3
+ The Firecrawl Python SDK is a library that allows you to easily scrape and crawl websites, and output the data in a format ready for use with language models (LLMs). It provides a simple and intuitive interface for interacting with the Firecrawl API.
4
+
5
+ ## Installation
6
+
7
+ To install the Firecrawl Python SDK, you can use pip:
8
+
9
+ ```bash
10
+ pip install firecrawl-py
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ 1. Get an API key from [firecrawl.dev](https://firecrawl.dev)
16
+ 2. Set the API key as an environment variable named `FIRECRAWL_API_KEY` or pass it as a parameter to the `Firecrawl` class.
17
+
18
+ Here's an example of how to use the SDK:
19
+
20
+ ```python
21
+ from firecrawl import Firecrawl
22
+ from firecrawl.types import ScrapeOptions
23
+
24
+ firecrawl = Firecrawl(api_key="fc-YOUR_API_KEY")
25
+
26
+ # Scrape a website (v2):
27
+ data = firecrawl.scrape(
28
+ 'https://firecrawl.dev',
29
+ formats=['markdown', 'html']
30
+ )
31
+ print(data)
32
+
33
+ # Crawl a website (v2 waiter):
34
+ crawl_status = firecrawl.crawl(
35
+ 'https://firecrawl.dev',
36
+ limit=100,
37
+ scrape_options=ScrapeOptions(formats=['markdown', 'html'])
38
+ )
39
+ print(crawl_status)
40
+ ```
41
+
42
+ ### Scraping a URL
43
+
44
+ To scrape a single URL, use the `scrape` method. It takes the URL as a parameter and returns a document with the requested formats.
45
+
46
+ ```python
47
+ # Scrape a website (v2):
48
+ scrape_result = firecrawl.scrape('https://firecrawl.dev', formats=['markdown', 'html'])
49
+ print(scrape_result)
50
+ ```
51
+
52
+ ### Crawling a Website
53
+
54
+ To crawl a website, use the `crawl` method. It takes the starting URL and optional parameters as arguments. You can control depth, limits, formats, and more.
55
+
56
+ ```python
57
+ crawl_status = firecrawl.crawl(
58
+ 'https://firecrawl.dev',
59
+ limit=100,
60
+ scrape_options=ScrapeOptions(formats=['markdown', 'html']),
61
+ poll_interval=30
62
+ )
63
+ print(crawl_status)
64
+ ```
65
+
66
+ ### Asynchronous Crawling
67
+
68
+ <Tip>Looking for async operations? Check out the [Async Class](#async-class) section below.</Tip>
69
+
70
+ To enqueue a crawl asynchronously, use `start_crawl`. It returns the crawl `ID` which you can use to check the status of the crawl job.
71
+
72
+ ```python
73
+ crawl_job = firecrawl.start_crawl(
74
+ 'https://firecrawl.dev',
75
+ limit=100,
76
+ scrape_options=ScrapeOptions(formats=['markdown', 'html']),
77
+ )
78
+ print(crawl_job)
79
+ ```
80
+
81
+ ### Checking Crawl Status
82
+
83
+ To check the status of a crawl job, use the `get_crawl_status` method. It takes the job ID as a parameter and returns the current status of the crawl job.
84
+
85
+ ```python
86
+ crawl_status = firecrawl.get_crawl_status("<crawl_id>")
87
+ print(crawl_status)
88
+ ```
89
+
90
+ ### Cancelling a Crawl
91
+
92
+ To cancel an asynchronous crawl job, use the `cancel_crawl` method. It takes the job ID of the asynchronous crawl as a parameter and returns the cancellation status.
93
+
94
+ ```python
95
+ cancel_crawl = firecrawl.cancel_crawl(id)
96
+ print(cancel_crawl)
97
+ ```
98
+
99
+ ### Map a Website
100
+
101
+ Use `map` to generate a list of URLs from a website. Options let you customize the mapping process, including whether to use the sitemap or include subdomains.
102
+
103
+ ```python
104
+ # Map a website (v2):
105
+ map_result = firecrawl.map('https://firecrawl.dev')
106
+ print(map_result)
107
+ ```
108
+
109
+ {/* ### Extracting Structured Data from Websites
110
+
111
+ To extract structured data from websites, use the `extract` method. It takes the URLs to extract data from, a prompt, and a schema as arguments. The schema is a Pydantic model that defines the structure of the extracted data.
112
+
113
+ <ExtractPythonShort /> */}
114
+
115
+ ### Crawling a Website with WebSockets
116
+
117
+ To crawl a website with WebSockets, use the `crawl_url_and_watch` method. It takes the starting URL and optional parameters as arguments. The `params` argument allows you to specify additional options for the crawl job, such as the maximum number of pages to crawl, allowed domains, and the output format.
118
+
119
+ ```python
120
+ # inside an async function...
121
+ nest_asyncio.apply()
122
+
123
+ # Define event handlers
124
+ def on_document(detail):
125
+ print("DOC", detail)
126
+
127
+ def on_error(detail):
128
+ print("ERR", detail['error'])
129
+
130
+ def on_done(detail):
131
+ print("DONE", detail['status'])
132
+
133
+ # Function to start the crawl and watch process
134
+ async def start_crawl_and_watch():
135
+ # Initiate the crawl job and get the watcher
136
+ watcher = app.crawl_url_and_watch('firecrawl.dev', exclude_paths=['blog/*'], limit=5)
137
+
138
+ # Add event listeners
139
+ watcher.add_event_listener("document", on_document)
140
+ watcher.add_event_listener("error", on_error)
141
+ watcher.add_event_listener("done", on_done)
142
+
143
+ # Start the watcher
144
+ await watcher.connect()
145
+
146
+ # Run the event loop
147
+ await start_crawl_and_watch()
148
+ ```
149
+
150
+ ## Error Handling
151
+
152
+ The SDK handles errors returned by the Firecrawl API and raises appropriate exceptions. If an error occurs during a request, an exception will be raised with a descriptive error message.
153
+
154
+ ## Async Class
155
+
156
+ For async operations, you can use the `AsyncFirecrawl` class. Its methods mirror the `Firecrawl` class, but you `await` them.
157
+
158
+ ```python
159
+ from firecrawl import AsyncFirecrawl
160
+
161
+ firecrawl = AsyncFirecrawl(api_key="YOUR_API_KEY")
162
+
163
+ # Async Scrape (v2)
164
+ async def example_scrape():
165
+ scrape_result = await firecrawl.scrape(url="https://example.com")
166
+ print(scrape_result)
167
+
168
+ # Async Crawl (v2)
169
+ async def example_crawl():
170
+ crawl_result = await firecrawl.crawl(url="https://example.com")
171
+ print(crawl_result)
172
+ ```
173
+
174
+ ## v1 compatibility
175
+
176
+ For legacy code paths, v1 remains available under `firecrawl.v1` with the original method names.
177
+
178
+ ```python
179
+ from firecrawl import Firecrawl
180
+
181
+ firecrawl = Firecrawl(api_key="YOUR_API_KEY")
182
+
183
+ # v1 methods (feature‑frozen)
184
+ doc_v1 = firecrawl.v1.scrape_url('https://firecrawl.dev', formats=['markdown', 'html'])
185
+ crawl_v1 = firecrawl.v1.crawl_url('https://firecrawl.dev', limit=100)
186
+ map_v1 = firecrawl.v1.map_url('https://firecrawl.dev')
187
+ ```
@@ -0,0 +1,87 @@
1
+ """
2
+ Firecrawl Python SDK
3
+
4
+ """
5
+
6
+ import logging
7
+ import os
8
+
9
+ from .client import Firecrawl, AsyncFirecrawl, FirecrawlApp, AsyncFirecrawlApp
10
+ from .v2.watcher import Watcher
11
+ from .v2.watcher_async import AsyncWatcher
12
+ from .v1 import (
13
+ V1FirecrawlApp,
14
+ AsyncV1FirecrawlApp,
15
+ V1JsonConfig,
16
+ V1ScrapeOptions,
17
+ V1ChangeTrackingOptions,
18
+ )
19
+
20
+ __version__ = "4.10.5"
21
+
22
+ # Define the logger for the Firecrawl project
23
+ logger: logging.Logger = logging.getLogger("firecrawl")
24
+
25
+
26
+ def _configure_logger() -> None:
27
+ """
28
+ Configure the firecrawl logger for console output.
29
+
30
+ The function attaches a handler for console output with a specific format and date
31
+ format to the firecrawl logger.
32
+ """
33
+ try:
34
+ formatter = logging.Formatter(
35
+ "[%(asctime)s - %(name)s:%(lineno)d - %(levelname)s] %(message)s",
36
+ datefmt="%Y-%m-%d %H:%M:%S",
37
+ )
38
+
39
+ console_handler = logging.StreamHandler()
40
+ console_handler.setFormatter(formatter)
41
+
42
+ logger.addHandler(console_handler)
43
+ except Exception as e:
44
+ logger.error("Failed to configure logging: %s", e)
45
+
46
+
47
+ def setup_logging() -> None:
48
+ """Set up logging based on the FIRECRAWL_LOGGING_LEVEL environment variable."""
49
+ if logger.hasHandlers():
50
+ return
51
+
52
+ if not (env := os.getenv("FIRECRAWL_LOGGING_LEVEL", "").upper()):
53
+ logger.addHandler(logging.NullHandler())
54
+ return
55
+
56
+ _configure_logger()
57
+
58
+ if env == "DEBUG":
59
+ logger.setLevel(logging.DEBUG)
60
+ elif env == "INFO":
61
+ logger.setLevel(logging.INFO)
62
+ elif env == "WARNING":
63
+ logger.setLevel(logging.WARNING)
64
+ elif env == "ERROR":
65
+ logger.setLevel(logging.ERROR)
66
+ elif env == "CRITICAL":
67
+ logger.setLevel(logging.CRITICAL)
68
+ else:
69
+ logger.setLevel(logging.INFO)
70
+ logger.warning("Unknown logging level: %s, defaulting to INFO", env)
71
+
72
+ setup_logging()
73
+ logger.debug("Debugging logger setup")
74
+
75
+ __all__ = [
76
+ 'Firecrawl',
77
+ 'AsyncFirecrawl',
78
+ 'FirecrawlApp',
79
+ 'AsyncFirecrawlApp',
80
+ 'Watcher',
81
+ 'AsyncWatcher',
82
+ 'V1FirecrawlApp',
83
+ 'AsyncV1FirecrawlApp',
84
+ 'V1JsonConfig',
85
+ 'V1ScrapeOptions',
86
+ 'V1ChangeTrackingOptions',
87
+ ]
@@ -0,0 +1,62 @@
1
+ """
2
+ Pytest configuration for async E2E tests.
3
+ Ensures environment variables are loaded before any test runs.
4
+ """
5
+ import os
6
+ import pytest
7
+ from dotenv import load_dotenv, find_dotenv
8
+
9
+ # Load environment IMMEDIATELY at module import time (before pytest collects tests)
10
+ # This ensures env vars are loaded before the first test runs
11
+ _env_loaded = False
12
+
13
+ def _ensure_env_loaded():
14
+ """Ensure environment is loaded exactly once, synchronously."""
15
+ global _env_loaded
16
+ if not _env_loaded:
17
+ # Find and load .env from multiple possible locations
18
+ env_file = find_dotenv(usecwd=True)
19
+ if env_file:
20
+ load_dotenv(env_file, override=True)
21
+ else:
22
+ # Try loading from current directory
23
+ load_dotenv(override=True)
24
+ _env_loaded = True
25
+
26
+ # Load env immediately when this module is imported
27
+ _ensure_env_loaded()
28
+
29
+
30
+ @pytest.fixture(scope="session", autouse=True)
31
+ def load_environment():
32
+ """Ensure environment variables are loaded before running any tests."""
33
+ # Double-check env is loaded (should already be done at import time)
34
+ _ensure_env_loaded()
35
+
36
+ # Validate required environment variables
37
+ required_vars = ["API_KEY", "API_URL"]
38
+ missing_vars = [var for var in required_vars if not os.getenv(var)]
39
+
40
+ if missing_vars:
41
+ pytest.skip(f"Skipping E2E tests: Missing required environment variables: {', '.join(missing_vars)}")
42
+
43
+ yield
44
+
45
+
46
+ @pytest.fixture(scope="function")
47
+ def api_key():
48
+ """Provide API key for tests."""
49
+ key = os.getenv("API_KEY")
50
+ if not key:
51
+ pytest.skip("API_KEY not set")
52
+ return key
53
+
54
+
55
+ @pytest.fixture(scope="function")
56
+ def api_url():
57
+ """Provide API URL for tests."""
58
+ url = os.getenv("API_URL")
59
+ if not url:
60
+ pytest.skip("API_URL not set")
61
+ return url
62
+
@@ -0,0 +1,69 @@
1
+ import asyncio
2
+ import pytest
3
+ from firecrawl import AsyncFirecrawl
4
+
5
+
6
+ @pytest.mark.asyncio
7
+ async def test_async_batch_start_and_status(api_key, api_url):
8
+ client = AsyncFirecrawl(api_key=api_key, api_url=api_url)
9
+ start = await client.start_batch_scrape([
10
+ "https://docs.firecrawl.dev",
11
+ "https://firecrawl.dev",
12
+ ], formats=["markdown"], max_concurrency=1)
13
+ job_id = start.id
14
+
15
+ deadline = asyncio.get_event_loop().time() + 240
16
+ status = await client.get_batch_scrape_status(job_id)
17
+ while status.status not in ("completed", "failed", "cancelled") and asyncio.get_event_loop().time() < deadline:
18
+ await asyncio.sleep(2)
19
+ status = await client.get_batch_scrape_status(job_id)
20
+
21
+ assert status.status in ("completed", "failed", "cancelled")
22
+
23
+
24
+ @pytest.mark.asyncio
25
+ async def test_async_batch_wait_minimal(api_key, api_url):
26
+ client = AsyncFirecrawl(api_key=api_key, api_url=api_url)
27
+ job = await client.batch_scrape([
28
+ "https://docs.firecrawl.dev",
29
+ "https://firecrawl.dev",
30
+ ], formats=["markdown"], poll_interval=1, timeout=120)
31
+ assert job.status in ("completed", "failed")
32
+
33
+
34
+ @pytest.mark.asyncio
35
+ async def test_async_batch_wait_with_all_params(api_key, api_url):
36
+ client = AsyncFirecrawl(api_key=api_key, api_url=api_url)
37
+ json_schema = {"type": "object", "properties": {"title": {"type": "string"}}, "required": ["title"]}
38
+ job = await client.batch_scrape(
39
+ [
40
+ "https://docs.firecrawl.dev",
41
+ "https://firecrawl.dev",
42
+ ],
43
+ formats=[
44
+ "markdown",
45
+ {"type": "json", "prompt": "Extract page title", "schema": json_schema},
46
+ {"type": "changeTracking", "prompt": "Track changes", "modes": ["json"]},
47
+ ],
48
+ only_main_content=True,
49
+ mobile=False,
50
+ ignore_invalid_urls=True,
51
+ max_concurrency=2,
52
+ zero_data_retention=False,
53
+ poll_interval=1,
54
+ timeout=180,
55
+ integration="_e2e-test",
56
+ )
57
+ assert job.status in ("completed", "failed")
58
+
59
+
60
+ @pytest.mark.asyncio
61
+ async def test_async_cancel_batch(api_key, api_url):
62
+ client = AsyncFirecrawl(api_key=api_key, api_url=api_url)
63
+ start = await client.start_batch_scrape([
64
+ "https://docs.firecrawl.dev",
65
+ "https://firecrawl.dev",
66
+ ], formats=["markdown"], max_concurrency=1)
67
+ ok = await client.cancel_batch_scrape(start.id)
68
+ assert ok is True
69
+