Get PSX stock prices in Python
The PSX Lens API answers plain HTTPS requests with JSON, so Python needs nothing beyond requests. Market data needs no key.
Latest quote
import requests
q = requests.get("https://api.psxlens.com/v1/quotes/OGDC", timeout=20).json()
print(q["symbol"], q["price"], q["change_pct"], q["timestamp"])Prices are delayed and published once a day after the 15:30 PKT close, so polling more than every few minutes gains nothing.
Daily price history into pandas
import pandas as pd, requests
rows = requests.get("https://api.psxlens.com/v1/prices/OGDC", params={"limit": 250}, timeout=30).json()["data"]
df = pd.DataFrame(rows).set_index("date")[["open", "high", "low", "close", "volume", "adjusted_close"]]
print(df.tail())adjusted_close is back-adjusted for ex-dividend, bonus and rights events since 9 November 2026; use it for returns.
Screen the market
params = {"inside_kse100": "true", "dividend_yield_min": 8, "beta_max": 1, "sort": "yield", "limit": 20}
res = requests.get("https://api.psxlens.com/v1/screener", params=params, timeout=30).json()
for s in res["matches"]:
print(s["symbol"], s["dividend_yield"], s["pe_ttm"], s["beta_1y"])Use a key for higher limits
Without a key you get 120 requests a minute per address. A free key from the developer dashboard raises that to 600 and is needed for portfolio data.
headers = {"authorization": "Bearer pl_live_..."}
me = requests.get("https://api.psxlens.com/v1/me/portfolios", headers=headers, timeout=20).json()