Allows python sdk to be used with local installs.
Showing the changes to apps/python-sdk (1 of 1 file). Show all
Unified · Split
| @@ -4,10 +4,11 @@ import requests · 3 unmodified lines | |||
| 4 | import time | 4 | import time |
| 5 | 5 | ||
| 6 | class FirecrawlApp: | 6 | class FirecrawlApp: |
| 7 | def __init__(self, api_key=None): | 7 | def __init__(self, api_key=None, api_url='https://api.firecrawl.dev'): |
| 8 | self.api_key = api_key or os.getenv('FIRECRAWL_API_KEY') | 8 | self.api_key = api_key or os.getenv('FIRECRAWL_API_KEY') |
| 9 | if self.api_key is None: | 9 | if self.api_key is None: |
| 10 | raise ValueError('No API key provided') | 10 | raise ValueError('No API key provided') |
| 11 | self.api_url = api_url or os.getenv('FIRECRAWL_API_URL') | ||
| 11 | 12 | ||
| 12 | 13 | ||
| 13 | 14 | ||
| @@ -38,7 +39,7 @@ class FirecrawlApp: · 24 unmodified lines | |||
| 38 | scrape_params[key] = value | 39 | scrape_params[key] = value |
| 39 | # Make the POST request with the prepared headers and JSON data | 40 | # Make the POST request with the prepared headers and JSON data |
| 40 | response = requests.post( | 41 | response = requests.post( |
| 41 | 'https://api.firecrawl.dev/v0/scrape', | 42 | f'{self.api_url}/v0/scrape', |
| 42 | headers=headers, | 43 | headers=headers, |
| 43 | json=scrape_params | 44 | json=scrape_params |
| 44 | ) | 45 | ) |
| @@ -63,7 +64,7 @@ class FirecrawlApp: · 18 unmodified lines | |||
| 63 | if params: | 64 | if params: |
| 64 | json_data.update(params) | 65 | json_data.update(params) |
| 65 | response = requests.post( | 66 | response = requests.post( |
| 66 | 'https://api.firecrawl.dev/v0/search', | 67 | f'{self.api_url}/v0/search', |
| 67 | headers=headers, | 68 | headers=headers, |
| 68 | json=json_data | 69 | json=json_data |
| 69 | ) | 70 | ) |
| @@ -85,7 +86,7 @@ class FirecrawlApp: · 15 unmodified lines | |||
| 85 | json_data = {'url': url} | 86 | json_data = {'url': url} |
| 86 | if params: | 87 | if params: |
| 87 | json_data.update(params) | 88 | json_data.update(params) |
| 88 | response = self._post_request('https://api.firecrawl.dev/v0/crawl', json_data, headers) | 89 | response = self._post_request(f'{self.api_url}/v0/crawl', json_data, headers) |
| 89 | if response.status_code == 200: | 90 | if response.status_code == 200: |
| 90 | job_id = response.json().get('jobId') | 91 | job_id = response.json().get('jobId') |
| 91 | if wait_until_done: | 92 | if wait_until_done: |
| @@ -97,7 +98,7 @@ class FirecrawlApp: · 5 unmodified lines | |||
| 97 | 98 | ||
| 98 | def check_crawl_status(self, job_id): | 99 | def check_crawl_status(self, job_id): |
| 99 | headers = self._prepare_headers() | 100 | headers = self._prepare_headers() |
| 100 | response = self._get_request(f'https://api.firecrawl.dev/v0/crawl/status/{job_id}', headers) | 101 | response = self._get_request(f'{self.api_url}/v0/crawl/status/{job_id}', headers) |
| 101 | if response.status_code == 200: | 102 | if response.status_code == 200: |
| 102 | return response.json() | 103 | return response.json() |
| 103 | else: | 104 | else: |
| @@ -130,7 +131,7 @@ class FirecrawlApp: · 26 unmodified lines | |||
| 130 | def _monitor_job_status(self, job_id, headers, timeout): | 131 | def _monitor_job_status(self, job_id, headers, timeout): |
| 131 | import time | 132 | import time |
| 132 | while True: | 133 | while True: |
| 133 | status_response = self._get_request(f'https://api.firecrawl.dev/v0/crawl/status/{job_id}', headers) | 134 | status_response = self._get_request(f'{self.api_url}/v0/crawl/status/{job_id}', headers) |
| 134 | if status_response.status_code == 200: | 135 | if status_response.status_code == 200: |
| 135 | status_data = status_response.json() | 136 | status_data = status_response.json() |
| 136 | if status_data['status'] == 'completed': | 137 | if status_data['status'] == 'completed': |