Metadata-Version: 2.5
Name: arcobi-sdk
Version: 0.1.0b1
Summary: Fetch, align and export energy-market time-series data (Datahub), with an optional shared credential pool.
Project-URL: Documentation, https://sdk.arcobi.com
Author: Arcobi
License-Expression: LicenseRef-Proprietary
License-File: LICENSE
Keywords: aeso,data,datahub,energy,ercot,ieso,time-series
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.11
Requires-Dist: httpx>=0.25
Requires-Dist: numpy>=1.24
Requires-Dist: pandas<4,>=2.2
Requires-Dist: pydantic>=2.0
Requires-Dist: websockets>=12
Provides-Extra: all
Requires-Dist: fastapi>=0.110; extra == 'all'
Requires-Dist: psycopg[binary,pool]>=3.1; extra == 'all'
Requires-Dist: pyarrow>=14; extra == 'all'
Requires-Dist: pydantic-settings>=2.0; extra == 'all'
Requires-Dist: pyyaml>=6.0; extra == 'all'
Requires-Dist: uvicorn[standard]>=0.27; extra == 'all'
Provides-Extra: excel
Requires-Dist: xlwings>=0.30; extra == 'excel'
Provides-Extra: parquet
Requires-Dist: pyarrow>=14; extra == 'parquet'
Provides-Extra: pool-server
Requires-Dist: fastapi>=0.110; extra == 'pool-server'
Requires-Dist: psycopg[binary,pool]>=3.1; extra == 'pool-server'
Requires-Dist: pydantic-settings>=2.0; extra == 'pool-server'
Requires-Dist: pyyaml>=6.0; extra == 'pool-server'
Requires-Dist: uvicorn[standard]>=0.27; extra == 'pool-server'
Description-Content-Type: text/markdown

# arcobi-sdk

Load energy-market time-series data from Datahub, align it on a time grid, and export it to a
DataFrame, CSV, Parquet or JSON. Optionally share a pool of vendor credentials across many jobs
through a small lease service. It takes you from the API to a clean, aligned frame or file,
ready for the features and models you build on top.

```bash
pip install arcobi-sdk                 # extraction + export + pool client
pip install "arcobi-sdk[parquet]"      # + Parquet export
pip install "arcobi-sdk[pool-server]"  # + the credential-pool service
```

## Quick start

```python
from datetime import datetime, timedelta

from arcobi_sdk import DatahubClient, fetch_streams, to_csv

end = datetime.now()
start = end - timedelta(days=7)

with DatahubClient(username="...", password="...") as client:
    df = fetch_streams(
        client, streams=[1001, 1002], start=start, end=end, names=["demand", "price"]
    )

to_csv(df, "week.csv")
```

`fetch_streams` fetches the streams one after another. To fetch in parallel, share the same
client across threads: it is thread-safe and holds the account's single token. Never open a
second client with the same account, Datahub allows one session per account (see the
[credentials guide](https://sdk.arcobi.com/credentials)).

Credentials can also come from the environment (`DATAHUB_USERNAME` / `DATAHUB_PASSWORD`,
or a pre-issued `DATAHUB_BEARER_TOKEN`), or from a local `.env` file loaded with
`arcobi_sdk.load_env()`. The [credentials guide](https://sdk.arcobi.com/credentials) covers every
option and the live smoke test.

## Sharing credentials across jobs

If several processes share a handful of vendor accounts, run the pool service once and let each
job lease a token. Leases carry a generic **priority level**: `0` is served first, then `1`, then
`2`; the default names are `high`, `normal`, `low` and deployments may rename them.

```python
from arcobi_sdk import DatahubClient, fetch_streams
from arcobi_sdk.pool import PoolClient

pool = PoolClient("http://localhost:8002", api_key="...")
with pool.lease(holder_id="nightly-report", priority="high") as lease:
    with DatahubClient(token_provider=lease.token_provider) as client:
        df = fetch_streams(client, [1001], start, end)
```

The token is refreshed by the service before it expires and the client picks the new one up
mid-extraction. Running the service is described in the
[credential-pool guide](https://sdk.arcobi.com/examples/credential-pool).

## Command line and Excel

Every install also provides a small CLI, handy for scripts, schedulers and spreadsheet macros:

```bash
arcobi-sdk check                                   # authenticate, print token expiry, release
arcobi-sdk fetch --streams 1001,1002 --names demand,price \
    --start 2024-01-01 --end 2024-01-08 --out week.csv
```

Exit codes are stable (0 ok, 2 bad arguments or config, 3 vendor or auth error, 4 no data) and
errors are one `error: ...` line on stderr, so a VBA `Shell` call can act on them. For Excel,
`ArcobiSdk.bas` is a ready-made macro module that runs the CLI and imports the CSV onto a
sheet. It ships inside the installed package:

```bash
python -c "import importlib.resources as r; print(r.files('arcobi_sdk.excel') / 'vba')"
```

`pip install "arcobi-sdk[excel]"` additionally provides xlwings-based functions (`datahub_fetch`,
`datahub_fetch_to_sheet`, `datahub_check`) for spill formulas and `RunPython`. The
[Excel guide](https://sdk.arcobi.com/excel) walks through both paths.

## What is in the box

| Module | Purpose |
|---|---|
| `arcobi_sdk.datahub` | `DatahubClient`, `fetch_streams`, extraction planning, time-grid alignment, gap interpolation |
| `arcobi_sdk.timeutils` | local-to-UTC conversion, timestamp naming |
| `arcobi_sdk.io` | `to_csv`, `to_parquet`, `to_json`, timestamped output folders |
| `arcobi_sdk.pool` | credential-pool client, priorities, wire protocol; server behind an extra |
| `arcobi_sdk.cli` | `arcobi-sdk fetch / check / version` command line |
| `arcobi_sdk.excel` | Excel helpers: value conversion, xlwings UDFs (extra `excel`), VBA module |

## Documentation

**<https://sdk.arcobi.com>** -- the guides referred to above, plus the API reference generated
from these docstrings:

| Guide | |
|---|---|
| [Installation](https://sdk.arcobi.com/installation) | extras, supported versions |
| [Quick start](https://sdk.arcobi.com/quickstart) | first extraction end to end |
| [Credentials](https://sdk.arcobi.com/credentials) | every way to authenticate, and the live smoke test |
| [Credential pool](https://sdk.arcobi.com/examples/credential-pool) | running and deploying the pool service |
| [Excel](https://sdk.arcobi.com/excel) | the VBA module and the xlwings UDFs |

The same material ships in the source distribution on PyPI, under `docs/` and
`deploy/pool-server/`. A wheel install carries the package only.

## Development

```bash
uv sync --all-extras --dev
uv run pytest
uv run ruff check . && uv run ruff format --check .
```

Tests do not need a database or network access. Tests marked `postgres` run only when
`POOL_TEST_DATABASE_URL` points at a reachable PostgreSQL. Tests marked `live` call the real
Datahub API and run only with `DATAHUB_LIVE=1`, credentials, and `DATAHUB_TEST_STREAM_ID`
set (`uv run pytest -m live`).
