import requests
from typing import List, Dict, Any
def query_events(tenant_id: str, api_key: str, filters: Dict[str, Any]) -> List[Dict]:
"""Query events with filters and pagination"""
response = requests.post(
f'https://api.grainql.com/v1/api/query/{tenant_id}',
headers={
'Content-Type': 'application/json',
'X-API-Key': api_key
},
json=filters
)
response.raise_for_status()
return response.json()
# Usage
events = query_events('your-tenant-id', 'your-api-key', {
'event': 'purchase_completed',
'filterSet': [
{
'property': 'properties.price',
'comparison': 'GREATER_THAN',
'value': 50
}
],
'pagination': {'offset': 0, 'size': 100}
})
print(f'Found {len(events)} high-value purchases')