Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Nick: added /search to the python sdk

Nicolasa32e16a9beba
diff --git a/apps/python-sdk/README.md b/apps/python-sdk/README.md
index 0a802028b..02ad3079d 100644
--- a/apps/python-sdk/README.md
+++ b/apps/python-sdk/README.md
@@ -47,6 +47,15 @@ url = 'https://example.com'
scraped_data = app.scrape_url(url)
```
+### Search for a query
+
+Used to search the web, get the most relevant results, scrap each page and return the markdown.
+
+```python
+query = 'what is mendable?'
+search_result = app.search(query)
+```
+
### Crawling a Website
To crawl a website, use the `crawl_url` 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.
diff --git a/apps/python-sdk/build/lib/firecrawl/firecrawl.py b/apps/python-sdk/build/lib/firecrawl/firecrawl.py
index f1f5e6e4e..ef3eb532e 100644
--- a/apps/python-sdk/build/lib/firecrawl/firecrawl.py
+++ b/apps/python-sdk/build/lib/firecrawl/firecrawl.py
@@ -32,6 +32,32 @@ class FirecrawlApp:
raise Exception(f'Failed to scrape URL. Status code: {response.status_code}. Error: {error_message}')
else:
raise Exception(f'Failed to scrape URL. Status code: {response.status_code}')
+
+ def search(self, query, params=None):
+ headers = {
+ 'Content-Type': 'application/json',
+ 'Authorization': f'Bearer {self.api_key}'
+ }
+ json_data = {'query': query}
+ if params:
+ json_data.update(params)
+ response = requests.post(
+ 'https://api.firecrawl.dev/v0/search',
+ headers=headers,
+ json=json_data
+ )
+ if response.status_code == 200:
+ response = response.json()
+ if response['success'] == True:
+ return response['data']
+ else:
+ raise Exception(f'Failed to search. Error: {response["error"]}')
+
+ elif response.status_code in [402, 409, 500]:
+ error_message = response.json().get('error', 'Unknown error occurred')
+ raise Exception(f'Failed to search. Status code: {response.status_code}. Error: {error_message}')
+ else:
+ raise Exception(f'Failed to search. Status code: {response.status_code}')
def crawl_url(self, url, params=None, wait_until_done=True, timeout=2):
headers = self._prepare_headers()
diff --git a/apps/python-sdk/dist/firecrawl-py-0.0.5.tar.gz b/apps/python-sdk/dist/firecrawl-py-0.0.5.tar.gz
deleted file mode 100644
index fab06b75d..000000000
Binary files a/apps/python-sdk/dist/firecrawl-py-0.0.5.tar.gz and /dev/null differ
diff --git a/apps/python-sdk/dist/firecrawl-py-0.0.6.tar.gz b/apps/python-sdk/dist/firecrawl-py-0.0.6.tar.gz
new file mode 100644
index 000000000..c1b4206e6
Binary files /dev/null and b/apps/python-sdk/dist/firecrawl-py-0.0.6.tar.gz differ
diff --git a/apps/python-sdk/dist/firecrawl_py-0.0.5-py3-none-any.whl b/apps/python-sdk/dist/firecrawl_py-0.0.5-py3-none-any.whl
deleted file mode 100644
index b32d0c82e..000000000
Binary files a/apps/python-sdk/dist/firecrawl_py-0.0.5-py3-none-any.whl and /dev/null differ
diff --git a/apps/python-sdk/dist/firecrawl_py-0.0.6-py3-none-any.whl b/apps/python-sdk/dist/firecrawl_py-0.0.6-py3-none-any.whl
new file mode 100644
index 000000000..5aba56187
Binary files /dev/null and b/apps/python-sdk/dist/firecrawl_py-0.0.6-py3-none-any.whl differ
diff --git a/apps/python-sdk/firecrawl/__pycache__/__init__.cpython-311.pyc b/apps/python-sdk/firecrawl/__pycache__/__init__.cpython-311.pyc
index 4926b8084..605b3df71 100644
Binary files a/apps/python-sdk/firecrawl/__pycache__/__init__.cpython-311.pyc and b/apps/python-sdk/firecrawl/__pycache__/__init__.cpython-311.pyc differ
diff --git a/apps/python-sdk/firecrawl/__pycache__/firecrawl.cpython-311.pyc b/apps/python-sdk/firecrawl/__pycache__/firecrawl.cpython-311.pyc
index 694553e2f..7c98fa33c 100644
Binary files a/apps/python-sdk/firecrawl/__pycache__/firecrawl.cpython-311.pyc and b/apps/python-sdk/firecrawl/__pycache__/firecrawl.cpython-311.pyc differ
diff --git a/apps/python-sdk/firecrawl/firecrawl.py b/apps/python-sdk/firecrawl/firecrawl.py
index f1f5e6e4e..ef3eb532e 100644
--- a/apps/python-sdk/firecrawl/firecrawl.py
+++ b/apps/python-sdk/firecrawl/firecrawl.py
@@ -32,6 +32,32 @@ class FirecrawlApp:
raise Exception(f'Failed to scrape URL. Status code: {response.status_code}. Error: {error_message}')
else:
raise Exception(f'Failed to scrape URL. Status code: {response.status_code}')
+
+ def search(self, query, params=None):
+ headers = {
+ 'Content-Type': 'application/json',
+ 'Authorization': f'Bearer {self.api_key}'
+ }
+ json_data = {'query': query}
+ if params:
+ json_data.update(params)
+ response = requests.post(
+ 'https://api.firecrawl.dev/v0/search',
+ headers=headers,
+ json=json_data
+ )
+ if response.status_code == 200:
+ response = response.json()
+ if response['success'] == True:
+ return response['data']
+ else:
+ raise Exception(f'Failed to search. Error: {response["error"]}')
+
+ elif response.status_code in [402, 409, 500]:
+ error_message = response.json().get('error', 'Unknown error occurred')
+ raise Exception(f'Failed to search. Status code: {response.status_code}. Error: {error_message}')
+ else:
+ raise Exception(f'Failed to search. Status code: {response.status_code}')
def crawl_url(self, url, params=None, wait_until_done=True, timeout=2):
headers = self._prepare_headers()
diff --git a/apps/python-sdk/firecrawl_py.egg-info/PKG-INFO b/apps/python-sdk/firecrawl_py.egg-info/PKG-INFO
index ad0bd09c8..61589c224 100644
--- a/apps/python-sdk/firecrawl_py.egg-info/PKG-INFO
+++ b/apps/python-sdk/firecrawl_py.egg-info/PKG-INFO
@@ -1,7 +1,7 @@
Metadata-Version: 2.1
Name: firecrawl-py
-Version: 0.0.5
+Version: 0.0.6
Summary: Python SDK for Firecrawl API
-Home-page: https://github.com/mendableai/firecrawl-py
+Home-page: https://github.com/mendableai/firecrawl
Author: Mendable.ai
Author-email: [email protected]
diff --git a/apps/python-sdk/setup.py b/apps/python-sdk/setup.py
index d2fc6b81e..a3589e343 100644
--- a/apps/python-sdk/setup.py
+++ b/apps/python-sdk/setup.py
@@ -2,8 +2,8 @@ from setuptools import setup, find_packages
setup(
name='firecrawl-py',
- version='0.0.5',
- url='https://github.com/mendableai/firecrawl-py',
+ version='0.0.6',
+ url='https://github.com/mendableai/firecrawl',
author='Mendable.ai',
author_email='[email protected]',
description='Python SDK for Firecrawl API',