Библиотека для работы с 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.
- ping (
- 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") datetimeobject
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.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_wb-0.2.0.tar.gz.
File metadata
- Download URL: python_wb-0.2.0.tar.gz
- Upload date:
- Size: 51.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1d903defd88bf5e7ff8f1b8af373244772dec1f273a182bbb68b68ea7fc2335
|
|
| MD5 |
50fd437189e18569eaa1721134e0aca1
|
|
| BLAKE2b-256 |
c26a0ff0487958fa04648d11c7677baaf61be878dfce6c3fc736b8564c1a88a5
|
File details
Details for the file python_wb-0.2.0-py3-none-any.whl.
File metadata
- Download URL: python_wb-0.2.0-py3-none-any.whl
- Upload date:
- Size: 73.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97f397e663bcbe66a17532f28ef5d7b3eca3f462ddd0c780198dc1635c88762d
|
|
| MD5 |
07902d9e5fdd0d1b7e74aacac3dfeef8
|
|
| BLAKE2b-256 |
1295f27269a0b30fd738e09d367d5005c671fb6ddf180bbd50bcf18ef712733a
|