History

Allow override of API URL

Allows python sdk to be used with local installs.

Matt Joyce committed 2 years ago

Commit 7e5ef4d1 parent c74f7571 file · +7 −6Browse files

Showing the changes to apps/python-sdk (1 of 1 file). Show all

Unified · Split

apps/python-sdk/firecrawl/firecrawl.py+7−6
@@ -4,10 +4,11 @@ import requests · 3 unmodified lines
44 import time
55
66 class FirecrawlApp:
7− def __init__(self, api_key=None):
7+ def __init__(self, api_key=None, api_url='https://api.firecrawl.dev'):
88 self.api_key = api_key or os.getenv('FIRECRAWL_API_KEY')
99 if self.api_key is None:
1010 raise ValueError('No API key provided')
11+ self.api_url = api_url or os.getenv('FIRECRAWL_API_URL')
1112
1213
1314
@@ -38,7 +39,7 @@ class FirecrawlApp: · 24 unmodified lines
3839 scrape_params[key] = value
3940 # Make the POST request with the prepared headers and JSON data
4041 response = requests.post(
41− 'https://api.firecrawl.dev/v0/scrape',
42+ f'{self.api_url}/v0/scrape',
4243 headers=headers,
4344 json=scrape_params
4445 )
@@ -63,7 +64,7 @@ class FirecrawlApp: · 18 unmodified lines
6364 if params:
6465 json_data.update(params)
6566 response = requests.post(
66− 'https://api.firecrawl.dev/v0/search',
67+ f'{self.api_url}/v0/search',
6768 headers=headers,
6869 json=json_data
6970 )
@@ -85,7 +86,7 @@ class FirecrawlApp: · 15 unmodified lines
8586 json_data = {'url': url}
8687 if params:
8788 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)
8990 if response.status_code == 200:
9091 job_id = response.json().get('jobId')
9192 if wait_until_done:
@@ -97,7 +98,7 @@ class FirecrawlApp: · 5 unmodified lines
9798
9899 def check_crawl_status(self, job_id):
99100 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)
101102 if response.status_code == 200:
102103 return response.json()
103104 else:
@@ -130,7 +131,7 @@ class FirecrawlApp: · 26 unmodified lines
130131 def _monitor_job_status(self, job_id, headers, timeout):
131132 import time
132133 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)
134135 if status_response.status_code == 200:
135136 status_data = status_response.json()
136137 if status_data['status'] == 'completed':

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t