Metadata-Version: 2.4
Name: salable-sdk
Version: 0.0.1b1
Summary: Official Python SDK for the Salable API
Author: Salable
License-Expression: Apache-2.0
Project-URL: Homepage, https://salable.app
Project-URL: Documentation, https://github.com/Salable/python-sdk#readme
Project-URL: Repository, https://github.com/Salable/python-sdk
Project-URL: Issues, https://github.com/Salable/python-sdk/issues
Project-URL: Changelog, https://github.com/Salable/python-sdk/blob/main/CHANGELOG.md
Keywords: salable,sdk,subscriptions,billing,entitlements
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27
Requires-Dist: microsoft-kiota-abstractions>=1.11.7
Requires-Dist: microsoft-kiota-http>=1.11.7
Requires-Dist: microsoft-kiota-serialization-json>=1.11.7
Requires-Dist: microsoft-kiota-serialization-text>=1.11.7
Requires-Dist: microsoft-kiota-serialization-form>=1.11.7
Requires-Dist: microsoft-kiota-serialization-multipart>=1.11.7
Provides-Extra: dev
Requires-Dist: pytest>=8.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.24.0; extra == "dev"
Requires-Dist: ruff>=0.8.0; extra == "dev"
Requires-Dist: mypy>=1.13.0; extra == "dev"
Dynamic: license-file

# Salable Python SDK

The official Python SDK for the [Salable](https://salable.app) API. It wraps the REST API for products, plans, subscriptions, and the rest of the Salable resources.

Package name: `salable-sdk`.

Requires **Python 3.10+**. Resource methods are generated by [Kiota](https://github.com/microsoft/kiota) and are async. `await` each call.

Releases before `1.0.0` are `0.x`. Those versions can still change as the OpenAPI description settles. `1.0.0` is the compatibility promise.

## Table of Contents

- [Getting Started](#getting-started)
  - [Installation](#installation)
  - [Initialisation](#initialisation)
- [CRUD Pattern](#crud-pattern)
- [Error Handling](#error-handling)
- [Query Parameters](#query-parameters)
- [Pagination](#pagination)

## Getting Started

### Installation

```bash
pip install salable-sdk
```

Releases from the `beta` branch are prereleases. pip skips those unless you opt in:

```bash
pip install --pre salable-sdk
```

### Initialisation

Create one `Salable` client with your secret API key and reuse it. The default client calls `https://salable.app`, times out after 30 seconds, retries 429, 503, and 504, and sends a `salable-python/<version>` User-Agent.

```python
import asyncio

from salable import Salable


async def main() -> None:
    async with Salable("your-api-key") as salable:
        products = await salable.api.products.get()
        print(products)


asyncio.run(main())
```

Your API key is sent as a `Bearer` token on every request. Keep it out of source control.

Pass `base_url` for another origin. Pass `http_client` for your own `httpx.AsyncClient`. A client passed as `http_client` replaces the default timeout, retries, and User-Agent, so set those on that client if you still want them. `aclose()` closes that client too.

```python
import httpx

from salable import Salable

salable = Salable(
    "your-api-key",
    base_url="https://salable.app",
    http_client=httpx.AsyncClient(timeout=10),
)
```

Close the client with `await salable.aclose()`, or use `async with`.

## CRUD Pattern

Every resource uses the same request-builder pattern. `await` the method each call returns.

| Operation | Method | Example |
|-----------|--------|---------|
| List all  | `.get()` | `await salable.api.products.get()` |
| Get one   | `.by_id(id).get()` | `await salable.api.products.by_id(id).get()` |
| Create    | `.post(body)` | `await salable.api.products.post(body)` |
| Update    | `.by_id(id).put(body)` | `await salable.api.products.by_id(id).put(body)` |
| Delete    | `.by_id(id).delete()` | `await salable.api.products.by_id(id).delete()` |

Product import is `salable.api.products.import_()`. `import` is a Python keyword, so the navigator keeps the trailing underscore. The HTTP path remains `/api/products/import`.

Create example:

```python
from salable.sdk.models.create_product_request_schema import CreateProductRequestSchema

product = await salable.api.products.post(
    CreateProductRequestSchema(name="My Product", is_active=True)
)
```

## Error Handling

Non-2xx responses raise `ErrorResponseBody`, which extends Kiota's `APIError`. `response_status_code` is the HTTP status.

```python
from salable import ErrorResponseBody

try:
    product = await salable.api.products.by_id("product-id").get()
except ErrorResponseBody as error:
    print(error.response_status_code, error.title)
```

| Status | Meaning |
|--------|---------|
| `400` | Bad request — check your request body |
| `401` | Unauthorised — check your API key |
| `403` | Forbidden — insufficient permissions |
| `404` | Resource not found |
| `429` | Rate limit exceeded. The default client retries this status. |
| `500` | Internal server error |

## Query Parameters

Query parameters use Kiota's `RequestConfiguration`. `limit` is an `int`. `include_archived` is a `bool`.

```python
from kiota_abstractions.base_request_configuration import RequestConfiguration

from salable.sdk.api.products.products_request_builder import ProductsRequestBuilder

query = ProductsRequestBuilder.ProductsRequestBuilderGetQueryParameters(
    limit=20,
    after="cursor-from-previous-page",
)
products = await salable.api.products.get(
    request_configuration=RequestConfiguration(query_parameters=query)
)
```

## Pagination

List responses include `next_cursor` and `previous_cursor`. Pass the previous page's `next_cursor` as `after` to read the next page. Pass `previous_cursor` as `before` to read the previous page.

```python
from kiota_abstractions.base_request_configuration import RequestConfiguration

from salable.sdk.api.products.products_request_builder import ProductsRequestBuilder

page = await salable.api.products.get()
if page is not None and page.next_cursor:
    query = ProductsRequestBuilder.ProductsRequestBuilderGetQueryParameters(
        after=page.next_cursor,
    )
    next_page = await salable.api.products.get(
        request_configuration=RequestConfiguration(query_parameters=query)
    )
```
