An overview of the python package yadirstat - the easiest way to get statistics from the Yandex Direct API

Hello, I have to collect statistics from Yandex Direct and, to simplify my work, I published my python package, with which this can be done very simply.



First you need to get a token for your account ( more details here )



The yadirstat package is already published on pypi - you can install it using pip



pip install yadirstat


The package allows you to get the following statistics:



  • Campaign statistics
  • Statistics on impression terms (such as keywords and audiences)
  • Search query statistics


How statistics are requested:




yadirstat.yadirstat. ( ,  ,  ,  )


Something like this will look like a request to get statistics on search queries




query_report =yadirstat.yadirstat.query('','-1245234','2020-05-10','2020-07-15')
print(query_report)




And here's a request to get statistics on campaigns :


campaign_report = yadirstat.yadirstat.campaign('','-1245234','2020-05-10','2020-07-15')
print(campaign_report)


And here's a request to get statistics on the conditions of impressions :




criteria_report = yadirstat.yadirstat.criteria('','-1245234','2020-05-10','2020-07-15')
print(criteria_report)


An example of my request:




from yadirstat import yadirstat
x = yadirstat.yadirstat.campaign('AgAAAxxxxxxxXXXXXXxxxxxXXXXXcI','BxxxxXXXX','2020-05-10','2020-07-15')
print(x)


The output looks like this:







If the data does not fit during the output, you can use the following:




import pandas as pd
pd.set_option('display.max_columns', None)
pd.set_option('display.expand_frame_repr', False)
pd.set_option('max_colwidth', 80)
pd.set_option('max_rows', 600000)


At the output, we get a DataFrame.



For full use, I replace "-" with "0"



Data structure



Searches:



  • CampaignName
  • Query
  • Impressions
  • Clicks
  • Ctr
  • Cost
  • AvgCpc
  • ConversionRate
  • CostPerConversion
  • Conversions


Campaigns *:



  • Date
  • CampaignName
  • Impressions
  • Clicks
  • Ctr
  • Cost
  • AvgCpc
  • BounceRate
  • AvgPageviews
  • ConversionRate
  • CostPerConversion
  • Conversions
  • Date


Show conditions:



  • CampaignName
  • Criterion
  • Impressions
  • Clicks
  • Ctr
  • Cost
  • AvgCpc
  • Date


* - Adding a date as the last column allows you not to lose data by dates when transferring a DataFrame (For example, when transferring to BigQuery, a column with dates is lost due to the fact that it is indexed, to avoid problems, I just duplicated this column).



Why such a structure? This is how I collect statistics so that I can then send it to Google BigQuery and then visualize it in Google DataStudio.



I would be glad to hear suggestions for the development of this package and your experience in collecting statistics.



PS:



  • This also works with agent accounts.
  • And with Elama accounts



All Articles