Skip to main content

A Python API client for Perekrestok catalog

Project description

Perekrestok API (not official)

Tests last run (ISO) Tests PyPI - Python Version PyPI - Package Version PyPI - Downloads License Discord Telegram

Perekrestok (Перекрёсток) - https://www.perekrestok.ru/

⭐ Star us on GitHub | 📚 Read the Docs | 🐛 Report Bug

Принцип работы

Библиотека полностью повторяет сетевую работу обычного пользователя на сайте.

Usage

pip install perekrestok_api
from perekrestok_api import PerekrestokAPI
from perekrestok_api import abstraction
import asyncio


async def main():
    async with PerekrestokAPI() as Api:
        geopos_handler = await Api.Geolocation.current()
        geopos = geopos_handler.json()
        print(f'Текущий город сессии {geopos["content"]["city"]["name"]} ({geopos["content"]["city"]["id"]})')
    
        # Получаем список категорий
        categories = await Api.Catalog.tree()
        cat = categories.json()
        print(f'Список категорий: {len(cat["content"]["items"])}')

        # Выводим первую категорию
        print(f'Категория: {cat["content"]["items"][0]["category"]["title"]} ({cat["content"]["items"][0]["category"]["id"]})')
        # Получаем список товаров
        filter = abstraction.CatalogFeedFilter()
        filter.CATEGORY_ID = cat["content"]["items"][0]["category"]["id"]
        filter.PROMO_LISTING = 27
        products = await Api.Catalog.feed(filter=filter)
        prod = products.json()

        # Выводим первый товар
        print(f'Первый товар: {prod["content"]["items"][0]["title"]} ({prod["content"]["items"][0]["id"]})')

# Запуск асинхронной функции main
if __name__ == "__main__":
    asyncio.run(main())
> Текущий город сессии Москва (81)
> Список категорий: 31
> Категория: Встречаем Новый год (1692)
> Первый товар: Икра Камчатское Море горбуши зернистая солёная, 320г (487063)

Для более подробной информации смотрите референсы документации.


Автотесты API (pytest + snapshots)

В проекте используется автотест-фреймворк из human_requests:

  • endpoint-методы в бизнес-коде помечаются @autotest;
  • pytest-плагин сам находит эти методы и запускает их;
  • JSON-ответы проверяются через pytest-jsonschema-snapshot (schemashot);
  • параметры вызова и пост-обработка результата регистрируются в tests/endpoints/* через:
    • @autotest_params
    • @autotest_hook
    • @autotest_depends_on

Минимальная конфигурация уже включена в pyproject.toml:

[tool.pytest.ini_options]
anyio_mode = "auto"
autotest_start_class = "perekrestok_api.PerekrestokAPI"
autotest_typecheck = "strict"

Запуск тестов:

pytest

Важно:

  • используется pytest-anyio (не pytest-asyncio);
  • проверка типов аргументов @autotest_params берётся из аннотаций endpoint-методов (autotest_typecheck = "strict");
  • ручные тесты остаются только для кейсов, которые не относятся к JSON-схемам endpoint-методов (например, download_image).

Report

If you have any problems using it / suggestions, do not hesitate to write to the project's GitHub!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

perekrestok_api-0.2.2.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

perekrestok_api-0.2.2-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

Details for the file perekrestok_api-0.2.2.tar.gz.

File metadata

  • Download URL: perekrestok_api-0.2.2.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for perekrestok_api-0.2.2.tar.gz
Algorithm Hash digest
SHA256 7add999e9da7a7de552bd344e70efcfcaa076b8df2bd7d703f54a3b074be0de5
MD5 c0d9ec081ef99fa7b1f97bdd89681ff9
BLAKE2b-256 98c015f42da51b5cf10173fb86ddb8c2aea8efa2544f37442690d99e9e8738fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for perekrestok_api-0.2.2.tar.gz:

Publisher: publish.yml on Open-Inflation/perekrestok_api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file perekrestok_api-0.2.2-py3-none-any.whl.

File metadata

File hashes

Hashes for perekrestok_api-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3109fce07ef699305cf94b9122ce3c49ca95f6403aa1c9597184f95adf8eac51
MD5 0e8f931300511db0266d6ee580dc4511
BLAKE2b-256 740ef159604f6cda2b8dbcf86af9ca745cfb14af5fa8cd7088a6618df471b3e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for perekrestok_api-0.2.2-py3-none-any.whl:

Publisher: publish.yml on Open-Inflation/perekrestok_api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page