Metadata-Version: 2.5
Name: goldprice-dev
Version: 0.2.0
Summary: Python client for the goldprice.dev gold and precious metals price API
Project-URL: Homepage, https://goldprice.dev/docs
Project-URL: Source, https://github.com/nusantara-ventures
Project-URL: Documentation, https://goldprice.dev/docs
Author-email: "Nusantara Ventures, LLC" <hello@goldprice.dev>
License-Expression: MIT
License-File: LICENSE
Keywords: bullion,gold price,goldprice,precious metals,silver,xau
Classifier: License :: OSI Approved :: MIT License
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: Programming Language :: Python :: 3.14
Classifier: Typing :: Typed
Requires-Python: >=3.10
Requires-Dist: httpx>=0.27
Requires-Dist: pydantic>=2.5
Description-Content-Type: text/markdown

# goldprice-dev

Python client for the [goldprice.dev](https://goldprice.dev/docs) gold and precious metals price API.
Typed responses (pydantic, prices as `Decimal`), API-key auth, and the API's error envelope raised as exceptions.

```sh
pip install goldprice-dev
```

Python 3.10 or newer. Depends on `httpx` and `pydantic`.

## Quick start

```python
import os
from goldprice_dev import GoldpriceClient

client = GoldpriceClient(os.environ["GOLDPRICE_API_KEY"])

spot = client.spot("XAU-USD-SPOT")
print(spot.price, spot.is_stale)

grams = client.carat("USD")
print(grams.price_gram_24k)
```

With no argument the client reads `GOLDPRICE_API_KEY` from the environment. Without a key, requests go out
anonymously and the API serves them on the free keyless terms (prices 15 minutes late). Use the client as a
context manager, or call `close()`, to release the connection pool.

Prices arrive as decimal strings on the wire and are returned as `decimal.Decimal`. Check `is_stale` and the
timestamps before describing a price as live.

## Methods

| Method | Endpoint |
|---|---|
| `prices(symbol=None, include=None)` | `GET /v1/prices` |
| `spot(symbol="XAU-USD-SPOT", include=None)` | `GET /v1/spot/{symbol}` |
| `history(symbol, from_date, to_date, interval=None, limit=None)` | `GET /v1/prices/history` |
| `convert(from_symbol, to_symbol, amount=None, unit=None)` | `GET /v1/convert` |
| `carat(currency="USD")` | `GET /v1/carat` |
| `bars(symbol, from_date, to_date, interval=None, limit=None, cursor=None)` | `GET /v1/bars` |
| `latest_bar(symbol, interval=None)` | `GET /v1/bars/latest` |
| `ratios(pair, from_date, to_date, limit=None, cursor=None)` | `GET /v1/ratios` |
| `latest_ratio(pair)` | `GET /v1/ratios/latest` |
| `usage()` | `GET /v1/account/usage` |

For any other endpoint: `client.request("GET", "/v1/physical", params={...})` returns the decoded JSON.

## Upgrading from 0.1.0

`Goldprice`, `client.prices.spot(...)`, `client.convert.carat(...)` and the old error names still work. The async client, retries and `ResponseMeta` were removed. See [CHANGELOG.md](CHANGELOG.md) for each change and its replacement.

## Errors

Every non-2xx response raises `APIError` with `status`, `code`, `message`, `retry_after` (seconds, if sent),
`request_id` and the raw `body` (some errors carry extra fields such as `hint`). Subclasses:
`AuthenticationError` (401), `PermissionDeniedError` (403), `NotFoundError` (404), `RateLimitError` (429).
Transport failures raise `APIConnectionError`; a 2xx body that does not fit the models raises `ResponseValidationError`. All inherit from `GoldpriceError`. There are no automatic retries.

```python
import time
from goldprice_dev import RateLimitError

try:
    client.spot()
except RateLimitError as exc:
    time.sleep(exc.retry_after or 30)
```

Prices are indicative and not settlement quotes.

## Development

```sh
uv run --with-editable . --with pytest pytest          # unit tests
GOLDPRICE_API_KEY=... uv run --with-editable . python scripts/smoke.py   # live smoke test
uv run --no-project python scripts/generate.py          # regenerate models from the live OpenAPI spec
uv build
```
