Metadata-Version: 2.5
Name: omnicommerce
Version: 0.2.0
Summary: Python SDK for the OmniCommerce API. Generated from the public OpenAPI spec.
Project-URL: Homepage, https://docs.omnicommerce.sg/sdk/python
Project-URL: Repository, https://github.com/rmdort/omnicommerce
License: MIT
License-File: LICENSE
Keywords: api,omni,omnicommerce,sdk
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Description-Content-Type: text/markdown

# omnicommerce

Python client for the [OmniCommerce API](https://docs.omnicommerce.sg/api-reference).

The client is generated from the public OpenAPI spec, the same operation map as `@omni-commerce/sdk`. Sync and async clients take snake_case keyword arguments. Responses are parsed JSON.

## Install

Install from PyPI:

```bash
python3 -m pip install omnicommerce
```

Python 3.10+.

## Usage

```python
import os
from omnicommerce import Omni

with Omni(api_key=os.environ["OMNI_API_KEY"]) as client:
    products = client.products.list(q="lamp")
    job = client.products.create(
        product={
            "sku": "SKU-100",
            "title": "Sample product",
            "price": 29.9,
            "currency": "SGD",
            "images": ["https://cdn.example.com/product.jpg"],
        }
    )
    created = client.jobs.wait(job_id=job["jobId"])
```

API keys are organization-scoped. Do not send `organization_id` on API-key requests.

```python
from omnicommerce import AsyncOmni, Omni, OmniEnvironment

client = Omni(
    api_key="omni_sk_...",
    environment=OmniEnvironment.LOCAL,  # http://localhost:3000
    timeout_in_seconds=60,
    max_retries=2,
)

async with AsyncOmni(api_key=os.environ["OMNI_API_KEY"]) as client:
    products = await client.products.list(q="lamp")
```

`client.with_raw_response.products.get(product_id="prod_123")` returns `data`, `status_code`, `headers`, and `url`.

## Resources

| Client                         | Examples                                                                        |
| ------------------------------ | ------------------------------------------------------------------------------- |
| `client.products`              | `list`, `create`, `get`, `update`, `delete`, `publish`, `bulk_import`, `enrich` |
| `client.orders`                | `list`, `create`, `get`, `update`                                               |
| `client.promotions`            | `list`, `create`, `get`, `update`, `delete`, `sync`                             |
| `client.price_books`           | `list`, `create`, `get`, `update`, `delete`, `preview`                          |
| `client.aop`                   | `create`, `execute`, `get_config`, `update_config`, `retry`                     |
| `client.jobs`                  | `get`, `cancel`, `wait`                                                         |
| `client.webhooks`              | `list`, `create`                                                                |
| `client.checkout_sessions`     | `create`, `get`, `update`, `complete`, `cancel`                                 |
| `client.ucp.checkout_sessions` | Universal Commerce Protocol checkout                                            |
| `client.oauth`                 | `token`, `revoke`                                                               |

Every other documented tag is exposed the same way.

## Errors

```python
from omnicommerce import NotFoundError, Omni, OmniError

try:
    client.products.get(product_id="missing")
except NotFoundError:
    pass
except OmniError as error:
    print(error.status_code, error.body)
```

## Webhooks

```python
from omnicommerce import construct_event

event = construct_event(raw_body, headers, os.environ["OMNI_WEBHOOK_SECRET"])
```

Signature: HMAC-SHA256 over `{timestamp}.{raw_body}` compared to `X-Omni-Signature`.

## Regenerate from OpenAPI

From the monorepo root:

```bash
yarn sdk:generate
```

That refreshes `src/omnicommerce/_generated/resources.py` from `docs/openapi.json`.
