Reading Datasets from a running instance, synchronously: for a notebook, or a script.
from cointoss.client import datasets, frame
frame("bars", start="2026-01-01", end="2026-03-31", instruments=["crypto.native.btc"])
frame(name, **params) is cointoss.datasets.load: one Dataset over JSON-RPC as a pandas
DataFrame with its column types applied. datasets() is the datasets node's answer, each
Dataset's name, description, columns and params JSON Schema. Both go through the API, never
cointoss.db (ADR-0010), so an owned Dataset holds the Portfolios of whoever the token names.
The server and token are resolved as the CLI's portfolio commands resolve them
(cointoss.cli.resolve_endpoint): $COINTOSS_URL, else the local instance's woodglue.yaml;
$COINTOSS_TOKEN, else the local instance's admin token when calling it, else what wgl login
stored. A notebook kernel has no other credential: the Delegated Token woodglue sends JupyterLab
arrives in request headers the kernel never sees. Client takes all three explicitly.
Each call runs on a fresh event loop in a worker thread, since a Jupyter kernel already runs
a loop, in which asyncio.run refuses to start another. Needs pandas, from the notebook or
ui extra.
Client
A server and the token to call it with, resolved once.
Any of url, token and data_dir left out is resolved as the module docstring says.
Source code in src/cointoss/client.py
| class Client:
"""A server and the token to call it with, resolved once.
Any of `url`, `token` and `data_dir` left out is resolved as the module docstring says.
"""
endpoint: Endpoint
namespace: str
def __init__(
self,
url: str | None = None,
token: str | None = None,
*,
data_dir: Path | None = None,
namespace: str = DEFAULT_NAMESPACE,
) -> None:
home = resolve_data_dir(data_dir).expanduser().absolute()
self.endpoint = resolve_endpoint(home, url, token)
self.namespace = namespace
def datasets(self) -> list[dict[str, Any]]:
"""Every Dataset: its name, description, columns and params JSON Schema."""
async def call(client: WoodglueClient) -> list[dict[str, Any]]:
return await client.call(f"{self.namespace}:datasets")
return _run(call, self.endpoint)
def frame(self, name: str, /, **params: Any) -> pd.DataFrame:
"""Dataset `name` read with `params`, as a typed DataFrame (`cointoss.datasets.load`).
A `date` param may be given as a `datetime.date`; it is sent as `YYYY-MM-DD`.
"""
sent = {k: v.isoformat() if isinstance(v, dt.date) else v for k, v in params.items()}
async def call(client: WoodglueClient) -> pd.DataFrame:
return await load(client, name, namespace=self.namespace, **sent)
return _run(call, self.endpoint)
|
datasets()
Every Dataset: its name, description, columns and params JSON Schema.
Source code in src/cointoss/client.py
| def datasets(self) -> list[dict[str, Any]]:
"""Every Dataset: its name, description, columns and params JSON Schema."""
async def call(client: WoodglueClient) -> list[dict[str, Any]]:
return await client.call(f"{self.namespace}:datasets")
return _run(call, self.endpoint)
|
frame(name, /, **params)
Dataset name read with params, as a typed DataFrame (cointoss.datasets.load).
A date param may be given as a datetime.date; it is sent as YYYY-MM-DD.
Source code in src/cointoss/client.py
| def frame(self, name: str, /, **params: Any) -> pd.DataFrame:
"""Dataset `name` read with `params`, as a typed DataFrame (`cointoss.datasets.load`).
A `date` param may be given as a `datetime.date`; it is sent as `YYYY-MM-DD`.
"""
sent = {k: v.isoformat() if isinstance(v, dt.date) else v for k, v in params.items()}
async def call(client: WoodglueClient) -> pd.DataFrame:
return await load(client, name, namespace=self.namespace, **sent)
return _run(call, self.endpoint)
|
datasets()
Every Dataset of the instance the environment names; see Client.datasets.
Source code in src/cointoss/client.py
| def datasets() -> list[dict[str, Any]]:
"""Every Dataset of the instance the environment names; see `Client.datasets`."""
return Client().datasets()
|
frame(name, /, **params)
Dataset name from the instance the environment names; see Client.frame.
Source code in src/cointoss/client.py
| def frame(name: str, /, **params: Any) -> pd.DataFrame:
"""Dataset `name` from the instance the environment names; see `Client.frame`."""
return Client().frame(name, **params)
|