portfolio_financials.py
from openfilings import Client
client = Client(api_key="of_...") # or OPENFILINGS_API_KEY
# Resolve holdings, then pull multi-year KPIs in one call
for ticker in ["AAPL", "7203.T", "005930.KS"]:
entity = client.entities.search(ticker=ticker).entity
market = entity.listings[0].market_id
series = client.companies.financials(
ticker=ticker,
market_id=market,
fiscal_year_from=2020,
fiscal_year_to=2024,
line_items=["revenue", "ebitda", "net_income"],
)
for period in series.periods:
print(entity.canonical_key, period.fiscal_year, period.values)webhook_handler.py · FastAPI
import os
from fastapi import Depends, FastAPI
from openfilings import Client
from openfilings.integrations.fastapi import openfilings_webhook_dependency
from openfilings.webhooks import WebhookEvent
app = FastAPI()
client = Client(api_key=os.environ["OPENFILINGS_API_KEY"])
verify = openfilings_webhook_dependency(os.environ["OPENFILINGS_WEBHOOK_SECRET"])
@app.post("/openfilings-webhook")
async def on_filing(event: WebhookEvent = Depends(verify)) -> dict:
if event.event == "filing.discovered":
kpis = client.filings.kpis(event.data["filing_id"])
# ... refresh the screen / research queue ...
print(event.data["ticker"], kpis.canonical.get("revenue"))
return {"ok": True}