Export a company
Download every datapoint a company serves as CSV or Parquet.
GET /v1/companies/{symbol}/export returns every datapoint the API serves for
one company (its KPIs and statement lines, all periods) in one file, one row per
datapoint. The rows are the values the single reads return, with the cited
source on each. Export is available on Starter and above.
Columns: ticker, series_key, series_kind, label, fiscal_period,
calendar_period, period_end, period_kind, value, unit, provisional,
src_id, source_url. provisional is true for an earnings-day value that no
10-Q or 10-K states yet.
import csv
import io
import os
import pathlib
import time
import httpx
BASE_URL = os.environ.get("SIGNALS_BASE_URL", "https://api.signals.ai")
API_KEY = os.environ["SIGNALS_API_KEY"]
def get(client, url, **kwargs):
"""GET with the rate limit honoured: a 429 waits for its Retry-After."""
for _attempt in range(6):
r = client.get(url, **kwargs)
if r.status_code != 429:
r.raise_for_status()
return r
time.sleep(float(r.headers.get("Retry-After", "1")))
r.raise_for_status()
return r
def export_company(client, ticker, *, fmt="csv", out_dir="."):
"""Save the company's export and return the file's path."""
r = get(client, f"/v1/companies/{ticker}/export", params={"format": fmt})
path = pathlib.Path(out_dir) / f"{ticker}.{fmt}"
path.write_bytes(r.content)
return path
def read_csv_rows(path):
return list(csv.DictReader(io.StringIO(pathlib.Path(path).read_text())))
if __name__ == "__main__":
headers = {"Authorization": f"Bearer {API_KEY}"}
with httpx.Client(base_url=BASE_URL, headers=headers, timeout=60) as client:
path = export_company(client, "UBER")
rows = read_csv_rows(path)
print(f"{len(rows)} datapoints -> {path}")
for row in rows[:5]:
print(row["series_key"], row["fiscal_period"], row["value"], row["source_url"])For Parquet pass fmt="parquet" and read the file with pyarrow.parquet or
pandas. First-reported history (history=first_reported) is not served yet and
returns 422 with unavailable: first_reported_history.