Skip to main content

Библиотека для работы с API Wildberries на Python.

Project description

pywb

Asynchronous Python client for working with the Wildberries Seller API.

The library provides:

  • async HTTP client based on aiohttp
  • typed request/response models via pydantic
  • centralized API error mapping to Python exceptions
  • support for multiple Wildberries API domains

Features

  • Easy entry point through WBClient
  • Domain routing (common, content, statistics, etc.)
  • Built-in methods:
    • ping (client.ping())
    • content ping (client.ping_content())
    • statistics orders report (client.get_orders(...))
    • etc.
  • Generic low-level method execution:
    • await client(SomeWBMethod(...))
  • Context manager support:
    • async with WBClient(...) as client:

Requirements

  • Python 3.12+

Installation

Using uv:

uv add python-wb

With pip:

pip install python-wb

Quick Start

import asyncio
from pywb import WBClient


async def main() -> None:
    token = "YOUR_WB_API_TOKEN"

    async with WBClient(token) as client:
        result = await client.ping()
        print(result.ts, result.status)


if __name__ == "__main__":
    asyncio.run(main())

Usage

1) Health check

result = await client.ping()
print(result.status)

2) Content API health check

result = await client.ping_content()
print(result.status)

3) Get orders from Statistics API

from datetime import datetime

orders = await client.get_orders(
    date_from=datetime(2026, 1, 1, 0, 0, 0),
    flag=0,
)

if orders:
    print(orders[0].srid, orders[0].brand)

date_from accepts either:

  • ISO 8601 string (example: "2022-03-04T18:08:31")
  • datetime object

Low-Level Method Call

You can call method objects directly through the client:

from pywb.methods import Ping

response = await client(Ping())

This is useful when adding new method classes while keeping one transport layer.

Error Handling

HTTP errors are mapped to dedicated exceptions:

  • BadRequestError (400)
  • UnauthorizedError (401)
  • PaymentRequiredError (402)
  • AccessDeniedError (403)
  • NotFoundError (404)
  • ConflictError (409)
  • PayloadTooLargeError (413)
  • UnprocessableEntityError (422)
  • TooManyRequestsError (429)
  • InternalServerError (5xx)

Base type: WBApiError

Example:

from pywb.exceptions import BadRequestError

try:
    await client.get_orders(date_from="2022-03-04T18:08:31")
except BadRequestError as e:
    print(e)
    print(e.payload)

Network/transport failures in the aiohttp session are raised as WBNetworkError.

Sandbox and Domains

The client supports domain-based URL routing through WBDomain and WB_ROUTER.

To enable sandbox mode (only where available for a domain):

client = WBClient(token="YOUR_TOKEN", is_sandbox=True)

If sandbox is unavailable for a domain, a ValueError is raised by the session router.

Development

Run the example script:

python examples/ping.py

Notes

  • Keep your API token secret and do not commit it to git.
  • Respect Wildberries API rate limits for each endpoint.
  • For the statistics orders endpoint, use pagination strategy based on the last record timestamp when handling large datasets.

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

python_wb-0.1.0.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

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

python_wb-0.1.0-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file python_wb-0.1.0.tar.gz.

File metadata

  • Download URL: python_wb-0.1.0.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for python_wb-0.1.0.tar.gz
Algorithm Hash digest
SHA256 520a2dfacbf6796b6f1fc754b87cbd5d2da00afb3ab7d216bf1434a20f748619
MD5 8ca63185580094896af6091b98c83b15
BLAKE2b-256 3720dcc6e20d58c9a3e344bab1b6dde02bfbca3916de9a49d5807e4aea3de275

See more details on using hashes here.

File details

Details for the file python_wb-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: python_wb-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for python_wb-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 25c42cc24113cba97f14f286f94fe7798d45ea409b846731b099789f50804817
MD5 207431129f4899104fb4997b7f161d7f
BLAKE2b-256 6de056085e9bb52f4e5d35cc045039ba511beba46c5ff5d094b3f67f92786264

See more details on using hashes here.

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