Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tapi-yandex-market

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tapi-yandex-market

Python client for API Yandex Market

  • 1.0.3
  • PyPI
  • Socket score

Maintainers
1

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;)

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

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc