An invalid stat_producer entry will lead to a generic KeyError and thus to an HTTP 500. This is OK, but I'd raise an explicit exception instead (explicit is better than implicit).

```python
sp = stat_producer_dict[stat_producer]
if sp is None:
    raise ValueError('Invalid stat producer: %s' % stat_producer)
page_count = sp(page_size, filter_query)
```