Skip to main content

Official Python SDK for the Monitoro API

Project description

Monitoro API Client

This is a Python client for the Monitoro API, which allows you to extract data from websites using Monitoro's scraping capabilities and powered by your own browser - no need to worry about renting servers, proxies, or solving captchas.

Installation

You can install the Monitoro API client using pip:

pip install monitoro

Usage

Here are some examples of how to use the Monitoro API client:

Basic Usage

from monitoro import Monitoro, MonitoroAPIError

# Initialize the client with your API token
client = Monitoro("your_api_token_here")

try:
    # Extract data from a single URL using a specific monitor
    for url, result in client.extract(monitor="monitor_id", url="https://example.com"):
        print(f"Extracted data from {url}:")
        print(result)


    # Extract data from multiple URLs using a specific monitor
    urls = ["https://example.com", "https://example.org", "https://example.net"]
    for url, result in client.extract(monitor="monitor_id", urls=urls):
        print(f"Extracted data from {url}:")
        print(result)


    # Extract data using a template
    for url, result in client.extract(template="template_id", urls=["https://example.com"]):
        print(f"Extracted data from {url} using template:")
        print(result)

    # Extract data using selectors
    for url, result in client.extract(selectors={"title": "h1"}, urls=["https://example.com"]):
        print(f"Extracted data from {url} using selectors:")
        print(result)

except MonitoroAPIError as e:
    print(f"An error occurred: {e}")

Using MonitoroSwarm for Distributed Extraction

from monitoro import MonitoroSwarm, MonitoroAPIError

# Initialize the swarm client with multiple API tokens
swarm = MonitoroSwarm(["token1", "token2", "token3"])

try:
    urls = ["https://example.com", "https://example.org", "https://example.net"]

    for url, result in swarm.extract(template="template_id", urls=urls):
        print(f"Extracted data from {url}:")
        print(result)
    
    for url, result in swarm.extract(selectors={"title": "h1"}, urls=urls):
        print(f"Extracted data from {url}:")
        print(result)
        
except MonitoroAPIError as e:
    print(f"An error occurred: {e}")

API Reference

Monitoro(token)

Creates a new Monitoro API client instance.

  • token (str): Your Monitoro API token.

Monitoro.extract(monitor_id=None, template_id=None, selectors=None, url=None, urls=None, no_ingest=False)

Extracts data from URLs using a specific monitor's settings or a template.

  • Only one of these parameters should be provided at a time.

    • monitor_id (str, optional): The ID of the monitor to use for extraction.
    • template_id (str, optional): The ID of the template to use for extraction.
    • selectors (dict, optional): The selectors to use for extraction.
  • url (str, optional): The URL to extract data from.

  • urls (list, optional): The list of URLs to extract data from.

  • no_ingest (bool, optional): If True, skip running automations. Defaults to False. Only valid with monitor_id.

Returns a generator that yields (url, data) tuples for successful extractions, followed by a list of (url, error) tuples for failed extractions.

MonitoroSwarm(tokens)

Creates a new Monitoro Swarm client instance for distributed extraction.

  • tokens (list): A list of Monitoro API tokens.

The MonitoroSwarm class has the same extract method as the Monitoro class, but it distributes the workload across multiple API tokens. Calling extract with monitor_id is not supported in swarm mode, and no_ingest is always set to false in this mode.

Error Handling

The client raises specific exceptions for different error scenarios:

  • BadRequestError: For 400 Bad Request errors (e.g., missing URL or malformed request)
  • MonitorNotFoundError: For 404 Monitor Not Found errors
  • ServerError: For 500 Server Error during data extraction
  • MonitoroAPIError: Base exception for all other API errors

You can catch these exceptions to handle errors in your code.

License

This client is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

monitoro-0.2.1.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

monitoro-0.2.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file monitoro-0.2.1.tar.gz.

File metadata

  • Download URL: monitoro-0.2.1.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for monitoro-0.2.1.tar.gz
Algorithm Hash digest
SHA256 cec1673de3285cc8853740cba2310eb8c8ed8df7796d9a583a2cd93acf9186af
MD5 6b967efd70a7ef531e2f1e090da37208
BLAKE2b-256 48caf6e4a3251b737ce0fa0c2f5e5ca17f905da852d6ac2cddbbb3695732e328

See more details on using hashes here.

File details

Details for the file monitoro-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: monitoro-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for monitoro-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fd507331b5952fdfb81f6874d141bbe93e6905044c578c9ba9c20d4eed34069a
MD5 578db64e73a511d535f5d65a83281b9d
BLAKE2b-256 6f6cf9e29c4ce88d72577a48b6b304a65bef2a54df61d9a2762b8f081306d8b8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page