firecrawl-haystack 1.0.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.
- firecrawl_haystack-1.0.0/.gitignore +146 -0
- firecrawl_haystack-1.0.0/LICENSE +201 -0
- firecrawl_haystack-1.0.0/PKG-INFO +39 -0
- firecrawl_haystack-1.0.0/README.md +15 -0
- firecrawl_haystack-1.0.0/pydoc/config_docusaurus.yml +13 -0
- firecrawl_haystack-1.0.0/pyproject.toml +164 -0
- firecrawl_haystack-1.0.0/src/haystack_integrations/components/fetchers/firecrawl/__init__.py +7 -0
- firecrawl_haystack-1.0.0/src/haystack_integrations/components/fetchers/firecrawl/firecrawl_crawler.py +198 -0
- firecrawl_haystack-1.0.0/src/haystack_integrations/components/fetchers/py.typed +0 -0
- firecrawl_haystack-1.0.0/tests/__init__.py +3 -0
- firecrawl_haystack-1.0.0/tests/test_firecrawl_crawler.py +264 -0
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
volumes/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
target/
|
|
77
|
+
|
|
78
|
+
# Jupyter Notebook
|
|
79
|
+
.ipynb_checkpoints
|
|
80
|
+
|
|
81
|
+
# IPython
|
|
82
|
+
profile_default/
|
|
83
|
+
ipython_config.py
|
|
84
|
+
|
|
85
|
+
# pyenv
|
|
86
|
+
.python-version
|
|
87
|
+
|
|
88
|
+
# pipenv
|
|
89
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
90
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
91
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
92
|
+
# install all needed dependencies.
|
|
93
|
+
#Pipfile.lock
|
|
94
|
+
|
|
95
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
96
|
+
__pypackages__/
|
|
97
|
+
|
|
98
|
+
# Celery stuff
|
|
99
|
+
celerybeat-schedule
|
|
100
|
+
celerybeat.pid
|
|
101
|
+
|
|
102
|
+
# SageMath parsed files
|
|
103
|
+
*.sage.py
|
|
104
|
+
|
|
105
|
+
# Environments
|
|
106
|
+
.env
|
|
107
|
+
.venv
|
|
108
|
+
env/
|
|
109
|
+
venv/
|
|
110
|
+
ENV/
|
|
111
|
+
env.bak/
|
|
112
|
+
venv.bak/
|
|
113
|
+
|
|
114
|
+
# Spyder project settings
|
|
115
|
+
.spyderproject
|
|
116
|
+
.spyproject
|
|
117
|
+
|
|
118
|
+
# Rope project settings
|
|
119
|
+
.ropeproject
|
|
120
|
+
|
|
121
|
+
# mkdocs documentation
|
|
122
|
+
/site
|
|
123
|
+
|
|
124
|
+
# mypy
|
|
125
|
+
.mypy_cache/
|
|
126
|
+
.dmypy.json
|
|
127
|
+
dmypy.json
|
|
128
|
+
|
|
129
|
+
# Pyre type checker
|
|
130
|
+
.pyre/
|
|
131
|
+
|
|
132
|
+
# IDEs
|
|
133
|
+
.vscode
|
|
134
|
+
|
|
135
|
+
# Docs generation artifacts
|
|
136
|
+
_readme_*.md
|
|
137
|
+
.idea
|
|
138
|
+
|
|
139
|
+
# macOS
|
|
140
|
+
.DS_Store
|
|
141
|
+
|
|
142
|
+
# http cache (requests-cache)
|
|
143
|
+
**/http_cache.sqlite
|
|
144
|
+
|
|
145
|
+
# ruff
|
|
146
|
+
.ruff_cache
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2023 deepset GmbH
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: firecrawl-haystack
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Haystack integration for Firecrawl
|
|
5
|
+
Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/firecrawl#readme
|
|
6
|
+
Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
|
|
7
|
+
Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/firecrawl
|
|
8
|
+
Author-email: deepset GmbH <info@deepset.ai>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: Firecrawl,Haystack,Web Crawler,Web Scraping
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
19
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
20
|
+
Requires-Python: >=3.10
|
|
21
|
+
Requires-Dist: firecrawl-py>=4.0.0
|
|
22
|
+
Requires-Dist: haystack-ai>=2.24.1
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# firecrawl-haystack
|
|
26
|
+
|
|
27
|
+
[](https://pypi.org/project/firecrawl-haystack)
|
|
28
|
+
[](https://pypi.org/project/firecrawl-haystack)
|
|
29
|
+
|
|
30
|
+
- [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/firecrawl/CHANGELOG.md)
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## Contributing
|
|
35
|
+
|
|
36
|
+
Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
To run integration tests locally, you need to export the `FIRECRAWL_API_KEY` environment variable.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# firecrawl-haystack
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/firecrawl-haystack)
|
|
4
|
+
[](https://pypi.org/project/firecrawl-haystack)
|
|
5
|
+
|
|
6
|
+
- [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/firecrawl/CHANGELOG.md)
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Contributing
|
|
11
|
+
|
|
12
|
+
Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
To run integration tests locally, you need to export the `FIRECRAWL_API_KEY` environment variable.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
loaders:
|
|
2
|
+
- modules:
|
|
3
|
+
- haystack_integrations.components.fetchers.firecrawl
|
|
4
|
+
search_path: [../src]
|
|
5
|
+
processors:
|
|
6
|
+
- type: filter
|
|
7
|
+
documented_only: true
|
|
8
|
+
skip_empty_modules: true
|
|
9
|
+
renderer:
|
|
10
|
+
description: Firecrawl integration for Haystack
|
|
11
|
+
id: integrations-firecrawl
|
|
12
|
+
filename: firecrawl.md
|
|
13
|
+
title: Firecrawl
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "firecrawl-haystack"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Haystack integration for Firecrawl"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
keywords = [
|
|
13
|
+
"Firecrawl",
|
|
14
|
+
"Haystack",
|
|
15
|
+
"Web Crawler",
|
|
16
|
+
"Web Scraping",
|
|
17
|
+
]
|
|
18
|
+
authors = [
|
|
19
|
+
{ name = "deepset GmbH", email = "info@deepset.ai" },
|
|
20
|
+
]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"License :: OSI Approved :: Apache Software License",
|
|
23
|
+
"Development Status :: 4 - Beta",
|
|
24
|
+
"Programming Language :: Python",
|
|
25
|
+
"Programming Language :: Python :: 3.10",
|
|
26
|
+
"Programming Language :: Python :: 3.11",
|
|
27
|
+
"Programming Language :: Python :: 3.12",
|
|
28
|
+
"Programming Language :: Python :: 3.13",
|
|
29
|
+
"Programming Language :: Python :: Implementation :: CPython",
|
|
30
|
+
]
|
|
31
|
+
dependencies = [
|
|
32
|
+
"haystack-ai>=2.24.1",
|
|
33
|
+
"firecrawl-py>=4.0.0",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/firecrawl#readme"
|
|
38
|
+
Issues = "https://github.com/deepset-ai/haystack-core-integrations/issues"
|
|
39
|
+
Source = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/firecrawl"
|
|
40
|
+
|
|
41
|
+
[tool.hatch.build.targets.wheel]
|
|
42
|
+
packages = ["src/haystack_integrations"]
|
|
43
|
+
|
|
44
|
+
[tool.hatch.version]
|
|
45
|
+
source = "vcs"
|
|
46
|
+
tag-pattern = 'integrations\/firecrawl-v(?P<version>.*)'
|
|
47
|
+
|
|
48
|
+
[tool.hatch.version.raw-options]
|
|
49
|
+
root = "../.."
|
|
50
|
+
git_describe_command = 'git describe --tags --match="integrations/firecrawl-v[0-9]*"'
|
|
51
|
+
|
|
52
|
+
[tool.hatch.envs.default]
|
|
53
|
+
installer = "uv"
|
|
54
|
+
dependencies = ["haystack-pydoc-tools", "ruff"]
|
|
55
|
+
|
|
56
|
+
[tool.hatch.envs.default.scripts]
|
|
57
|
+
docs = ["haystack-pydoc pydoc/config_docusaurus.yml"]
|
|
58
|
+
fmt = "ruff check --fix {args}; ruff format {args}"
|
|
59
|
+
fmt-check = "ruff check {args} && ruff format --check {args}"
|
|
60
|
+
|
|
61
|
+
[tool.hatch.envs.test]
|
|
62
|
+
dependencies = [
|
|
63
|
+
"pytest",
|
|
64
|
+
"pytest-asyncio",
|
|
65
|
+
"pytest-cov",
|
|
66
|
+
"pytest-rerunfailures",
|
|
67
|
+
"mypy",
|
|
68
|
+
"pip",
|
|
69
|
+
]
|
|
70
|
+
|
|
71
|
+
[tool.hatch.envs.test.scripts]
|
|
72
|
+
unit = 'pytest -m "not integration" {args:tests}'
|
|
73
|
+
integration = 'pytest -m "integration" {args:tests}'
|
|
74
|
+
all = 'pytest {args:tests}'
|
|
75
|
+
cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x {args:tests}'
|
|
76
|
+
types = "mypy -p haystack_integrations.components.fetchers.firecrawl {args}"
|
|
77
|
+
|
|
78
|
+
[tool.mypy]
|
|
79
|
+
install_types = true
|
|
80
|
+
non_interactive = true
|
|
81
|
+
check_untyped_defs = true
|
|
82
|
+
disallow_incomplete_defs = true
|
|
83
|
+
|
|
84
|
+
[tool.ruff]
|
|
85
|
+
line-length = 120
|
|
86
|
+
|
|
87
|
+
[tool.ruff.lint]
|
|
88
|
+
select = [
|
|
89
|
+
"A",
|
|
90
|
+
"ARG",
|
|
91
|
+
"B",
|
|
92
|
+
"C",
|
|
93
|
+
"DTZ",
|
|
94
|
+
"E",
|
|
95
|
+
"EM",
|
|
96
|
+
"F",
|
|
97
|
+
"I",
|
|
98
|
+
"ICN",
|
|
99
|
+
"ISC",
|
|
100
|
+
"N",
|
|
101
|
+
"PLC",
|
|
102
|
+
"PLE",
|
|
103
|
+
"PLR",
|
|
104
|
+
"PLW",
|
|
105
|
+
"Q",
|
|
106
|
+
"RUF",
|
|
107
|
+
"S",
|
|
108
|
+
"T",
|
|
109
|
+
"TID",
|
|
110
|
+
"UP",
|
|
111
|
+
"W",
|
|
112
|
+
"YTT",
|
|
113
|
+
]
|
|
114
|
+
ignore = [
|
|
115
|
+
# Allow non-abstract empty methods in abstract base classes
|
|
116
|
+
"B027",
|
|
117
|
+
# Allow function calls in argument defaults (common Haystack pattern for Secret.from_env_var)
|
|
118
|
+
"B008",
|
|
119
|
+
# zip() without strict= is OK when lengths are guaranteed equal
|
|
120
|
+
"B905",
|
|
121
|
+
# Ignore checks for possible passwords
|
|
122
|
+
"S105",
|
|
123
|
+
"S106",
|
|
124
|
+
"S107",
|
|
125
|
+
# Ignore complexity
|
|
126
|
+
"C901",
|
|
127
|
+
"PLR0911",
|
|
128
|
+
"PLR0912",
|
|
129
|
+
"PLR0913",
|
|
130
|
+
"PLR0915",
|
|
131
|
+
]
|
|
132
|
+
unfixable = [
|
|
133
|
+
# Don't touch unused imports
|
|
134
|
+
"F401",
|
|
135
|
+
]
|
|
136
|
+
|
|
137
|
+
[tool.ruff.lint.isort]
|
|
138
|
+
known-first-party = ["haystack_integrations"]
|
|
139
|
+
|
|
140
|
+
[tool.ruff.lint.flake8-tidy-imports]
|
|
141
|
+
ban-relative-imports = "parents"
|
|
142
|
+
|
|
143
|
+
[tool.ruff.lint.per-file-ignores]
|
|
144
|
+
# Tests can use magic values, assertions, and relative imports
|
|
145
|
+
"tests/**/*" = ["PLR2004", "S101", "TID252"]
|
|
146
|
+
|
|
147
|
+
[tool.coverage.run]
|
|
148
|
+
source = ["haystack_integrations"]
|
|
149
|
+
branch = true
|
|
150
|
+
parallel = false
|
|
151
|
+
|
|
152
|
+
[tool.coverage.report]
|
|
153
|
+
omit = ["*/tests/*", "*/__init__.py"]
|
|
154
|
+
show_missing = true
|
|
155
|
+
exclude_lines = ["no cov", "if __name__ == .__main__.:", "if TYPE_CHECKING:"]
|
|
156
|
+
|
|
157
|
+
[tool.pytest.ini_options]
|
|
158
|
+
addopts = "--strict-markers"
|
|
159
|
+
markers = [
|
|
160
|
+
"unit: unit tests",
|
|
161
|
+
"integration: integration tests",
|
|
162
|
+
]
|
|
163
|
+
log_cli = true
|
|
164
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from datetime import datetime, timezone
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from haystack import Document, component, logging
|
|
9
|
+
from haystack.utils import Secret
|
|
10
|
+
|
|
11
|
+
from firecrawl import AsyncFirecrawl, Firecrawl # type: ignore[import-untyped]
|
|
12
|
+
|
|
13
|
+
logger = logging.getLogger(__name__)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@component
|
|
17
|
+
class FirecrawlCrawler:
|
|
18
|
+
"""
|
|
19
|
+
A component that uses Firecrawl to crawl one or more URLs and return the content as Haystack Documents.
|
|
20
|
+
|
|
21
|
+
Crawling starts from each given URL and follows links to discover subpages, up to a configurable limit.
|
|
22
|
+
This is useful for ingesting entire websites or documentation sites, not just single pages.
|
|
23
|
+
|
|
24
|
+
Firecrawl is a service that crawls websites and returns content in a structured format (e.g. Markdown)
|
|
25
|
+
suitable for LLMs. You need a Firecrawl API key from [firecrawl.dev](https://firecrawl.dev).
|
|
26
|
+
|
|
27
|
+
### Usage example
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from haystack_integrations.components.fetchers.firecrawl import FirecrawlFetcher
|
|
31
|
+
|
|
32
|
+
fetcher = FirecrawlFetcher(
|
|
33
|
+
api_key=Secret.from_env_var("FIRECRAWL_API_KEY"),
|
|
34
|
+
params={"limit": 5},
|
|
35
|
+
)
|
|
36
|
+
fetcher.warm_up()
|
|
37
|
+
|
|
38
|
+
result = fetcher.run(urls=["https://docs.haystack.deepset.ai/docs/intro"])
|
|
39
|
+
documents = result["documents"]
|
|
40
|
+
```
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self,
|
|
45
|
+
api_key: Secret = Secret.from_env_var("FIRECRAWL_API_KEY"),
|
|
46
|
+
params: dict[str, Any] | None = None,
|
|
47
|
+
) -> None:
|
|
48
|
+
"""
|
|
49
|
+
Initialize the FirecrawlFetcher.
|
|
50
|
+
|
|
51
|
+
:param api_key:
|
|
52
|
+
API key for Firecrawl.
|
|
53
|
+
Defaults to the `FIRECRAWL_API_KEY` environment variable.
|
|
54
|
+
:param params:
|
|
55
|
+
Parameters for the crawl request. See the
|
|
56
|
+
[Firecrawl API reference](https://docs.firecrawl.dev/api-reference/endpoint/crawl-post)
|
|
57
|
+
for available parameters.
|
|
58
|
+
Defaults to `{"limit": 1, "scrape_options": {"formats": ["markdown"]}}`.
|
|
59
|
+
Without a limit, Firecrawl may crawl all subpages and consume credits quickly.
|
|
60
|
+
"""
|
|
61
|
+
self.api_key = api_key
|
|
62
|
+
self.params = params
|
|
63
|
+
self._params = {} if params is None else params.copy()
|
|
64
|
+
self._params.setdefault("limit", 1)
|
|
65
|
+
self._params.setdefault("scrape_options", {"formats": ["markdown"]})
|
|
66
|
+
self._firecrawl_client: Firecrawl | None = None
|
|
67
|
+
self._async_firecrawl_client: AsyncFirecrawl | None = None
|
|
68
|
+
|
|
69
|
+
@component.output_types(documents=list[Document])
|
|
70
|
+
def run(
|
|
71
|
+
self,
|
|
72
|
+
urls: list[str],
|
|
73
|
+
params: dict[str, Any] | None = None,
|
|
74
|
+
) -> dict[str, Any]:
|
|
75
|
+
"""
|
|
76
|
+
Crawls the given URLs and returns the extracted content as Documents.
|
|
77
|
+
|
|
78
|
+
:param urls:
|
|
79
|
+
List of URLs to crawl.
|
|
80
|
+
:param params:
|
|
81
|
+
Optional override of crawl parameters for this run.
|
|
82
|
+
If provided, fully replaces the init-time params.
|
|
83
|
+
:returns: A dictionary with the following keys:
|
|
84
|
+
- `documents`: List of documents, one for each URL crawled.
|
|
85
|
+
"""
|
|
86
|
+
if self._firecrawl_client is None:
|
|
87
|
+
self.warm_up()
|
|
88
|
+
|
|
89
|
+
current_params = params if params is not None else self._params
|
|
90
|
+
documents: list[Document] = []
|
|
91
|
+
for url in urls:
|
|
92
|
+
docs = self._crawl_url(url=url, params=current_params)
|
|
93
|
+
documents.extend(docs)
|
|
94
|
+
|
|
95
|
+
return {"documents": documents}
|
|
96
|
+
|
|
97
|
+
@component.output_types(documents=list[Document])
|
|
98
|
+
async def run_async(
|
|
99
|
+
self,
|
|
100
|
+
urls: list[str],
|
|
101
|
+
params: dict[str, Any] | None = None,
|
|
102
|
+
) -> dict[str, Any]:
|
|
103
|
+
"""
|
|
104
|
+
Asynchronously crawls the given URLs and returns the extracted content as Documents.
|
|
105
|
+
|
|
106
|
+
:param urls:
|
|
107
|
+
List of URLs to crawl.
|
|
108
|
+
:param params:
|
|
109
|
+
Optional override of crawl parameters for this run.
|
|
110
|
+
If provided, fully replaces the init-time params.
|
|
111
|
+
:returns: A dictionary with the following keys:
|
|
112
|
+
- `documents`: List of documents, one for each URL crawled.
|
|
113
|
+
"""
|
|
114
|
+
if self._async_firecrawl_client is None:
|
|
115
|
+
self.warm_up()
|
|
116
|
+
|
|
117
|
+
current_params = params if params is not None else self._params
|
|
118
|
+
documents: list[Document] = []
|
|
119
|
+
for url in urls:
|
|
120
|
+
docs = await self._crawl_url_async(url=url, params=current_params)
|
|
121
|
+
documents.extend(docs)
|
|
122
|
+
|
|
123
|
+
return {"documents": documents}
|
|
124
|
+
|
|
125
|
+
def warm_up(self) -> None:
|
|
126
|
+
"""
|
|
127
|
+
Warm up the Firecrawl client by initializing the clients.
|
|
128
|
+
This is useful to avoid cold start delays when crawling many URLs.
|
|
129
|
+
"""
|
|
130
|
+
if self._firecrawl_client is None:
|
|
131
|
+
self._firecrawl_client = Firecrawl(api_key=self.api_key.resolve_value())
|
|
132
|
+
if self._async_firecrawl_client is None:
|
|
133
|
+
self._async_firecrawl_client = AsyncFirecrawl(api_key=self.api_key.resolve_value())
|
|
134
|
+
|
|
135
|
+
def _crawl_url(self, url: str, params: dict[str, Any]) -> list[Document]:
|
|
136
|
+
"""
|
|
137
|
+
Crawl a single URL and return Documents.
|
|
138
|
+
|
|
139
|
+
:param url: URL to crawl.
|
|
140
|
+
:param params: Crawl request parameters.
|
|
141
|
+
:return: List of Documents from the crawl result.
|
|
142
|
+
"""
|
|
143
|
+
try:
|
|
144
|
+
# Ignoring type because the firecrawl client is initialized as None and only set during warm_up
|
|
145
|
+
crawl_response = self._firecrawl_client.crawl( # type: ignore[union-attr]
|
|
146
|
+
url=url,
|
|
147
|
+
**params,
|
|
148
|
+
)
|
|
149
|
+
except Exception as error:
|
|
150
|
+
logger.exception(f"Failed to crawl website {url}: {error}")
|
|
151
|
+
return []
|
|
152
|
+
|
|
153
|
+
return self._documents_from_crawl_response(url=url, crawl_response=crawl_response)
|
|
154
|
+
|
|
155
|
+
async def _crawl_url_async(self, url: str, params: dict[str, Any]) -> list[Document]:
|
|
156
|
+
"""
|
|
157
|
+
Asynchronously crawl a single URL and return Documents.
|
|
158
|
+
|
|
159
|
+
:param url: URL to crawl.
|
|
160
|
+
:param params: Crawl request parameters.
|
|
161
|
+
:return: List of Documents from the crawl result.
|
|
162
|
+
"""
|
|
163
|
+
try:
|
|
164
|
+
# Ignoring type because the firecrawl client is initialized as None and only set during warm_up
|
|
165
|
+
crawl_response = await self._async_firecrawl_client.crawl( # type: ignore[union-attr]
|
|
166
|
+
url=url,
|
|
167
|
+
**params,
|
|
168
|
+
)
|
|
169
|
+
except Exception as error:
|
|
170
|
+
logger.exception(f"Failed to crawl website {url}: {error}")
|
|
171
|
+
return []
|
|
172
|
+
|
|
173
|
+
return self._documents_from_crawl_response(url=url, crawl_response=crawl_response)
|
|
174
|
+
|
|
175
|
+
def _documents_from_crawl_response(self, url: str, crawl_response: Any) -> list[Document]:
|
|
176
|
+
"""
|
|
177
|
+
Convert a Firecrawl crawl response to Haystack Documents.
|
|
178
|
+
|
|
179
|
+
:param url: URL that was crawled.
|
|
180
|
+
:param crawl_response: Firecrawl crawl response.
|
|
181
|
+
:return: List of documents built from crawled pages.
|
|
182
|
+
"""
|
|
183
|
+
if crawl_response.status != "completed":
|
|
184
|
+
logger.exception(f"Failed to crawl website {url}: {crawl_response.status}")
|
|
185
|
+
|
|
186
|
+
documents: list[Document] = []
|
|
187
|
+
for page in crawl_response.data:
|
|
188
|
+
metadata = page.metadata_dict
|
|
189
|
+
doc = Document(
|
|
190
|
+
content=page.markdown,
|
|
191
|
+
meta={
|
|
192
|
+
"timestamp": datetime.now(tz=timezone.utc).isoformat(),
|
|
193
|
+
**metadata,
|
|
194
|
+
},
|
|
195
|
+
)
|
|
196
|
+
documents.append(doc)
|
|
197
|
+
|
|
198
|
+
return documents
|
|
File without changes
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present deepset GmbH <info@deepset.ai>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
from unittest.mock import AsyncMock, MagicMock, patch
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
from firecrawl.v2.utils.error_handler import UnauthorizedError
|
|
10
|
+
from haystack import Document
|
|
11
|
+
from haystack.core.serialization import component_from_dict, component_to_dict
|
|
12
|
+
from haystack.utils import Secret
|
|
13
|
+
|
|
14
|
+
from haystack_integrations.components.fetchers.firecrawl import FirecrawlCrawler
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
class TestFirecrawlCrawler:
|
|
18
|
+
@pytest.fixture
|
|
19
|
+
def page(self) -> MagicMock:
|
|
20
|
+
page = MagicMock()
|
|
21
|
+
page.markdown = "Page content"
|
|
22
|
+
page.metadata_dict = {"url": "https://example.com"}
|
|
23
|
+
return page
|
|
24
|
+
|
|
25
|
+
@pytest.fixture
|
|
26
|
+
def crawl_response(self, page) -> MagicMock:
|
|
27
|
+
crawl_response = MagicMock()
|
|
28
|
+
crawl_response.status = "completed"
|
|
29
|
+
crawl_response.data = [page]
|
|
30
|
+
return crawl_response
|
|
31
|
+
|
|
32
|
+
@pytest.fixture
|
|
33
|
+
def mock_client(self, crawl_response) -> MagicMock:
|
|
34
|
+
mock_client = MagicMock()
|
|
35
|
+
mock_client.crawl.return_value = crawl_response
|
|
36
|
+
return mock_client
|
|
37
|
+
|
|
38
|
+
@pytest.fixture
|
|
39
|
+
def mock_async_client(self, crawl_response) -> MagicMock:
|
|
40
|
+
mock_async_client = MagicMock()
|
|
41
|
+
mock_async_client.crawl = AsyncMock(return_value=crawl_response)
|
|
42
|
+
return mock_async_client
|
|
43
|
+
|
|
44
|
+
def test_init_default(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
45
|
+
monkeypatch.setenv("FIRECRAWL_API_KEY", "test-key")
|
|
46
|
+
fetcher = FirecrawlCrawler()
|
|
47
|
+
assert fetcher._params == {"limit": 1, "scrape_options": {"formats": ["markdown"]}}
|
|
48
|
+
assert fetcher.api_key.resolve_value() == "test-key"
|
|
49
|
+
|
|
50
|
+
def test_init_with_params(self) -> None:
|
|
51
|
+
fetcher = FirecrawlCrawler(
|
|
52
|
+
api_key=Secret.from_token("custom-key"),
|
|
53
|
+
params={"limit": 10},
|
|
54
|
+
)
|
|
55
|
+
assert fetcher._params == {"limit": 10, "scrape_options": {"formats": ["markdown"]}}
|
|
56
|
+
assert fetcher.api_key.resolve_value() == "custom-key"
|
|
57
|
+
|
|
58
|
+
def test_to_dict(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
59
|
+
monkeypatch.setenv("FIRECRAWL_API_KEY", "test-key")
|
|
60
|
+
fetcher = FirecrawlCrawler(
|
|
61
|
+
api_key=Secret.from_env_var("FIRECRAWL_API_KEY"),
|
|
62
|
+
params={"limit": 5},
|
|
63
|
+
)
|
|
64
|
+
data = component_to_dict(fetcher, "FirecrawlFetcher")
|
|
65
|
+
assert data["type"] == "haystack_integrations.components.fetchers.firecrawl.firecrawl_crawler.FirecrawlCrawler"
|
|
66
|
+
assert data["init_parameters"]["params"] == {"limit": 5}
|
|
67
|
+
assert "api_key" in data["init_parameters"]
|
|
68
|
+
|
|
69
|
+
def test_from_dict(self, monkeypatch: pytest.MonkeyPatch) -> None:
|
|
70
|
+
monkeypatch.setenv("FIRECRAWL_API_KEY", "test-key")
|
|
71
|
+
data = {
|
|
72
|
+
"type": "haystack_integrations.components.fetchers.firecrawl.firecrawl_crawler.FirecrawlCrawler",
|
|
73
|
+
"init_parameters": {
|
|
74
|
+
"params": {"limit": 3},
|
|
75
|
+
"api_key": {"env_vars": ["FIRECRAWL_API_KEY"], "strict": True, "type": "env_var"},
|
|
76
|
+
},
|
|
77
|
+
}
|
|
78
|
+
fetcher = component_from_dict(FirecrawlCrawler, data, "FirecrawlFetcher")
|
|
79
|
+
assert fetcher.params == {"limit": 3}
|
|
80
|
+
assert fetcher.api_key.resolve_value() == "test-key"
|
|
81
|
+
|
|
82
|
+
def test_run_with_mocked_firecrawl_client(self, mock_client) -> None:
|
|
83
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_token("test-key"))
|
|
84
|
+
|
|
85
|
+
fetcher._firecrawl_client = mock_client
|
|
86
|
+
|
|
87
|
+
result = fetcher.run(urls=["https://example.com", "https://docs.example.com"])
|
|
88
|
+
|
|
89
|
+
assert len(result["documents"]) == 2
|
|
90
|
+
assert all(isinstance(doc, Document) for doc in result["documents"])
|
|
91
|
+
assert result["documents"][0].content == "Page content"
|
|
92
|
+
assert result["documents"][0].meta["url"] == "https://example.com"
|
|
93
|
+
|
|
94
|
+
assert mock_client.crawl.call_count == 2
|
|
95
|
+
mock_client.crawl.assert_any_call(
|
|
96
|
+
url="https://example.com",
|
|
97
|
+
limit=1,
|
|
98
|
+
scrape_options={"formats": ["markdown"]},
|
|
99
|
+
)
|
|
100
|
+
mock_client.crawl.assert_any_call(
|
|
101
|
+
url="https://docs.example.com",
|
|
102
|
+
limit=1,
|
|
103
|
+
scrape_options={"formats": ["markdown"]},
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
def test_run_overrides_init_params_with_runtime_params(self, mock_client) -> None:
|
|
107
|
+
fetcher = FirecrawlCrawler(
|
|
108
|
+
api_key=Secret.from_token("test-key"),
|
|
109
|
+
params={"limit": 1, "scrape_options": {"formats": ["markdown"]}},
|
|
110
|
+
)
|
|
111
|
+
|
|
112
|
+
fetcher._firecrawl_client = mock_client
|
|
113
|
+
|
|
114
|
+
fetcher.run(urls=["https://example.com"], params={"limit": 5})
|
|
115
|
+
|
|
116
|
+
mock_client.crawl.assert_called_once_with(
|
|
117
|
+
url="https://example.com",
|
|
118
|
+
limit=5,
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
@pytest.mark.asyncio
|
|
122
|
+
async def test_run_async_uses_async_firecrawl_client(self, mock_async_client) -> None:
|
|
123
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_token("test-key"))
|
|
124
|
+
|
|
125
|
+
fetcher._async_firecrawl_client = mock_async_client
|
|
126
|
+
|
|
127
|
+
result = await fetcher.run_async(urls=["https://example.com"], params={"limit": 2})
|
|
128
|
+
|
|
129
|
+
assert len(result["documents"]) == 1
|
|
130
|
+
assert result["documents"][0].content == "Page content"
|
|
131
|
+
assert result["documents"][0].meta["url"] == "https://example.com"
|
|
132
|
+
mock_async_client.crawl.assert_awaited_once_with(
|
|
133
|
+
url="https://example.com",
|
|
134
|
+
limit=2,
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
def test_run_calls_warm_up(self, crawl_response) -> None:
|
|
138
|
+
with (
|
|
139
|
+
patch(
|
|
140
|
+
"haystack_integrations.components.fetchers.firecrawl.firecrawl_crawler.Firecrawl"
|
|
141
|
+
) as mock_firecrawl_client,
|
|
142
|
+
patch("haystack_integrations.components.fetchers.firecrawl.firecrawl_crawler.AsyncFirecrawl"),
|
|
143
|
+
):
|
|
144
|
+
mock_firecrawl_client.return_value.crawl.return_value = crawl_response
|
|
145
|
+
|
|
146
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_token("test-key"))
|
|
147
|
+
fetcher.run(urls=["https://example.com"])
|
|
148
|
+
|
|
149
|
+
assert fetcher._firecrawl_client is mock_firecrawl_client.return_value
|
|
150
|
+
mock_firecrawl_client.assert_called_once_with(api_key="test-key")
|
|
151
|
+
|
|
152
|
+
@pytest.mark.asyncio
|
|
153
|
+
async def test_run_async_calls_warm_up(self, crawl_response) -> None:
|
|
154
|
+
with (
|
|
155
|
+
patch("haystack_integrations.components.fetchers.firecrawl.firecrawl_crawler.Firecrawl"),
|
|
156
|
+
patch(
|
|
157
|
+
"haystack_integrations.components.fetchers.firecrawl.firecrawl_crawler.AsyncFirecrawl"
|
|
158
|
+
) as mock_async_firecrawl_client,
|
|
159
|
+
):
|
|
160
|
+
mock_async_firecrawl_client.return_value.crawl = AsyncMock(return_value=crawl_response)
|
|
161
|
+
|
|
162
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_token("test-key"))
|
|
163
|
+
await fetcher.run_async(urls=["https://example.com"])
|
|
164
|
+
|
|
165
|
+
assert fetcher._async_firecrawl_client is mock_async_firecrawl_client.return_value
|
|
166
|
+
mock_async_firecrawl_client.assert_called_once_with(api_key="test-key")
|
|
167
|
+
|
|
168
|
+
def test_run_returns_empty_on_crawl_error(self, mock_client) -> None:
|
|
169
|
+
mock_client.crawl.side_effect = UnauthorizedError(
|
|
170
|
+
"Unauthorized: Failed to start crawl. Unauthorized: Invalid token - No additional error details provided."
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_token("test-key"))
|
|
174
|
+
fetcher._firecrawl_client = mock_client
|
|
175
|
+
|
|
176
|
+
result = fetcher.run(urls=["https://example.com"])
|
|
177
|
+
|
|
178
|
+
assert result["documents"] == []
|
|
179
|
+
mock_client.crawl.assert_called_once()
|
|
180
|
+
|
|
181
|
+
@pytest.mark.asyncio
|
|
182
|
+
async def test_run_async_returns_empty_on_crawl_error(self, mock_async_client) -> None:
|
|
183
|
+
mock_async_client.crawl = AsyncMock(
|
|
184
|
+
side_effect=UnauthorizedError(
|
|
185
|
+
"Unauthorized: Failed to start crawl. Unauthorized: Invalid token"
|
|
186
|
+
" - No additional error details provided."
|
|
187
|
+
)
|
|
188
|
+
)
|
|
189
|
+
|
|
190
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_token("test-key"))
|
|
191
|
+
fetcher._async_firecrawl_client = mock_async_client
|
|
192
|
+
|
|
193
|
+
result = await fetcher.run_async(urls=["https://example.com"])
|
|
194
|
+
|
|
195
|
+
assert result["documents"] == []
|
|
196
|
+
mock_async_client.crawl.assert_awaited_once()
|
|
197
|
+
|
|
198
|
+
def test_run_logs_error_on_failed_crawl_status(self, mock_client, page, caplog) -> None:
|
|
199
|
+
failed_response = MagicMock()
|
|
200
|
+
failed_response.status = "failed"
|
|
201
|
+
failed_response.data = [page]
|
|
202
|
+
mock_client.crawl.return_value = failed_response
|
|
203
|
+
|
|
204
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_token("test-key"))
|
|
205
|
+
fetcher._firecrawl_client = mock_client
|
|
206
|
+
|
|
207
|
+
fetcher.run(urls=["https://example.com"])
|
|
208
|
+
|
|
209
|
+
assert "Failed to crawl website https://example.com: failed" in caplog.text
|
|
210
|
+
|
|
211
|
+
@pytest.mark.asyncio
|
|
212
|
+
async def test_run_async_logs_error_on_failed_crawl_status(self, mock_async_client, page, caplog) -> None:
|
|
213
|
+
failed_response = MagicMock()
|
|
214
|
+
failed_response.status = "failed"
|
|
215
|
+
failed_response.data = [page]
|
|
216
|
+
mock_async_client.crawl = AsyncMock(return_value=failed_response)
|
|
217
|
+
|
|
218
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_token("test-key"))
|
|
219
|
+
fetcher._async_firecrawl_client = mock_async_client
|
|
220
|
+
|
|
221
|
+
await fetcher.run_async(urls=["https://example.com"])
|
|
222
|
+
|
|
223
|
+
assert "Failed to crawl website https://example.com: failed" in caplog.text
|
|
224
|
+
|
|
225
|
+
def test_warm_up_initializes_clients(self) -> None:
|
|
226
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_token("test-key"))
|
|
227
|
+
assert fetcher._firecrawl_client is None
|
|
228
|
+
assert fetcher._async_firecrawl_client is None
|
|
229
|
+
|
|
230
|
+
fetcher.warm_up()
|
|
231
|
+
|
|
232
|
+
assert fetcher._firecrawl_client is not None
|
|
233
|
+
assert fetcher._async_firecrawl_client is not None
|
|
234
|
+
|
|
235
|
+
@pytest.mark.skipif(
|
|
236
|
+
not os.environ.get("FIRECRAWL_API_KEY"),
|
|
237
|
+
reason="Export FIRECRAWL_API_KEY to run integration tests.",
|
|
238
|
+
)
|
|
239
|
+
@pytest.mark.integration
|
|
240
|
+
def test_run_integration(self) -> None:
|
|
241
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_env_var("FIRECRAWL_API_KEY"), params={"limit": 1})
|
|
242
|
+
result = fetcher.run(urls=["https://docs.haystack.deepset.ai/docs/intro"], params={"limit": 1})
|
|
243
|
+
|
|
244
|
+
assert "documents" in result
|
|
245
|
+
assert isinstance(result["documents"], list)
|
|
246
|
+
assert len(result["documents"]) > 0
|
|
247
|
+
assert "Haystack" in result["documents"][0].content
|
|
248
|
+
assert "https://docs.haystack.deepset.ai/docs/intro" == result["documents"][0].meta["url"]
|
|
249
|
+
|
|
250
|
+
@pytest.mark.skipif(
|
|
251
|
+
not os.environ.get("FIRECRAWL_API_KEY"),
|
|
252
|
+
reason="Export FIRECRAWL_API_KEY to run integration tests.",
|
|
253
|
+
)
|
|
254
|
+
@pytest.mark.integration
|
|
255
|
+
@pytest.mark.asyncio
|
|
256
|
+
async def test_run_async_integration(self) -> None:
|
|
257
|
+
fetcher = FirecrawlCrawler(api_key=Secret.from_env_var("FIRECRAWL_API_KEY"), params={"limit": 1})
|
|
258
|
+
result = await fetcher.run_async(urls=["https://docs.haystack.deepset.ai/docs/intro"])
|
|
259
|
+
|
|
260
|
+
assert "documents" in result
|
|
261
|
+
assert isinstance(result["documents"], list)
|
|
262
|
+
assert len(result["documents"]) > 0
|
|
263
|
+
assert "Haystack" in result["documents"][0].content
|
|
264
|
+
assert "https://docs.haystack.deepset.ai/docs/intro" == result["documents"][0].meta["url"]
|