Metadata-Version: 2.5
Name: bricktrack
Version: 0.1.0
Summary: Official Python SDK for the BrickTrack LEGO price tracking API.
Project-URL: Homepage, https://www.bricktrack.dev
Project-URL: Documentation, https://www.bricktrack.dev/docs
Project-URL: Repository, https://github.com/bricktrackdev/bricktrack-python
Project-URL: Issues, https://github.com/bricktrackdev/bricktrack-python/issues
Author-email: BrickTrack <contact@bricktrack.dev>
License-Expression: MIT
License-File: LICENSE
Keywords: api,bricktrack,lego,lego-sets,price-history,price-tracking,sdk
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: httpx<1,>=0.27
Provides-Extra: dev
Requires-Dist: build<2,>=1.2; extra == 'dev'
Requires-Dist: mypy>=1.13; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.24; extra == 'dev'
Requires-Dist: pytest>=8.3; extra == 'dev'
Requires-Dist: ruff<1,>=0.8; extra == 'dev'
Description-Content-Type: text/markdown

# BrickTrack Python SDK

The official Python SDK for the [BrickTrack](https://www.bricktrack.dev) LEGO price tracking API.

Track LEGO set prices with a scheduled watchlist, price history and alerts.

The SDK exposes **9 typed methods**, one per documented endpoint, with blocking and `asyncio` clients built on [HTTPX](https://www.python-httpx.org/), plus a generic `request()`.

## Requirements

- Python 3.11 or newer

## Installation

```sh
pip install bricktrack
```

## Get your API key

[Sign up for BrickTrack](https://www.bricktrack.dev/signup) or sign in, then copy your API key from the [dashboard](https://www.bricktrack.dev/app). The client reads the `BRICKTRACK_API_KEY` environment variable when no key is passed.

## Quick start

```python
import os

from bricktrack import BrickTrackClient

with BrickTrackClient(os.environ["BRICKTRACK_API_KEY"]) as client:
    response = client.search_sets(query="millennium falcon")
    print(response.data)
```

Keyword arguments mirror the [API reference](https://www.bricktrack.dev/docs). Python keywords get a trailing underscore (`from_=`), and the wire name is used on the request.

## Async I/O

```python
import asyncio

from bricktrack import AsyncBrickTrackClient


async def main() -> None:
    async with AsyncBrickTrackClient() as client:
        response = await client.search_sets(query="millennium falcon")
        print(response.data)


asyncio.run(main())
```

## HTTP methods

Each method uses the HTTP verb of its endpoint. `GET` and `DELETE` send parameters in the query string; `POST` and `PATCH` send them as a JSON body, except `wait` on `/products/{id}/check`, which stays in the query string. `None` values are never sent, so `update_product(target_price=None)` leaves the target price as it is: `clear_target_price(id=...)` removes it (it sends `{"target_price": null}`).

```python
client.clear_target_price(id="p1")
```

`None` values are omitted, `False` and `0` are sent, and sequences repeat the parameter name.

## Any endpoint

```python
response = client.request("GET", "/account")
```

## Errors

```python
from bricktrack import BrickTrackAPIError

try:
    client.search_sets(query="millennium falcon")
except BrickTrackAPIError as error:
    print(error.status, error.error_code, error, error.response_body)
```

| Error | When |
| --- | --- |
| `BrickTrackConfigurationError` | Missing API key, invalid options, unsupported method, closed client. |
| `BrickTrackSerializationError` | A required parameter is missing or a value can't be sent. |
| `BrickTrackTransportError` | Network failure or timeout. |
| `BrickTrackAPIError` | Non-2xx status (`status`, `error_message`, `error_code`, `response_body`, `raw_response`). `error_code` is the API's `error.code`, such as `insufficient_credits` or `product_limit` (`None` when the body has none). |
| `BrickTrackResponseDecodingError` | A success response could not be decoded. |

All of them extend `BrickTrackError`.

## Retries

Requests are retried up to 3 times after a network error, a `408`, `500`, `502`, `503` or `504`. Other statuses, such as `400`, `401`, `402`, `404` or `429`, and client-side timeouts are not retried: the API's rate limits last until the hour (or the day) is over, and on the free plan every retry would count as a request. The delay starts at 1 second and grows 1.5× per retry (capped at 30 seconds); a `Retry-After` header wins.

```python
client = BrickTrackClient(max_retries=5, retry_delay=0.5)

# or for one request
client.search_sets(query="millennium falcon", request_options=RequestOptions(max_retries=0))
```

## Batch requests

`batch()` runs a function per item on 10 threads (`concurrency`) and returns one `BatchResult` per item, in input order. A failing item never stops the others. `AsyncBrickTrackClient.batch()` does the same with `asyncio`.

```python
inputs = ["millennium falcon", "titanic", "botanical"]
results = client.batch(inputs, lambda query: client.search_sets(query=query), concurrency=5)

for result in results:
    if result.ok:
        print(result.value.data)
    else:
        print(inputs[result.index], result.error)
```

| Constant | Default | Description |
| --- | --- | --- |
| `DEFAULT_CONCURRENCY` | `10` | Tasks run at the same time by batch |
| `DEFAULT_TIMEOUT` | `120.0` | Request timeout (seconds) |
| `MAX_RETRIES` | `3` | Retry attempts after a network error, a 408/5xx |
| `RETRY_BACKOFF_FACTOR` | `1.5` | Exponential backoff multiplier |
| `DEFAULT_RETRY_DELAY` | `1.0` | Delay before the first retry (seconds) |

## Timeouts and custom HTTPX clients

```python
import httpx

from bricktrack import BrickTrackClient, RequestOptions

client = BrickTrackClient(timeout=60)  # seconds, default 120, None disables
client.search_sets(query="millennium falcon", request_options=RequestOptions(timeout=30))

# Bring your own HTTPX client (proxies, limits, event hooks…). You keep ownership of it.
http_client = httpx.Client(proxy="http://localhost:8080")
client = BrickTrackClient(http_client=http_client)
```

## Endpoints

9 methods, generated from the [OpenAPI document](https://www.bricktrack.dev/openapi.json), plus `clear_target_price()`.

| Method | HTTP | Description |
| --- | --- | --- |
| `check_product()` | POST `/products/{id}/check` | Asks for a check right away (1 credit), at most once per 5 minutes; earlier calls return the product unchanged. A paused product has to be… |
| `clear_target_price()` | PATCH `/products/{id}` | Removes the target price: sends `{"target_price": null}`. |
| `delete_product()` | DELETE `/products/{id}` | Removes the product and its price history. |
| `get_account()` | GET `/account` | Your plan, the credits left (monthly allowance and packs), how many products you track and the credits they use per month, the credits each… |
| `get_product()` | GET `/products/{id}` | The product's latest state and every price read of the period, oldest first. The history covers every read of this set number on this marke… |
| `get_set_history()` | GET `/history` | Every price BrickTrack read for a set number on a marketplace over the period, whoever tracks it, oldest first, with the lowest, highest an… |
| `list_products()` | GET `/products` | Your watchlist, newest first, with each product's latest state and its recent prices (trend). Filter with set_number (and marketplace) to k… |
| `search_sets()` | GET `/search` | LEGO sets matching a name, a theme or the start of a set number (up to 20, the biggest first), from BrickTrack's catalog of official sets,… |
| `track_product()` | POST `/products` | Adds a set number or a LEGO link to your watchlist. The first check runs in the background within seconds (checking is true until then): po… |
| `update_product()` | PATCH `/products/{id}` | Target price, drop alerts, check interval, or pause. Send only what changes. On the free plan, alerts (price drop, back in stock, target pr… |

## All BrickTrack SDKs

| SDK | Package | Install |
| --- | --- | --- |
| Node.js | [`@bricktrack/sdk`](https://www.npmjs.com/package/@bricktrack/sdk) | `npm install @bricktrack/sdk` |
| Python | [`bricktrack`](https://pypi.org/project/bricktrack/) | `pip install bricktrack` |
| Go | [`bricktrack-go`](https://pkg.go.dev/github.com/bricktrackdev/bricktrack-go) | `go get github.com/bricktrackdev/bricktrack-go` |
| .NET | [`BrickTrack`](https://www.nuget.org/packages/BrickTrack) | `dotnet add package BrickTrack` |
| Ruby | [`bricktrack`](https://rubygems.org/gems/bricktrack) | `gem install bricktrack` |
| PHP | [`bricktrack/sdk`](https://packagist.org/packages/bricktrack/sdk) | `composer require bricktrack/sdk` |
| Java | [`bricktrack-java`](https://github.com/bricktrackdev/bricktrack-java) | build from source, see its README |
| CLI | [`@bricktrack/cli`](https://www.npmjs.com/package/@bricktrack/cli) | `npm install -g @bricktrack/cli` |
| MCP server | [`@bricktrack/mcp`](https://www.npmjs.com/package/@bricktrack/mcp) | `npx -y @bricktrack/mcp` |

## Trademarks

LEGO® is a trademark of the LEGO Group of companies which does not sponsor, authorize or endorse this software.

## License

MIT — see [LICENSE](LICENSE).
