# Python reference (tryyoursize)

> The server SDK for Python 3.9+, standard library only: recommendations, catalog, orders and returns, audit log, webhooks.

Source: https://docs.tryyoursize.com/reference/python/

*SDK* · `tryyoursize` · v0.1.0

The official Python SDK for the TryYourSize server API: no third-party dependencies (standard library only), Python 3.9+, fully typed (`py.typed`). Use it **on your server** with a secret key (`sk_test_…` / `sk_live_…`) or a restricted key (`rk_…`); publishable keys (`pk_…`) are refused. Responses are plain dicts typed with `TypedDict`s generated from our OpenAPI spec.

## Install

**pip**

```bash
pip install tryyoursize
```

**npm**

```bash
npm install @tryyoursize/node
```

## Initialize

**Python**

```python

tys = tryyoursize.TryYourSize(os.environ["TRYYOURSIZE_SECRET_KEY"], max_retries=2, timeout=30.0)
```

**Node.js**

```ts

const tys = new TryYourSize(process.env.TRYYOURSIZE_SECRET_KEY!, {
  maxRetries: 2,      // network errors, timeouts, 429, 5xx
  timeoutMs: 30_000,
});
```

Every method maps to one HTTP operation of the [HTTP API reference](https://docs.tryyoursize.com/api/reference.md). Errors are typed: see [Errors](https://docs.tryyoursize.com/reference/python/errors.md) and the [API error codes](https://docs.tryyoursize.com/api/errors.md).

## Client

| | |
|---|---|
| [`TryYourSize()`](https://docs.tryyoursize.com/reference/python/client.md) | Creates a client for one secret or restricted key. |
| [`mode`](https://docs.tryyoursize.com/reference/python/mode.md) | "test" or "live", from the key prefix ("unknown" for other formats). |

## Recommendations

| | |
|---|---|
| [`recommendations.create()`](https://docs.tryyoursize.com/reference/python/recommendations-create.md) | The shopper's size for up to 25 products (SKUs), from a browser SDK handle. |

## Products

| | |
|---|---|
| [`products.list()`](https://docs.tryyoursize.com/reference/python/products-list.md) | The store's products, newest first. |
| [`products.create()`](https://docs.tryyoursize.com/reference/python/products-create.md) | Create a product. |
| [`products.retrieve()`](https://docs.tryyoursize.com/reference/python/products-retrieve.md) | A product by its TryYourSize ID or its SKU. |
| [`products.update()`](https://docs.tryyoursize.com/reference/python/products-update.md) | Replace the SKU, name and category (all three required). |
| [`products.size_map.retrieve()`](https://docs.tryyoursize.com/reference/python/products-size-map-retrieve.md) | A product's size map (Studio size → your size label). |
| [`products.size_map.save()`](https://docs.tryyoursize.com/reference/python/products-size-map-save.md) | Replace the size map, e.g. |
| [`products.garments.list()`](https://docs.tryyoursize.com/reference/python/products-garments-list.md) | Garment versions of a product, newest first (has_more is always false). |
| [`products.garments.create_draft()`](https://docs.tryyoursize.com/reference/python/products-garments-create-draft.md) | Start a draft version: sizes, points of measure (mm) per size, grading, fabric. |

## Garments

| | |
|---|---|
| [`garments.retrieve()`](https://docs.tryyoursize.com/reference/python/garments-retrieve.md) | A garment version. |
| [`garments.update_draft()`](https://docs.tryyoursize.com/reference/python/garments-update-draft.md) | Replace a draft's content. |
| [`garments.publish()`](https://docs.tryyoursize.com/reference/python/garments-publish.md) | Publish a complete draft (same checks as Studio; 422 lists what is missing). |

## Fit groups

| | |
|---|---|
| [`fit_groups.list()`](https://docs.tryyoursize.com/reference/python/fit-groups-list.md) | Fit groups, cursor-paginated. |
| [`fit_groups.create()`](https://docs.tryyoursize.com/reference/python/fit-groups-create.md) | Create a fit group: one garment shared by several products (colourways, prints). |
| [`fit_groups.retrieve()`](https://docs.tryyoursize.com/reference/python/fit-groups-retrieve.md) | A fit group. |
| [`fit_groups.link_products()`](https://docs.tryyoursize.com/reference/python/fit-groups-link-products.md) | Move products into the fit group; they then use its garment. |

## Outcomes

| | |
|---|---|
| [`orders.create()`](https://docs.tryyoursize.com/reference/python/orders-create.md) | Record an order (idempotent by order id; re-sending updates it). |
| [`returns.create()`](https://docs.tryyoursize.com/reference/python/returns-create.md) | Record a return of an order line (idempotent by return id and line). |

## Audit log

| | |
|---|---|
| [`audit_events.list()`](https://docs.tryyoursize.com/reference/python/audit-events-list.md) | The audit log of the key's organization, newest first. |

## Webhooks

| | |
|---|---|
| [`Webhook.construct_event()`](https://docs.tryyoursize.com/reference/python/webhook-construct-event.md) | Verify the signature, then return the parsed event envelope. |
| [`Webhook.verify_signature()`](https://docs.tryyoursize.com/reference/python/webhook-verify-signature.md) | Return True or raise SignatureVerificationError. |
| [`Webhook.generate_test_header()`](https://docs.tryyoursize.com/reference/python/webhook-generate-test-header.md) | A valid TYS-Signature value, for your own tests. |

## Pagination and errors

| | |
|---|---|
| [`ListPage`](https://docs.tryyoursize.com/reference/python/list-page.md) | One page of a list. |
| [`Errors`](https://docs.tryyoursize.com/reference/python/errors.md) | Every exception is a TryYourSizeError. |
