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 | 4 | import time |
| 5 | 5 | |
| 6 | 6 | class FirecrawlApp: |
| 7 | − def __init__(self, api_key=None): | |
| 7 | + def __init__(self, api_key=None, api_url='https://api.firecrawl.dev'): | |
| 8 | 8 | self.api_key = api_key or os.getenv('FIRECRAWL_API_KEY') |
| 9 | 9 | if self.api_key is None: |
| 10 | 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 | 39 | scrape_params[key] = value |
| 39 | 40 | # Make the POST request with the prepared headers and JSON data |
| 40 | 41 | response = requests.post( |
| 41 | − 'https://api.firecrawl.dev/v0/scrape', | |
| 42 | + f'{self.api_url}/v0/scrape', | |
| 42 | 43 | headers=headers, |
| 43 | 44 | json=scrape_params |
| 44 | 45 | ) |
| @@ -63,7 +64,7 @@ class FirecrawlApp: · 18 unmodified lines | ||
| 63 | 64 | if params: |
| 64 | 65 | json_data.update(params) |
| 65 | 66 | response = requests.post( |
| 66 | − 'https://api.firecrawl.dev/v0/search', | |
| 67 | + f'{self.api_url}/v0/search', | |
| 67 | 68 | headers=headers, |
| 68 | 69 | json=json_data |
| 69 | 70 | ) |
| @@ -85,7 +86,7 @@ class FirecrawlApp: · 15 unmodified lines | ||
| 85 | 86 | json_data = {'url': url} |
| 86 | 87 | if params: |
| 87 | 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 | 90 | if response.status_code == 200: |
| 90 | 91 | job_id = response.json().get('jobId') |
| 91 | 92 | if wait_until_done: |
| @@ -97,7 +98,7 @@ class FirecrawlApp: · 5 unmodified lines | ||
| 97 | 98 | |
| 98 | 99 | def check_crawl_status(self, job_id): |
| 99 | 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 | 102 | if response.status_code == 200: |
| 102 | 103 | return response.json() |
| 103 | 104 | else: |
| @@ -130,7 +131,7 @@ class FirecrawlApp: · 26 unmodified lines | ||
| 130 | 131 | def _monitor_job_status(self, job_id, headers, timeout): |
| 131 | 132 | import time |
| 132 | 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 | 135 | if status_response.status_code == 200: |
| 135 | 136 | status_data = status_response.json() |
| 136 | 137 | if status_data['status'] == 'completed': |