Lumirank API docs

Visibility in pandas

Load your daily visibility for each engine into a pandas table, and calculate correct totals.

Each report row is a JSON object with 1 key per column, so the rows load straight into a pandas DataFrame.

import os

import pandas as pd
import requests

API = "https://api.lumirank.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['LUMIRANK_API_KEY']}"}

resp = requests.get(f"{API}/reports/visibility", headers=HEADERS,
                    params={"dimensions": "day,engine", "limit": 10000}, timeout=60)
resp.raise_for_status()
df = pd.DataFrame(resp.json()["data"])

# 1 row per day, 1 column per engine, in percent, as the dashboard shows it.
daily = df.pivot(index="day", columns="engine", values="visibility") * 100
print(daily.round(1))

# Totals per engine: add up the counts, then divide. Never average the daily rates.
totals = df.groupby("engine")[["mentions", "answers"]].sum()
totals["visibility"] = totals["mentions"] / totals["answers"]
print(totals)

With no dates, the report covers the last 30 days. For another range, add start_date and end_date. 1 request can cover up to 90 days.

To compare your brand with its competitors, use /v1/reports/brands in the same way, and pivot on competitor_name.