> ## Documentation Index
> Fetch the complete documentation index at: https://docs.meter.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Strategy Methods

> Generate, refine, and manage extraction strategies

# Strategy Methods

Strategy methods allow you to create and manage AI-generated extraction strategies. See the [MeterClient reference](/api-reference/python/client#strategy-methods) for complete method signatures.

## Quick reference

| Method                | Description                                 |
| --------------------- | ------------------------------------------- |
| `generate_strategy()` | Generate a new extraction strategy using AI |
| `refine_strategy()`   | Improve an existing strategy with feedback  |
| `list_strategies()`   | List all strategies                         |
| `get_strategy()`      | Get details for a specific strategy         |
| `delete_strategy()`   | Delete a strategy and associated data       |

## Common workflows

### Generate and refine

```python theme={null}
from meter_sdk import MeterClient

client = MeterClient(api_key="sk_live_...")

# Generate initial strategy
result = client.generate_strategy(
    url="https://shop.com/products",
    description="Extract product name, price, and image",
    name="Product Scraper"
)

# Check preview
print(result['preview_data'][:3])

# Refine if needed
if 'sku' not in result['preview_data'][0]:
    refined = client.refine_strategy(
        strategy_id=result['strategy_id'],
        feedback="Also extract the product SKU"
    )
    print(refined['preview_data'][:3])
```

### API-based scraping

For sites that load data via JavaScript APIs, use `force_api=True` to capture the underlying API:

```python theme={null}
# Force API-based capture
result = client.generate_strategy(
    url="https://api-heavy-site.com/listings",
    description="Extract all listing data",
    name="Listings API Scraper",
    force_api=True
)

# Check scraper type
print(f"Scraper type: {result['scraper_type']}")  # 'api' or 'css'

# For API strategies, available parameters are returned
if result.get('api_parameters'):
    print(f"Available parameters: {result['api_parameters']}")
    # e.g., {'page': 1, 'limit': 20, 'category': 'all'}
```

<Note>
  API-based strategies capture underlying API calls instead of using CSS selectors.
  This is useful for dynamic sites where data is loaded via JavaScript.
</Note>

### List and filter

```python theme={null}
# Get all strategies
strategies = client.list_strategies()

# Find by name
product_strategies = [
    s for s in strategies
    if 'product' in s['name'].lower()
]

# Most recent
recent = client.list_strategies(limit=5, offset=0)
```

### Batch operations

```python theme={null}
# Delete old strategies
strategies = client.list_strategies(limit=100)

for strategy in strategies:
    # Delete if created more than 30 days ago
    if is_old(strategy['created_at']):
        client.delete_strategy(strategy['strategy_id'])
        print(f"Deleted {strategy['name']}")
```

## See also

<CardGroup cols={2}>
  <Card title="Full Method Reference" icon="code" href="/api-reference/python/client#strategy-methods">
    Complete parameter and return type documentation
  </Card>

  <Card title="Strategies Concept" icon="brain" href="/concepts/strategies">
    Understand strategy lifecycle and best practices
  </Card>

  <Card title="REST API" icon="brackets-curly" href="/api-reference/rest/strategies">
    Strategy endpoints in the REST API
  </Card>

  <Card title="Quick Start" icon="rocket" href="/quickstart">
    Generate your first strategy
  </Card>
</CardGroup>

## Need help?

Email me at [mckinnon@meter.sh](mailto:mckinnon@meter.sh)
