Skip to main content

cmoney-datahub

Thin Python client for the CMoney DataHub delivery API. It mirrors the portal's pull path (catalog → tree → presign → parquet) and returns pandas DataFrames. Downloads are S3-direct (the API only signs URLs), so large pulls are not bound by any server request timeout.

Install

pip install cmoney-datahub

Optional extras: polars (engine="polars"), duckdb (.sql()), progress (tqdm bar), or everything — pip install "cmoney-datahub[all]".

The package is a thin client; you still need a CMoney DataHub API key to pull data — pass it as Client("dpk_...") or set CMONEY_DATAHUB_KEY. Contact your account manager for a key.

Alternative: install from the portal (no PyPI)

The key must go in an HTTP header, so download the wheel then install it:

curl -fsSL -H "X-API-Key: dpk_..." \
  "https://datahub.cmoney.tw/api/skill?format=wheel" -o cmoney_datahub.whl
pip install --force-reinstall cmoney_datahub.whl

In Jupyter: run the curl in a ! cell, then %pip install --force-reinstall <wheel> and restart the kernel. For local development: pip install -e ./sdk.

Quickstart

from cmoney_datahub import Client

c = Client("dpk_...")            # or set CMONEY_DATAHUB_KEY and call Client()
c.datasets()                     # datasets this key is entitled to (code · slug · title · category)

df = c.get("market-vote", start="2026-06", end="2026-06")
df.head()

The dataset id accepts the client-facing slug (stock-pageviews) or the internal code (a3-stock-pv) interchangeably.

The surface model — one get() = one surface

A dataset exposes one or more surfaces. A surface is either a bare panel (e.g. app-forum) or a panel/grain pair (e.g. app-forum/daily); the grain drives the column set. Each get() returns exactly one surface's schema — if a multi-surface dataset is under-specified, it raises AmbiguousSurfaceError rather than silently stacking mismatched columns.

# grid dataset (panel × grain)
df = c.get("stock-pageviews", panel="app-forum", grain="daily",
           start="2026-01", end="2026-03")
# equivalently: surface="app-forum/daily"

# record / list dataset
df = c.get("paper-trading", surface="deal-record", start="2026-01", end="2026-03")

# single-surface dataset — nothing to pass
df = c.get("market-vote", start="2026-06", end="2026-06")

Discover surfaces with c.surfaces(code); inspect one with c.schema(code, panel=..., grain=...).

Core methods

Method Purpose
Client(key=None, api=...) Connect. key falls back to $CMONEY_DATAHUB_KEY.
.datasets() Entitled datasets (drops not-yet-uploaded ones).
.surfaces(code) Pullable surface list for a dataset.
.schema(code, *, surface=|panel=+grain=) One surface's columns + types.
.coverage(code, *, surface=|panel=+grain=) {from, to, months} coverage.
.estimate(code, start, end, *, surface=|panel=+grain=) {files, bytes} without downloading.
.get(code, start, end, *, surface=|panel=+grain=, tickers=, columns=, version=, workers=4, engine="pandas", cache=True, progress=) Pull one surface → DataFrame.
.get_all(code, start, end, ...) Every surface at once → {surface: DataFrame}.
.iter_get(code, ..., columns=, version=, cache=True) Stream one DataFrame per file (bounded memory).
.download(code, dest, ..., workers=4, cache=True) Write parquet files to disk (no pandas), keeping the S3 layout.
.sql(query, code=None, *, surface=|panel=+grain=, start, end, table="data") DuckDB over the cached slice → pandas.
.versions(code) Available versions (months) → pass to version=.
.usage() Trial quota vs cap.

Working with large datasets

A single get() concatenates every file into one DataFrame — fine for most slices, but a wide multi-year pull (e.g. stock-pageviews ≈ 1 GB / 144M rows) can exhaust memory. Two escape hatches:

# stream one month at a time — memory stays bounded
for df in c.iter_get("stock-pageviews", panel="app-forum", grain="daily",
                     start="2024-01", end="2026-06"):
    process(df)

# or land parquet on disk and query with DuckDB / Polars (no pandas)
paths = c.download("stock-pageviews", "./pv", panel="app-forum", grain="daily")
import duckdb
duckdb.sql("select * from read_parquet('pv/**/*.parquet')")

# or let the SDK stage + query it for you (auto-caches; exposes the slice as view `data`)
top = c.sql("select stockid, sum(pv) pv from data group by 1 order by pv desc limit 10",
            code="stock-pageviews", panel="app-forum", grain="daily",
            start="2026-01", end="2026-03")

get_all() pulls every surface at once, and engine= changes the return type:

panels = c.get_all("stock-pageviews", start="2026-01", end="2026-03")   # {surface: DataFrame}
df = c.get("market-vote", start="2026-06", end="2026-06", engine="polars")  # polars.DataFrame

Behaviour notes

  • Ticker filter is client-side. tickers=["2330"] filters after download; the server never receives symbols (PIT-safe, matches the flat-file delivery model).
  • Column projection. columns=["stockid", "pv"] reads only those columns from parquet — less memory and parse time on wide datasets.
  • sha-verified local cache (on by default). Files are cached by content hash, so repeat pulls read from disk and cost no quota. Disable with cache=False; relocate with cache_dir= or $CMONEY_DATAHUB_CACHE.
  • Every download is verified (0.2.2). Each file is checked against the catalog's sha256 (or its byte size when no sha256 is published). A mismatch is re-downloaded once more with a fresh URL; if it still does not match, IntegrityError is raised and the bytes are never returned or cached.
  • Expired download links are renewed automatically (0.2.2). Signed links live 15 minutes; when the storage refuses an expired one (HTTP 403 on S3, 400 on GCS) the client requests a new link for that file and continues.
  • Daily files count toward their month (0.2.2). Datasets with daily releases list versions like "2026-11-10"; start= / end= given as months include those days (end="2026-11" covers 2026-11-01 … 2026-11-30).
  • Quota is checked before downloading — a request that won't fit the trial cap raises QuotaError up front (the server 403 is the hard backstop).
  • Window / entitlement are enforced server-side. An over-range request warns (or raises with strict=True) and returns the available intersection.
  • Every call reports. get / download / iter_get print a one-line receipt — file counts (new · cached · failed), bytes pulled this call, live quota (used/cap/left), and cumulative c.session_bytes. get() also attaches df.attrs["cmoney"] = {files, downloaded, cached, failures, bytes, bytes_new, session_bytes}. Silence with progress=False.

Errors

All subclass DataHubError and carry a stable e.code + e.status (HTTP), so you can branch by class or by code:

Class .code HTTP
AuthError unauthorized 401
EntitlementError not_entitled 403
QuotaError quota_exceeded (+ .used_gb / .cap_gb) 403
RateLimitError rate_limited 429
NotFoundError not_found 404
IntegrityError integrity_mismatch — (downloaded bytes failed sha256/size check twice)
AmbiguousSurfaceError ambiguous_surface (+ .dataset / .options) —
from cmoney_datahub import DataHubError
try:
    df = c.get("stock-pageviews", panel="app-forum", grain="daily", start="2026-01", end="2026-03")
except DataHubError as e:
    print(e.code, e.status, e)   # e.g. quota_exceeded 403 ...

Metadata

Release files for cmoney-datahub 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cmoney-datahub 0.2.2
File Size Uploaded Provenance Actions
cmoney_datahub-0.2.2.tar.gz 18.6 kB Without provenance Details for cmoney_datahub-0.2.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cmoney-datahub 0.2.2
File Interpreter ABI Platform Actions
cmoney_datahub-0.2.2-py3-none-any.whl Python 3 none any Details for cmoney_datahub-0.2.2-py3-none-any.whl

Total release size: 39.7 kB

Release files / cmoney_datahub-0.2.2.tar.gz

Download URL cmoney_datahub-0.2.2.tar.gz
Size 18.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7dea9a9d93a762a3f0a714475ac116353d996766c4361ad392b02b2ccf6dec34
BLAKE2b-256 checksum
How to use checksums
0aa87c76542e7bfe2b28a698471b8a12de4fc2b59d93022e8f378d6c15f0223a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Release files / cmoney_datahub-0.2.2-py3-none-any.whl

Download URL cmoney_datahub-0.2.2-py3-none-any.whl
Size 21.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6931a8f041b669a8a15dfa09a7e60e1792724aefb223b84d7ff3adacfe98c1e2
BLAKE2b-256 checksum
How to use checksums
e1b6dfe50f513ea86cda0479399ed4ba465acc7f0c25376eb6b46b12f4e45ef4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.10

Security for cmoney-datahub 0.2.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page