# 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
```python
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
```python
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.
Raw data
{
"_id": null,
"home_page": "https://github.com/monitoro-inc/python-client",
"name": "monitoro",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "monitoro, scraping, web scraping, web scraping api, local scraping, generative AI, agent tools",
"author": "Omar Kamali",
"author_email": "support@monitoro.co",
"download_url": "https://files.pythonhosted.org/packages/c1/f1/574cf478f38ea0212269a8685ef8544883cb619f10d0e72a02715fc5836c/monitoro-0.2.3.tar.gz",
"platform": null,
"description": "# Monitoro API Client\n\nThis 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.\n\n## Installation\n\nYou can install the Monitoro API client using pip:\n```\npip install monitoro\n```\n\n## Usage\n\nHere are some examples of how to use the Monitoro API client:\n\n### Basic Usage\n```python\nfrom monitoro import Monitoro, MonitoroAPIError\n\n# Initialize the client with your API token\nclient = Monitoro(\"your_api_token_here\")\n\ntry:\n # Extract data from a single URL using a specific monitor\n for url, result in client.extract(monitor=\"monitor_id\", url=\"https://example.com\"):\n print(f\"Extracted data from {url}:\")\n print(result)\n\n\n # Extract data from multiple URLs using a specific monitor\n urls = [\"https://example.com\", \"https://example.org\", \"https://example.net\"]\n for url, result in client.extract(monitor=\"monitor_id\", urls=urls):\n print(f\"Extracted data from {url}:\")\n print(result)\n\n\n # Extract data using a template\n for url, result in client.extract(template=\"template_id\", urls=[\"https://example.com\"]):\n print(f\"Extracted data from {url} using template:\")\n print(result)\n\n # Extract data using selectors\n for url, result in client.extract(selectors={\"title\": \"h1\"}, urls=[\"https://example.com\"]):\n print(f\"Extracted data from {url} using selectors:\")\n print(result)\n\nexcept MonitoroAPIError as e:\n print(f\"An error occurred: {e}\")\n```\n\n### Using MonitoroSwarm for Distributed Extraction\n```python\nfrom monitoro import MonitoroSwarm, MonitoroAPIError\n\n# Initialize the swarm client with multiple API tokens\nswarm = MonitoroSwarm([\"token1\", \"token2\", \"token3\"])\n\ntry:\n urls = [\"https://example.com\", \"https://example.org\", \"https://example.net\"]\n\n for url, result in swarm.extract(template=\"template_id\", urls=urls):\n print(f\"Extracted data from {url}:\")\n print(result)\n \n for url, result in swarm.extract(selectors={\"title\": \"h1\"}, urls=urls):\n print(f\"Extracted data from {url}:\")\n print(result)\n \nexcept MonitoroAPIError as e:\n print(f\"An error occurred: {e}\")\n```\n\n## API Reference\n\n### `Monitoro(token)`\n\nCreates a new Monitoro API client instance.\n\n- `token` (str): Your Monitoro API token.\n\n### `Monitoro.extract(monitor_id=None, template_id=None, selectors=None, url=None, urls=None, no_ingest=False)`\n\nExtracts data from URLs using a specific monitor's settings or a template.\n\n- Only one of these parameters should be provided at a time.\n - `monitor_id` (str, optional): The ID of the monitor to use for extraction.\n - `template_id` (str, optional): The ID of the template to use for extraction.\n - `selectors` (dict, optional): The selectors to use for extraction.\n\n- `url` (str, optional): The URL to extract data from.\n- `urls` (list, optional): The list of URLs to extract data from.\n- `no_ingest` (bool, optional): If True, skip running automations. Defaults to False. Only valid with `monitor_id`.\n\nReturns a generator that yields (url, data) tuples for successful extractions, followed by a list of (url, error) tuples for failed extractions.\n\n### `MonitoroSwarm(tokens)`\n\nCreates a new Monitoro Swarm client instance for distributed extraction.\n\n- `tokens` (list): A list of Monitoro API tokens.\n\nThe `MonitoroSwarm` class has the same `extract` method as the `Monitoro` class, but it distributes the workload across multiple API tokens.\nCalling `extract` with monitor_id is not supported in swarm mode, and `no_ingest` is always set to false in this mode.\n\n## Error Handling\n\nThe client raises specific exceptions for different error scenarios:\n\n- `BadRequestError`: For 400 Bad Request errors (e.g., missing URL or malformed request)\n- `MonitorNotFoundError`: For 404 Monitor Not Found errors\n- `ServerError`: For 500 Server Error during data extraction\n- `MonitoroAPIError`: Base exception for all other API errors\n\nYou can catch these exceptions to handle errors in your code.\n\n## License\n\nThis client is licensed under the MIT License.\n",
"bugtrack_url": null,
"license": null,
"summary": "Official Python SDK for the Monitoro API",
"version": "0.2.3",
"project_urls": {
"Homepage": "https://github.com/monitoro-inc/python-client"
},
"split_keywords": [
"monitoro",
" scraping",
" web scraping",
" web scraping api",
" local scraping",
" generative ai",
" agent tools"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ab840b4cefde8a5ee1cd573e857e95196edaf36658eea3a32bb1dd6111dad350",
"md5": "92f384c7be63b0e31d3b4e8e53dba0b3",
"sha256": "3bf9f0e79a7ae49a42fc4e7c39541287ade9dd478d05fe9f238eba8eeffaefc2"
},
"downloads": -1,
"filename": "monitoro-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "92f384c7be63b0e31d3b4e8e53dba0b3",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 5200,
"upload_time": "2025-01-04T01:37:02",
"upload_time_iso_8601": "2025-01-04T01:37:02.529464Z",
"url": "https://files.pythonhosted.org/packages/ab/84/0b4cefde8a5ee1cd573e857e95196edaf36658eea3a32bb1dd6111dad350/monitoro-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "c1f1574cf478f38ea0212269a8685ef8544883cb619f10d0e72a02715fc5836c",
"md5": "5d6bc571f86cf912b8ecd6614d3d9248",
"sha256": "3707311ae6e71c4961f8df3a373172c40701144e5d392c748de69f8f23c2fd11"
},
"downloads": -1,
"filename": "monitoro-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "5d6bc571f86cf912b8ecd6614d3d9248",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 5032,
"upload_time": "2025-01-04T01:37:04",
"upload_time_iso_8601": "2025-01-04T01:37:04.592949Z",
"url": "https://files.pythonhosted.org/packages/c1/f1/574cf478f38ea0212269a8685ef8544883cb619f10d0e72a02715fc5836c/monitoro-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-04 01:37:04",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "monitoro-inc",
"github_project": "python-client",
"github_not_found": true,
"lcname": "monitoro"
}