Skip to main content

Botasaurus API

The Botasaurus API client is a Python library for interacting with Botasaurus Scrapers via an API.

It provides a simple and convenient way to create, fetch, download, abort, and delete tasks, as well as manage their results.

Installation

To install the API client, use pip:

python -m pip install --upgrade botasaurus-api

Usage

First, import the Api class from the library:

from botasaurus-api import Api

Then, create an instance of the Api class:

api = Api()

You can also provide an optional api_url parameter to specify the base URL for the API server. If the api_url parameter is not provided, it defaults to http://localhost:8000.

api = Api('https://example.com/')

Additionally, the API client will create response JSON files in the output/responses/ directory to help with debugging and development. If you want to disable this feature in production, you can set create_response_files=False.

api = Api(create_response_files=False)

Creating Tasks

There are two types of tasks:

  • Asynchronous Task
  • Synchronous Task

Asynchronous tasks run asynchronously, without waiting for the task to be completed. The server will return a response immediately, containing information about the task, but not the actual results. The client can then retrieve the results later.

Synchronous tasks, on the other hand, wait for the completion of the task. The server response will contain the results of the task.

You should use asynchronous tasks when you want to run a task in the background and retrieve the results later. Synchronous tasks are better suited for scenarios where you have a small number of tasks and want to wait and get the results immediately.

To create an asynchronous task, use the create_async_task method:

data = {'link': 'https://www.omkar.cloud/'}
task = api.create_async_task(data)

You can also provide an optional scraper_name parameter to specify the scraper to be used for the task, if not provided, it will use the default scraper:

task = api.create_async_task(data, scraper_name='scrape_heading_task')

To create a synchronous task, use the create_sync_task method:

data = {'link': 'https://www.omkar.cloud/blog/'}
task = api.create_sync_task(data)

You can create multiple asynchronous or synchronous tasks at once using the create_async_tasks and create_sync_tasks methods, respectively:

data_items = [{'link': 'https://www.omkar.cloud/'}, {'link': 'https://www.omkar.cloud/blog/'}]
tasks = api.create_async_tasks(data_items)
tasks = api.create_sync_tasks(data_items)

Fetching Tasks

To fetch tasks from the server, use the get_tasks method:

tasks = api.get_tasks()

By default, all tasks are returned. You can also apply pagination, views, sorts and filters:

tasks = api.get_tasks(
    page=1,
    per_page=10,
    # view='overview',
    # sort='my-sort',
    # filters={'your_filter': 'value'},
)

To fetch a specific task by its ID, use the get_task method:

task = api.get_task(task_id=1)

Fetching Task Results

To fetch the results of a specific task, use the get_task_results method:

results = api.get_task_results(task_id=1)

You can also apply views, sorts and filters:

results = api.get_task_results(
    task_id=1,
    page=1,
    per_page=20,
    # view='overview',
    # sort='my_sort',
    # filters={'your_filter': 'value'},
)

Downloading Task Results

To download the results of a specific task in a particular format, use the download_task_results method:

results_bytes, filename = api.download_task_results(task_id=1, format='csv')
with open(filename, 'wb') as file:
    file.write(results_bytes)

You can also apply views, sorts and filters:

results_bytes, filename = api.download_task_results(
    task_id=1,
    format='excel',  # format can be one of: json, csv or excel
    # view='overview',
    # sort='my_sort',
    # filters={'your_filter': 'value'},
)

Aborting and Deleting Tasks

To abort a specific task, use the abort_task method:

api.abort_task(task_id=1)

To delete a specific task, use the delete_task method:

api.delete_task(task_id=1)

You can also bulk abort or delete multiple tasks at once using the abort_tasks and delete_tasks methods, respectively:

api.abort_tasks(1, 2, 3)
api.delete_tasks(4, 5, 6)

Examples

Here are some example usages of the API client:

from botasaurus_api import Api

# Create an instance of the API client
api = Api()

# Create an asynchronous task
data = {'link': 'https://www.omkar.cloud/'}
task = api.create_sync_task(data, scraper_name='scrape_heading_task')

# Fetch the task
task = api.get_task(task['id'])

# Fetch the task results
results = api.get_task_results(task['id'])

# Download the task results as a CSV
results_bytes, filename = api.download_task_results(task['id'], format='csv')

# Abort the task
api.abort_task(task['id'])

# Delete the task
api.delete_task(task['id'])

# --- Bulk Operations ---

# Create multiple synchronous tasks
data_items = [{'link': 'https://www.omkar.cloud/'}, {'link': 'https://www.omkar.cloud/blog/'}]
tasks = api.create_sync_tasks(data_items, scraper_name='scrape_heading_task')

# Fetch all tasks
all_tasks = api.get_tasks()

# Bulk abort tasks
api.abort_tasks(*[task['id'] for task in tasks])

# Bulk delete tasks
api.delete_tasks(*[task['id'] for task in tasks])

That's It!

Now, go and build something awesome.

Metadata

Release files for botasaurus-api 4.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for botasaurus-api 4.0.10
File Size Uploaded
botasaurus_api-4.0.10.tar.gz 8.5 kB Details

Release files / botasaurus_api-4.0.10.tar.gz

Download URL botasaurus_api-4.0.10.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
009fd7f59abba11725fe02d61b985757e9239a57afb6595b48b4da6ad4ed0a94
BLAKE2b-256 checksum
How to use checksums
b9eb9f58b93d1e7f6660dede8ea2d57885c8b26e5c1f0833ae359210cf897694
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

4.0.10 This release

1 release file

4.0.9

1 release file

4.0.4

1 release file

4.0.2

1 release file

4.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page