Package: tapi-yandex-market
Python client forAPI Yandex MarketInstallationpip install --upgrade tapi-yandex-market==1.0.3API docsDocumentationfromtapi_yandex_marketimportYandexMarketOAUTH_TOKEN="{oauth_token}"OAUTH_CLIENT_ID="{oauth_client_id}"client=YandexMarket(# https://yandex.ru/dev/market/partner/doc/dg/concepts/authorization.htmloauth_token=OAUTH_TOKEN,oauth_client_id=OAUTH_CLIENT_ID,# Will retry the request if the request limit is reached.retry_if_exceeded_requests_limit=True,)Resource methodsprint(dir(client))['all_feeds_categories','all_offers','balance','bid_recommendations','bids','bids_settings','campaign','campaign_invoice','campaign_outlets','campaigns','campaigns_by_login','daily_stats','delivery_services_dictionary','feed','feed_categories','feed_index_logs','feed_parameters','feed_refresh','feedback_updates','feeds','geo_region','geo_regions','hidden_offers','invoice','invoice_pay_preview','logins','model','model_offers','models','models_offers','monthly_stats','offer_prices','offers','offers_stats','outlet','outlets','outlets_licenses','quality_check','quality_report','quality_ticket','quality_ticket_fix','quality_tickets','region','region_children','remove_offer_prices','settings','stats','top_market_search','update_offer_prices','weekly_stats']Detailed resourceinformationAPI requestsAPI requests are made using HTTPmethods:DELETE,GET,POST,PUT.An example of an HTTPGETrequestfromtapi_yandex_marketimportYandexMarketclient=YandexMarket(...)result=client.campaigns().get()# Raw data.print(result.data)An example of an HTTPPOSTrequestResourcedocumentationfromtapi_yandex_marketimportYandexMarketclient=YandexMarket(...)body={"parameters":[{"deleted":{boolean},"name":"{enum}","values":[{int32},...]},...]}result=client.feed_parameters(campaignId=...,feedId=...).post(data=body)# Raw data.print(result.data)An example of an HTTPPUTrequestResourcedocumentationfromtapi_yandex_marketimportYandexMarketclient=YandexMarket(...)body={"bids":[{"feedId":{int64},"offerId":"{string}","bid":{double},"dontPullUpBids":{boolean}},...]}result=client.bids(campaignId=...).put(data=body)# Raw data.print(result.data)An example of an HTTPDELETErequestResourcedocumentationfromtapi_yandex_marketimportYandexMarketclient=YandexMarket(...)result=client.outlets_licenses(campaignId=...).delete()# Raw data.print(result.data)Client response methodsResult extraction method.fromtapi_yandex_marketimportYandexMarketclient=YandexMarket(...)campaign=client.campaign(campaignId=100500).get()print(type(campaign))# <class 'tapi2.tapi.TapiClient'>print(campaign)# <class 'tapi2.tapi.TapiClient'># <TapiClient object# {   'campaign': {   'clientId': 992161,#                     'domain': 'lady-xl.ru',#                     'id': 21033612,#                     'state': 1}}>print(campaign.status_code)# 200print(campaign.response)# <Response [200]>print(campaign.request_kwargs)# {'url': 'https://api.partner.market.yandex.ru/v2/campaigns/100500', 'params': {}, 'headers': {'Content-Type': 'application/json', 'Accept': 'application/json', 'Authorization': 'OAuth oauth_token="...", oauth_client_id="..."'}, 'data': None}print(type(campaign.data))# <class 'dict'>print(campaign.data)# {'campaign': {'id': 123456789, 'clientId': 100999, 'domain': 'shop100500', 'state': 1}}print(type(campaign["campaign"]))# <class 'dict'>print(campaign["campaign"])# {'id': 123456789, 'clientId': 100999, 'domain': 'shop100500', 'state': 1}.extract()Result extraction method.fromtapi_yandex_marketimportYandexMarketclient=YandexMarket(...)campaigns=client.campaigns().get()print(campaigns.data)# {'pager': {'total': 1, 'from': 1, 'to': 1, 'currentPage': 1, 'pagesCount': 1, 'pageSize': 1}, 'campaigns': [{'id': 21033612, 'clientId': 992161, 'domain': 'lady-xl.ru', 'state': 1}]}campaigns_list=campaigns().extract()print(type(campaigns_list))# <class 'list'>print(campaigns_list)# [{'id': 21033612, 'clientId': 992161, 'domain': 'lady-xl.ru', 'state': 1}]# Orprint(campaigns["campaigns"]==campaigns_list)# True# Orprint(campaigns.data["campaigns"]==campaigns["campaigns"]==campaigns_list)Example of exporting statisticsResourcedocumentationimportdatetimeasdtfromtapi_yandex_marketimportYandexMarketfromtapi_yandex_market.helperimportiter_flatten_stats_rowclient=YandexMarket(...)campaign_id=100500params=dict(fromDate=dt.date.today()-dt.timedelta(days=3),toDate=dt.date.today(),byPlaces=True,fields="shows,mobile,model")result=client.stats(campaignId=campaign_id).get(params=params)data=result().extract()print(data[0])# {'clicks': 282,# 'date': '2021-09-03',# 'detailedStats': [{'clicks': 259,#                 'shows': '1077017',#                 'spending': 33.37,#                 'type': 'mobile'}],# 'placeGroup': 3,# 'shows': '1409982',# 'spending': 36.29}new_column_names={"clicksMobile":"clicks_mobile"}data=list(iter_flatten_stats_row(data,**new_column_names))print(data[0])# {'clicks': 282,#  'clicks_mobile': 259,#  'date': '2021-09-03',#  'placeGroup': 3,#  'shows': '1409982',#  'showsMobile': '1077017',#  'spending': 36.29,#  'spendingMobile': 33.37}FeaturesInformation about the resource.client.campaigns().help()Open resource documentationclient.campaigns().open_docs()Send a request in the browser.client.campaigns().open_in_browser()Dependencesrequeststapi_wrapperCHANGELOGv1.0.32021-09-06fix iter_flatten_stats_rowv1.0.12021-09-06fix bugsAuthorPavel MaksimovYou can contact me atТелеграм,FacebookGood luck friend! Put an asterisk;)Удачи тебе, друг! Поставь звездочку ;)