💼 CapmonsterClient#
capmonster_python.CapmonsterClient #
create_task #
create_task(task, callback_url=None)
Creates a task based on the provided payload and returns the task ID.
This method is responsible for initiating a task by preparing the request with the provided task details and optional callback URL, sending a synchronous request to the task creation endpoint, and parsing the response to retrieve the task ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
TaskPayload
|
The task configuration payload that defines the specifics of the task to be created. |
required |
callback_url
|
Optional[str]
|
An optional URL to be called back upon task completion or update. |
None
|
Returns:
Type | Description |
---|---|
int
|
The unique identifier of the created task. |
Raises:
Type | Description |
---|---|
CapmonsterException
|
If the task creation request fails or the response is not contains valid task id. |
create_task_async
async
#
create_task_async(task, callback_url=None)
Asynchronously creates a task based on the provided payload and returns the task ID.
This method is responsible for initiating a task by preparing the request with the provided task details and optional callback URL, sending a synchronous request to the task creation endpoint, and parsing the response to retrieve the task ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task
|
TaskPayload
|
The task configuration payload that defines the specifics of the task to be created. |
required |
callback_url
|
Optional[str]
|
An optional URL to be called back upon task completion or update. |
None
|
Returns:
Type | Description |
---|---|
int
|
The unique identifier of the created task. |
Raises:
Type | Description |
---|---|
CapmonsterException
|
If the task creation request fails or the response is not contains valid task id. |
get_balance #
get_balance()
Fetches the current balance using the provided API key.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The balance fetched from the external service. Defaults to 0.0 if the balance |
float
|
key is not found in the response. |
get_balance_async
async
#
get_balance_async()
Asynchronously fetches the current balance using the provided API key.
Returns:
Name | Type | Description |
---|---|---|
float |
float
|
The balance fetched from the external service. Defaults to 0.0 if the balance |
float
|
key is not found in the response. |
get_task_result #
get_task_result(task_id)
Fetches the result of a specific task by its identifier.
This function interacts with API to retrieve the results of a previously submitted task. The function uses the provided task ID and sends a request to the API endpoint to get the result. It returns the solution data extracted from the API response or an empty dictionary if no solution data is found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id
|
int
|
An integer representing the unique identifier of the task. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the solution data retrieved from the task |
dict
|
result API endpoint. If the solution is not found in the response, an empty |
|
dict
|
dictionary is returned. |
get_task_result_async
async
#
get_task_result_async(task_id)
Asynchronously fetches the result of a specific task by its identifier.
This function interacts with API to retrieve the results of a previously submitted task. The function uses the provided task ID and sends a request to the API endpoint to get the result. It returns the solution data extracted from the API response or an empty dictionary if no solution data is found.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id
|
int
|
An integer representing the unique identifier of the task. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the solution data retrieved from the task |
dict
|
result API endpoint. If the solution is not found in the response, an empty |
|
dict
|
dictionary is returned. |
join_task_result #
join_task_result(task_id)
Joins and retrieves the result of a task given its ID, retrying a specified number of times if the result is not immediately available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id
|
int
|
The identifier of the task for which the result needs to be retrieved. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
The result of the task if successfully retrieved within the maximum retries. |
Raises:
Type | Description |
---|---|
CapmonsterException
|
If the maximum retry limit is exceeded without obtaining the task result. |
join_task_result_async
async
#
join_task_result_async(task_id)
Asynchronously joins and retrieves the result of a task given its ID, retrying a specified number of times if the result is not immediately available.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
task_id
|
int
|
The identifier of the task for which the result needs to be retrieved. |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
The result of the task if successfully retrieved within the maximum retries. |
Raises:
Type | Description |
---|---|
CapmonsterException
|
If the maximum retry limit is exceeded without obtaining the task result. |