Once a report status is processed, you can download it. Reports may consist of multiple parts.
Manual Download
Use client.download(requestId=request_id, partNumber=N).get() where partNumber is the index of the part (default is 0).
Automatic Download (Wait for report)
To avoid manual polling, initialize the client with wait_report=True. The client.create().post() call will block until the report is ready, allowing you to call client.download(requestId=request_id).get() immediately.
Data Transformation
Downloaded report parts can be transformed into different formats using the following methods:
to_values(): Returns data as values.to_lines(): Returns data as lines.to_dicts(): Returns data as dictionaries.to_columns(): Returns data in columns data orient.
from tapi_yandex_metrika import YandexMetrikaLogsapi
# Using wait_report=True to automate the process
client = YandexMetrikaLogsapi(
access_token=ACCESS_TOKEN,
default_url_params={'counterId': COUNTER_ID},
wait_report=True
)
params = {"fields": "ym:s:date,ym:s:clientID", "source": "visits", "date1": "2019-01-01", "date2": "2019-01-01"}
info = client.create().post(params=params)
request_id = info["log_request"]["request_id"]
# This will return the report once it is ready
report = client.download(requestId=request_id).get()
print(report.columns)
print(report().to_dicts())