Skip to main content

Python client for API Yandex Market

Supported Python Versions GitHub license Downloads Code style: black

Installation

pip install --upgrade tapi-yandex-market==1.0.3

API docs

Documentation

from tapi_yandex_market import YandexMarket

OAUTH_TOKEN = "{oauth_token}"
OAUTH_CLIENT_ID = "{oauth_client_id}"

client = YandexMarket(
    # https://yandex.ru/dev/market/partner/doc/dg/concepts/authorization.html
    oauth_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 methods

print(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 resource information

API requests

API requests are made using HTTP methods: DELETE, GET, POST, PUT.

An example of an HTTP GET request

from tapi_yandex_market import YandexMarket

client = YandexMarket(...)
result = client.campaigns().get()
# Raw data.
print(result.data)

An example of an HTTP POST request
Resource documentation

from tapi_yandex_market import YandexMarket

client = 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 HTTP PUT request
Resource documentation

from tapi_yandex_market import YandexMarket

client = 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 HTTP DELETE request
Resource documentation

from tapi_yandex_market import YandexMarket

client = YandexMarket(...)
result = client.outlets_licenses(campaignId=...).delete()
# Raw data.
print(result.data)

Client response methods

Result extraction method.

from tapi_yandex_market import YandexMarket

client = 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)
# 200

print(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.

from tapi_yandex_market import YandexMarket

client = 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}]

# Or

print(campaigns["campaigns"] == campaigns_list)
# True


# Or

print(campaigns.data["campaigns"] == campaigns["campaigns"] == campaigns_list)

Example of exporting statistics

Resource documentation

import datetime as dt

from tapi_yandex_market import YandexMarket
from tapi_yandex_market.helper import iter_flatten_stats_row

client = YandexMarket(...)

campaign_id = 100500
params = 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}

Features

Information about the resource.

client.campaigns().help()

Open resource documentation

client.campaigns().open_docs()

Send a request in the browser.

client.campaigns().open_in_browser()

Dependences

CHANGELOG

v1.0.3

2021-09-06

  • fix iter_flatten_stats_row

v1.0.1

2021-09-06

  • fix bugs

Author

Pavel Maksimov

You can contact me at Телеграм, Facebook

Good luck friend! Put an asterisk;)

Удачи тебе, друг! Поставь звездочку ;)

Metadata

Release files for tapi-yandex-market 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tapi-yandex-market 1.0.3
File Size Uploaded
tapi-yandex-market-1.0.3.tar.gz 15.2 kB Details

Release files / tapi-yandex-market-1.0.3.tar.gz

Download URL tapi-yandex-market-1.0.3.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
8f93761c4d2cb73c22fc9c6cc140655afdd1b05deb215a232b46daa26a8263ee
BLAKE2b-256 checksum
How to use checksums
630e9ae86eff89af04f2f22b7fe4cadc2cc953751135bd32d10ac99e5842a954
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.3.0 pkginfo/1.4.2 requests/2.23.0 requests-toolbelt/0.8.0 tqdm/4.45.0 CPython/3.6.3

Release history Release notifications | RSS feed

This release

1.0.3 This release

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page