Skip to main content

MeterClient

The MeterClient class is the main interface for all Meter API operations. It handles authentication, request management, and provides methods for strategies, jobs, and schedules.

Constructor

Parameters

Example

Context Manager

The client can be used as a context manager for automatic resource cleanup:

Strategy Methods

generate_strategy()

Generate a new extraction strategy using AI.
Parameters: Returns: Dict with fields:
  • strategy_id (str): UUID of the created strategy
  • strategy (dict): The extraction strategy (CSS selectors, fields)
  • preview_data (list): Sample extracted data (first 5-10 items)
  • attempts (int): Number of generation attempts (usually 1)
  • scraper_type (str): Type of scraper used - 'css' or 'api'
  • api_parameters (dict, optional): Available URL parameters for API-based strategies
Example:
Example with API capture:
Raises: MeterError if generation fails
When force_api=True, Meter will attempt to identify and capture underlying API calls instead of using CSS selectors. This is useful for sites that load data dynamically via JavaScript APIs.

refine_strategy()

Refine an existing strategy with feedback.
Parameters: Returns: Dict with same fields as generate_strategy() Example:
Refinement uses cached HTML from initial generation, so it’s fast and doesn’t re-fetch the page.

list_strategies()

List all strategies for the authenticated user.
Parameters: Returns: List[Dict] where each dict contains:
  • id (str): Strategy UUID
  • name (str): Strategy name
  • description (str): Extraction description
  • url (str): Original URL used for generation
  • preview_data (list): Sample extracted data
  • created_at (str): ISO timestamp
  • updated_at (str): ISO timestamp
Example:

get_strategy()

Get details for a specific strategy.
Parameters: Returns: Dict with full strategy details (same fields as list_strategies() items) Example:
Raises: MeterError with 404 if strategy not found

delete_strategy()

Delete a strategy and all associated jobs and schedules.
Parameters: Returns: Dict with confirmation message Example:
This action is irreversible. All associated jobs and schedules will also be deleted.

Job Methods

create_job()

Create a new scrape job using a strategy.
Parameters: Returns: Dict with fields:
  • job_id (str): UUID of the created job (single URL)
  • batch_id (str): Batch UUID for tracking progress (multiple URLs)
  • status (str): Job status (usually “pending”)
  • strategy_id (str): Strategy UUID
  • url (str): Target URL
  • parameters (dict, optional): Parameters used for this job
  • created_at (str): ISO timestamp
Example:
Example with API parameters:
Example with batch URLs:
You must provide either url or urls, but not both. The parameters option only applies to API-based strategies (where scraper_type is 'api').

execute_job()

Create and execute a scrape job synchronously. Returns results directly without polling.
Parameters: Returns: Dict with completed job details including results Example:
Example with API parameters:
Raises: MeterError if job fails or times out
This endpoint blocks until the job completes (up to 1 hour timeout). Use create_job() + wait_for_job() for more control over polling behavior, or create_job() alone for fire-and-forget jobs.

get_job()

Get status and results for a job.
Parameters: Returns: Dict with fields:
  • job_id (str): Job UUID
  • status (str): “pending”, “running”, “completed”, or “failed”
  • results (list): Extracted data (only if status is “completed”)
  • item_count (int): Number of items extracted
  • content_hash (str): Hash for change detection
  • structural_signature (dict): Structural fingerprint
  • error (str): Error message (only if status is “failed”)
  • started_at (str): ISO timestamp
  • completed_at (str): ISO timestamp
  • created_at (str): ISO timestamp
Example:

wait_for_job()

Wait for a job to complete, polling automatically.
Parameters: Returns: Dict with completed job details (same as get_job()) Example:
Raises: MeterError if timeout exceeded or job fails

list_jobs()

List jobs with optional filtering.
Parameters: Returns: List[Dict] of job summaries Example:

compare_jobs()

Compare two jobs to detect changes.
Parameters: Returns: Dict with fields:
  • content_hash_match (bool): True if content hashes match
  • structural_match (bool): True if structure matches
  • semantic_similarity (float): Similarity score 0.0-1.0 (planned feature)
  • changes (list): Detected structural changes
Example:

get_strategy_history()

Get timeline of all jobs for a strategy.
Parameters: Returns: List[Dict] where each dict contains:
  • job_id (str): Job UUID
  • status (str): Job status
  • item_count (int): Items extracted
  • has_changes (bool): True if content changed vs. previous job
  • created_at (str): ISO timestamp
Example:

Schedule Methods

create_schedule()

Create a new recurring schedule.
Parameters: Returns: Dict with schedule details Example:
Example with API parameters:
Example with multiple URLs:
You must provide either url or urls, but not both. You must also provide either interval_seconds or cron_expression, but not both.

list_schedules()

List all schedules for the authenticated user.
Returns: List[Dict] of schedules Example:

update_schedule()

Update an existing schedule.
Parameters: Returns: Dict with updated schedule details Example:
Setting url will clear urls, and vice versa.

delete_schedule()

Delete a schedule (stops future jobs).
Parameters: Returns: Dict with confirmation message Example:

get_schedule_changes()

Get unseen changes for a schedule (pull-based change detection).
Parameters: Returns: Dict with fields:
  • schedule_id (str): Schedule UUID
  • changes (list): Jobs with changes (full job details)
  • count (int): Number of changed jobs
  • marked_seen (bool): Whether changes were marked as seen
Example:
Example with keyword filtering:
Use mark_seen=False to preview changes without affecting state. The filter parameter filters individual items within job results.

regenerate_webhook_secret()

Regenerate the webhook secret for a schedule. The old secret is immediately invalidated.
Parameters: Returns: Dict with schedule_id and the new webhook_secret Example:
Raises: MeterError if schedule has no webhook URL configured
The new secret is returned only once. Store it securely and update your webhook handler before the next delivery.

Workflow Methods

For workflow methods (create_workflow, run_workflow, wait_for_workflow, etc.), see the dedicated Workflow Methods reference.

Strategy Group Methods

Manage collections of strategies with shared schedules and output schemas. See Strategy Groups for concepts.

create_strategy_group()

Create a new strategy group.
Parameters: Returns: Dict with id, name, description, strategy_count, created_at, updated_at Example:

list_strategy_groups()

List all strategy groups.
Parameters: Returns: List[Dict] of strategy groups with strategy counts Example:

get_strategy_group()

Get group details including member strategies.
Parameters: Returns: Dict with id, name, description, strategies (list), created_at, updated_at Example:

update_strategy_group()

Update a group’s name or description.
Parameters: Returns: Dict with updated group details

delete_strategy_group()

Delete a group. Strategies become ungrouped (not deleted).
Parameters: Returns: Dict with confirmation message

add_strategies_to_group()

Add existing strategies to a group.
Parameters: Returns: Dict with confirmation message Example:

remove_strategy_from_group()

Remove a strategy from a group without deleting it.
Parameters: Returns: Dict with confirmation message

apply_group_schedule()

Apply a schedule to all strategies in a group.
Parameters: Returns: Dict with message, created count, updated count Example:
Provide either interval_seconds or cron_expression, not both.

delete_group_schedules()

Delete all schedules for strategies in a group.

toggle_group_schedules()

Enable or disable all schedules in a group.
Example:

apply_group_schema()

Apply an output schema to all strategies in a group. Triggers async regeneration.
Parameters: Returns: Dict with message and strategy_count Example:

get_schema_progress()

Poll progress of a group schema regeneration.

test_group_webhook()

Send a test webhook using a group’s webhook configuration.
Returns: Dict with success, status_code, message

Error Handling

All methods raise MeterError on API errors. See Error Handling for details.

Next steps

Error Handling

Learn about error handling and exceptions

Quick Start

See the SDK in action with examples

Strategies Guide

Deep dive into strategy concepts

Jobs Guide

Understanding job lifecycle

Need help?

Email me at mckinnon@meter.sh