Skip to content

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

fix(python-sdk): added missing get_queue_status in aio and added to t… (#2081)

Rafael Miller3968a602fe05
diff --git a/apps/python-sdk/firecrawl/__init__.py b/apps/python-sdk/firecrawl/__init__.py
index f1e621169..adba0b03e 100644
--- a/apps/python-sdk/firecrawl/__init__.py
+++ b/apps/python-sdk/firecrawl/__init__.py
@@ -17,7 +17,7 @@ from .v1 import (
V1ChangeTrackingOptions,
)
-__version__ = "4.3.0"
+__version__ = "4.3.1"
# Define the logger for the Firecrawl project
logger: logging.Logger = logging.getLogger("firecrawl")
diff --git a/apps/python-sdk/firecrawl/__tests__/e2e/v2/aio/test_aio_usage.py b/apps/python-sdk/firecrawl/__tests__/e2e/v2/aio/test_aio_usage.py
index 42f1c2ce5..218e9892a 100644
--- a/apps/python-sdk/firecrawl/__tests__/e2e/v2/aio/test_aio_usage.py
+++ b/apps/python-sdk/firecrawl/__tests__/e2e/v2/aio/test_aio_usage.py
@@ -33,3 +33,10 @@ async def test_async_get_token_usage():
tokens = await client.get_token_usage()
assert hasattr(tokens, "remaining_tokens")
+
+async def test_async_get_queue_status():
+ client = AsyncFirecrawl(api_key=os.getenv("API_KEY"), api_url=os.getenv("API_URL"))
+ status = await client.get_queue_status()
+ assert hasattr(status, "jobs_in_queue")
+
diff --git a/apps/python-sdk/firecrawl/client.py b/apps/python-sdk/firecrawl/client.py
index 8a4c45c80..30946e947 100644
--- a/apps/python-sdk/firecrawl/client.py
+++ b/apps/python-sdk/firecrawl/client.py
@@ -56,23 +56,34 @@ class V2Proxy:
self._client = client_instance
if client_instance:
+ self.scrape = client_instance.scrape
self.search = client_instance.search
self.crawl = client_instance.crawl
+ self.start_crawl = client_instance.start_crawl
self.get_crawl_status = client_instance.get_crawl_status
self.cancel_crawl = client_instance.cancel_crawl
- self.start_crawl = client_instance.start_crawl
+ self.get_crawl_errors = client_instance.get_crawl_errors
+ self.get_active_crawls = client_instance.get_active_crawls
+ self.active_crawls = client_instance.active_crawls
self.crawl_params_preview = client_instance.crawl_params_preview
+
self.extract = client_instance.extract
+ self.start_extract = client_instance.start_extract
+ self.get_extract_status = client_instance.get_extract_status
+
self.start_batch_scrape = client_instance.start_batch_scrape
self.get_batch_scrape_status = client_instance.get_batch_scrape_status
self.cancel_batch_scrape = client_instance.cancel_batch_scrape
self.batch_scrape = client_instance.batch_scrape
self.get_batch_scrape_errors = client_instance.get_batch_scrape_errors
- self.get_extract_status = client_instance.get_extract_status
+
self.map = client_instance.map
self.get_concurrency = client_instance.get_concurrency
self.get_credit_usage = client_instance.get_credit_usage
self.get_token_usage = client_instance.get_token_usage
+ self.get_queue_status = client_instance.get_queue_status
+
+ self.watcher = client_instance.watcher
def __getattr__(self, name):
"""Forward attribute access to the underlying client."""
@@ -99,9 +110,9 @@ class AsyncV1Proxy:
class AsyncV2Proxy:
"""Proxy class that forwards method calls to the appropriate version client."""
- _client: Optional[Any] = None
+ _client: Optional[AsyncFirecrawlClient] = None
- def __init__(self, client_instance: Optional[Any] = None):
+ def __init__(self, client_instance: Optional[AsyncFirecrawlClient] = None):
self._client = client_instance
if client_instance:
@@ -132,6 +143,8 @@ class AsyncV2Proxy:
self.get_concurrency = client_instance.get_concurrency
self.get_credit_usage = client_instance.get_credit_usage
self.get_token_usage = client_instance.get_token_usage
+ self.get_queue_status = client_instance.get_queue_status
+
self.watcher = client_instance.watcher
def __getattr__(self, name):
@@ -193,7 +206,8 @@ class Firecrawl:
self.get_concurrency = self._v2_client.get_concurrency
self.get_credit_usage = self._v2_client.get_credit_usage
self.get_token_usage = self._v2_client.get_token_usage
-
+ self.get_queue_status = self._v2_client.get_queue_status
+
self.watcher = self._v2_client.watcher
class AsyncFirecrawl:
@@ -238,6 +252,7 @@ class AsyncFirecrawl:
self.get_concurrency = self._v2_client.get_concurrency
self.get_credit_usage = self._v2_client.get_credit_usage
self.get_token_usage = self._v2_client.get_token_usage
+ self.get_queue_status = self._v2_client.get_queue_status
self.watcher = self._v2_client.watcher
diff --git a/apps/python-sdk/firecrawl/types.py b/apps/python-sdk/firecrawl/types.py
index 0fcaa8a74..18793cba5 100644
--- a/apps/python-sdk/firecrawl/types.py
+++ b/apps/python-sdk/firecrawl/types.py
@@ -65,6 +65,9 @@ from .v2.types import (
ExecuteJavascriptAction,
PDFAction,
+ # Usage types
+ QueueStatusResponse,
+
# Location and format types
Location,
@@ -142,6 +145,9 @@ __all__ = [
'ScrapeAction',
'ExecuteJavascriptAction',
'PDFAction',
+
+ # Usage types
+ 'QueueStatusResponse',
# Location and format types
'Location',
diff --git a/apps/python-sdk/firecrawl/v2/client_async.py b/apps/python-sdk/firecrawl/v2/client_async.py
index a7d3552fd..9b414a0a8 100644
--- a/apps/python-sdk/firecrawl/v2/client_async.py
+++ b/apps/python-sdk/firecrawl/v2/client_async.py
@@ -253,6 +253,18 @@ class AsyncFirecrawlClient:
async def get_token_usage(self):
from .methods.aio import usage as async_usage # type: ignore[attr-defined]
return await async_usage.get_token_usage(self.async_http_client)
+
+ async def get_credit_usage_historical(self, by_api_key: bool = False):
+ from .methods.aio import usage as async_usage # type: ignore[attr-defined]
+ return await async_usage.get_credit_usage_historical(self.async_http_client, by_api_key)
+
+ async def get_token_usage_historical(self, by_api_key: bool = False):
+ from .methods.aio import usage as async_usage # type: ignore[attr-defined]
+ return await async_usage.get_token_usage_historical(self.async_http_client, by_api_key)
+
+ async def get_queue_status(self):
+ from .methods.aio import usage as async_usage # type: ignore[attr-defined]
+ return await async_usage.get_queue_status(self.async_http_client)
# Watcher (sync object usable from async contexts)
def watcher(
diff --git a/apps/python-sdk/firecrawl/v2/methods/aio/usage.py b/apps/python-sdk/firecrawl/v2/methods/aio/usage.py
index e1c9fb18e..f72f82600 100644
--- a/apps/python-sdk/firecrawl/v2/methods/aio/usage.py
+++ b/apps/python-sdk/firecrawl/v2/methods/aio/usage.py
@@ -1,6 +1,6 @@
from ...utils.http_client_async import AsyncHttpClient
from ...utils.error_handler import handle_response_error
-from ...types import ConcurrencyCheck, CreditUsage, TokenUsage, CreditUsageHistoricalResponse, TokenUsageHistoricalResponse
+from ...types import ConcurrencyCheck, CreditUsage, TokenUsage, CreditUsageHistoricalResponse, TokenUsageHistoricalResponse, QueueStatusResponse
async def get_concurrency(client: AsyncHttpClient) -> ConcurrencyCheck:
@@ -49,6 +49,23 @@ async def get_token_usage(client: AsyncHttpClient) -> TokenUsage:
)
+async def get_queue_status(client: AsyncHttpClient) -> QueueStatusResponse:
+ resp = await client.get("/v2/team/queue-status")
+ if resp.status_code >= 400:
+ handle_response_error(resp, "get queue status")
+ body = resp.json()
+ if not body.get("success"):
+ raise Exception(body.get("error", "Unknown error"))
+ data = body.get("data", body)
+ return QueueStatusResponse(
+ jobs_in_queue=data.get("jobsInQueue", 0),
+ active_jobs_in_queue=data.get("activeJobsInQueue", 0),
+ waiting_jobs_in_queue=data.get("waitingJobsInQueue", 0),
+ max_concurrency=data.get("maxConcurrency", 0),
+ most_recent_success=data.get("mostRecentSuccess", None),
+ )
+
+
async def get_credit_usage_historical(client: AsyncHttpClient, by_api_key: bool = False) -> CreditUsageHistoricalResponse:
query = "?byApiKey=true" if by_api_key else ""
resp = await client.get(f"/v2/team/credit-usage/historical{query}")