Metadata-Version: 2.4
Name: plentymarkets-api-client
Version: 0.2.1
Summary: Async Python client for the PlentyMarkets REST API
Project-URL: Homepage, https://codeberg.org/ZanderHammer/pyPlentyAPI
Project-URL: Repository, https://codeberg.org/ZanderHammer/pyPlentyAPI
Project-URL: Issues, https://codeberg.org/ZanderHammer/pyPlentyAPI/issues
Project-URL: Changelog, https://codeberg.org/ZanderHammer/pyPlentyAPI/src/branch/main/CHANGELOG.md
Author-email: Alexander Hammer <alexander@hmmr.online>
License: MIT License
        
        Copyright (c) 2026 Alexander Hammer
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: async,ecommerce,httpx,plentymarkets,rest-api
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: httpx>=0.27
Provides-Extra: dev
Requires-Dist: commitizen>=3.29; extra == 'dev'
Requires-Dist: hatchling>=1.25; extra == 'dev'
Requires-Dist: pre-commit>=3.7; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-httpx>=0.30; extra == 'dev'
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# pyPlentyAPI

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Python: 3.11+](https://img.shields.io/badge/Python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![UV: Sync](https://img.shields.io/badge/uv-sync-3178C6.svg?logo=python&logoColor=white)](https://github.com/astral-sh/uv)
[![Tests: Pytest](https://img.shields.io/badge/Tests-pytest-0A9EDC.svg?logo=pytest&logoColor=white)](https://docs.pytest.org/)

Async Python client for the [PlentyMarkets REST API](https://developers.plentymarkets.com/en-gb/plentymarkets-rest-api/index.html).

## Features
- **Async-first**: Built on `httpx.AsyncClient` for high-performance async/await support.
- **Lazy-loaded modules**: Access `orders`, `items`, `stock`, and `contacts` as properties of `PlentyClient`.
- **Auto-refreshing auth**: Tokens are refreshed automatically when within 60 seconds of expiry.
- **Comprehensive error handling**: Custom exceptions for HTTP status codes (e.g., `NotFoundError`, `RateLimitError`).
- **Pagination support**: Async generators for iterating across all pages of results.
- **Type hints**: Full type annotations for IDE support and static analysis.

## Installation
```bash
pip install plentymarkets-api-client
```

Or with `uv`:
```bash
uv add plentymarkets-api-client
```

## Quickstart
```python
import asyncio
from plentymarkets import PlentyClient

async def main():
    async with PlentyClient(username="your_username", password="your_password") as client:
        # Fetch an order by ID
        order = await client.orders.get(123)
        print(order)
        
        # List all items (paginated)
        async for item in client.items.paginate_items():
            print(item)

asyncio.run(main())
```

## Modules
| Module    | Description                          | Key Methods                                                                                     |
|-----------|--------------------------------------|-------------------------------------------------------------------------------------------------|
| **Orders**    | Manage orders and order statuses.    | `get()`, `list()`, `create()`, `update_status()`, `paginate_orders()`                           |
| **Items**     | Manage items and item variants.      | `get()`, `list()`, `create()`, `update()`, `paginate_items()`                                   |
| **Stock**     | Manage stock across warehouses.      | `get_by_warehouse()`, `correct()`, `paginate_stock()`                                           |
| **Contacts**  | Manage customer and supplier data.   | `get()`, `list()`, `create()`, `update()`, `paginate_contacts()`                                |
| **Pim**       | Product Information Management — variations, attributes, categories, sales prices, barcodes, and more. | `client.pim.*` (70+ methods) |

## API Coverage

Endpoint totals are counted against the [PlentyMarkets OpenAPI spec](https://raw.githubusercontent.com/plentymarkets/api-doc/master/plentymarkets/openApiV3/openApiV3.json), grouped by its own tags.

| Module      | Endpoints  | Status                          |
|-------------|------------|----------------------------------|
| **Pim**         | 41 / 41    | ✅ Complete                      |
| **Order**       | 2 / 239    | Core operations                  |
| **Item**        | 2 / 146    | Core operations                  |
| **Account**     | 2 / 87     | Core operations                  |
| **Stock**       | 2 / 16     | Core operations                  |

`Pim` reached full endpoint coverage in `v0.2.0` — see [ROADMAP.md](ROADMAP.md) for the endpoint-by-endpoint breakdown and the rest of the API surface still planned. `Stock`'s two methods live under the API's `StockManagement` tag.

## Authentication
1. Initialize `PlentyClient` with your PlentyMarkets username and password.
2. The client automatically logs in and manages the `accessToken` lifecycle.
3. Tokens are sent as `Authorization: Bearer <token>` in all requests.
4. If a 401 error occurs, the client attempts to re-login once before failing.

## Error Handling
Custom exceptions are raised for HTTP errors:
- `AuthError`: 401 Unauthorized
- `NotFoundError`: 404 Not Found  
- `RateLimitError`: 429 Too Many Requests
- `ServerError`: 5xx Server Errors
- `ConnectionError`: Network failures

Example:
```python
try:
    order = await client.orders.get(99999)
except plentymarkets.NotFoundError:
    print("Order not found")
except plentymarkets.RateLimitError:
    print("Rate limit exceeded")
```

## Pagination
Use async generators to iterate across all pages:
```python
async for order in client.orders.paginate_orders():
    print(order)
```

## Development
### Setup
```bash
uv sync --extra dev
uv run pre-commit install --hook-type commit-msg
```

### Running Tests
```bash
uv run pytest                        # Unit tests
uv run pytest -m integration         # Integration tests (requires live credentials)
```

## License
MIT
