Skip to main content

Python SDK for Monitoro Herd

Project description

Herd Python SDK

A Python SDK for interacting with the Herd automation platform. This SDK provides a simple interface for controlling browser automation and device management.

Installation

pip install -r requirements.txt

Usage

Here's a basic example of how to use the SDK:

import asyncio
from main import HerdClient

async def example():
    # Create a client
    client = HerdClient(
        token='your-auth-token'
    )

    # Initialize the client (required before using)
    await client.initialize()

    try:
        # List available devices
        devices = await client.list_devices()
        print('Available devices:', devices)

        # Get a specific device
        device = await client.get_device('device-id')

        # Create a new page
        page = await device.new_page()

        # Navigate to a URL
        await page.goto('https://example.com')

        # Click an element
        await page.click('#submit-button')

        # Fill a form field
        await page.fill('#username', 'testuser')

        # Extract data
        data = await page.extract({
            'title': 'h1',
            'description': '.description',
            'items': {
                'price': '.item-price',
                'name': '.item-name'
            }
        })
        print('Extracted data:', data)

        # Subscribe to device events
        def handle_event(event):
            print('Device event:', event)

        unsubscribe = device.on_event(handle_event)

        # Cleanup
        unsubscribe()
        await page.close()
        await device.close()
    finally:
        # Always close the client when done
        await client.close()

# Run the example
asyncio.run(example())

Features

  • Asynchronous API using asyncio
  • Device management
  • Browser automation
  • Event subscription
  • Data extraction
  • Automatic reconnection handling
  • Type hints for better IDE support

API Reference

HerdClient

The main client class for interacting with the Herd platform.

client = HerdClient(base_url: str, token: str)

Methods:

  • initialize() - Initialize the client and connect to NATS
  • list_devices() - Get a list of available devices
  • get_device(device_id: str) - Get a specific device
  • register_device(device_id: str, device_type: str, name: str = None) - Register a new device
  • close() - Close the client and cleanup resources

Device

Represents a device in the Herd platform.

Methods:

  • new_page() - Create a new page
  • list_pages() - List all pages
  • get_page(page_id: int) - Get a specific page
  • on_event(callback) - Subscribe to device events
  • close() - Close the device and cleanup resources

Page

Represents a browser page/tab.

Methods:

  • goto(url: str) - Navigate to a URL
  • click(selector: str, options: Dict = None) - Click an element
  • fill(selector: str, value: str, options: Dict = None) - Fill a form field
  • extract(selectors: Dict) - Extract data from the page
  • close() - Close the page

Error Handling

The SDK uses exceptions to handle errors. Make sure to handle these appropriately in your code:

try:
    await client.initialize()
except Exception as e:
    print(f"Failed to initialize client: {e}")

Best Practices

  1. Always use async/await with the SDK functions
  2. Initialize the client before using it
  3. Close resources when done using them
  4. Handle exceptions appropriately
  5. Use type hints for better code completion
  6. Subscribe to events when needed for real-time updates

Contributing

Feel free to submit issues and pull requests to improve the SDK.

License

EULA - see 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_herd-0.1.1.tar.gz (9.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_herd-0.1.1-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file monitoro_herd-0.1.1.tar.gz.

File metadata

  • Download URL: monitoro_herd-0.1.1.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for monitoro_herd-0.1.1.tar.gz
Algorithm Hash digest
SHA256 288c3e97a418145cbfe6a20030f944ca7e6b1f2d9731f6abef5d6567e6a24b53
MD5 e3cecc372c6a073a107458526bbbbd35
BLAKE2b-256 921094af55950f9c35fb3e75def8399fd7170e6776d0d5b0c14a4abb2e8f3bb6

See more details on using hashes here.

File details

Details for the file monitoro_herd-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: monitoro_herd-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.9

File hashes

Hashes for monitoro_herd-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c323fee4f72ae753c9088d13a21c4f2219fdb13205b3062fd8f77bb8f16ee1ff
MD5 689eb47b78ff258810b21657a48cc4c7
BLAKE2b-256 a54dfaf5c2dde42fcd876524817f13535e3e7faa073307134f58cfc2c37c180e

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