Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

psxdata — Python Library for Pakistan Stock Exchange (PSX) Data

CI PyPI Documentation Python License: MIT

Full documentation at psxdata.mintlify.app

Deprecated: ReadTheDocs hosting at psxdata.readthedocs.io is no longer the primary documentation source and may be removed in a future release.

psxdata is a Python library for downloading Pakistan Stock Exchange (PSX) data — historical OHLCV prices, real-time quotes, KSE-100 index constituents, sector summaries, fundamentals, debt market instruments, and margin-eligible stocks. Free, open-source, and actively maintained.

Alpha release note

0.1.0a1 — Core scraping, caching, and public API are complete. The FastAPI REST layer has moved to mtauha/psxdata-api. APIs may change before 1.0.


Installation

pip install psxdata

Requires Python 3.11+.


Quick Start

import psxdata

# Historical OHLCV data
df = psxdata.stocks("ENGRO", start="2024-01-01", end="2024-12-31")

# All listed tickers
all_tickers = psxdata.tickers()

# KSE-100 index constituents
kse100 = psxdata.indices("KSE100")

# Live quote
q = psxdata.quote("LUCK")

# Sector summary
sectors = psxdata.sectors()

# Debt market instruments
debt = psxdata.debt_market()

# Margin-eligible stocks
scrips = psxdata.eligible_scrips()

API Reference

Function Description
psxdata.stocks(symbol, start, end) Historical OHLCV DataFrame for a ticker
psxdata.tickers() All listed tickers (1000+)
psxdata.symbols() Symbol/sector/name metadata, optionally filtered
psxdata.quote(symbol) Live quote row for a ticker
psxdata.indices(name) Constituents of a named index (e.g."KSE100")
psxdata.sectors() Sector aggregates DataFrame (37 sectors)
psxdata.fundamentals(symbol) Financial reports for a ticker
psxdata.debt_market() Debt market instruments (TFCs, Sukuks, etc.)
psxdata.eligible_scrips() Margin trading eligible stocks

Why psxdata

Existing solutions for PSX data tend to hardcode date formats and column positions that break silently when PSX changes its HTML. psxdata is designed differently:

  • Dynamic column extraction from <th> tags — survives column reordering
  • Multi-format date parsing with fuzzy fallback via dateutil
  • Exponential backoff retries — 3 attempts, 1s/2s delays
  • Disk cache (~/.psxdata/cache/) — historical data cached forever, live data for 15 min
  • Data validation — OHLC constraint checks, duplicate/future date detection

REST API

A FastAPI REST service wrapping this library now lives in a standalone repository: mtauha/psxdata-api.

It exposes the same data as this library over HTTP (GET /stocks, GET /indices/{name}, GET /sectors, etc.), installs psxdata from PyPI, and ships its own Docker image (mtauha/psxdata-api on Docker Hub) and CI/CD pipeline. See that repo's README for endpoints, request/response formats, and Docker run instructions.


Development Status

See the roadmap issue for the full phase breakdown.

  • ✅ Phase 0 — PSX endpoint research and HTML fixture capture
  • ✅ Phase 0.5 — Repository setup, CI/CD, community files
  • ✅ Phase 2 — Core engineering (BaseScraper, parsers, cache, utils)
  • ✅ Phase 3 — Scrapers (historical, real-time, indices, sectors, fundamentals, screener, debt, eligible scrips)
  • ✅ Phase 3 API — Public Python package interface
  • ✅ Phase 4 — FastAPI REST layer (now at mtauha/psxdata-api)
  • ✅ Phase 5 — Full test suite (API layer tests pending)
  • ✅ Phase 6 — Packaging & PyPI publish
  • ✅ Phase 7 — Documentation

Contributing

Contributions are welcome. See CONTRIBUTING.md and open an issue before starting non-trivial work.


Architecture

See ARCHITECTURE.md for the component diagram, data flow, and design decisions.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

psxdata-0.1.0a5.tar.gz (27.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

psxdata-0.1.0a5-py3-none-any.whl (34.3 kB view details)

Uploaded Python 3

File details

Details for the file psxdata-0.1.0a5.tar.gz.

File metadata

  • Download URL: psxdata-0.1.0a5.tar.gz
  • Upload date:
  • Size: 27.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for psxdata-0.1.0a5.tar.gz
Algorithm Hash digest
SHA256 b37f22b13638237193dfc3c0712cfc3277d56e803ed75c8a0b6897036142be0a
MD5 66fe3fea5f08b24c132b3153be615bba
BLAKE2b-256 8d80de104fdff69cde4332e906fc020408e1b326cbe86ff5e9bb5437031f2414

See more details on using hashes here.

Provenance

The following attestation bundles were made for psxdata-0.1.0a5.tar.gz:

Publisher: publish.yml on mtauha/psxdata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file psxdata-0.1.0a5-py3-none-any.whl.

File metadata

  • Download URL: psxdata-0.1.0a5-py3-none-any.whl
  • Upload date:
  • Size: 34.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for psxdata-0.1.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 78a6fec3c7a949a14246828ef46f8716345e172d908637c270bf3cc1271eeabe
MD5 3ef3ac85dda30cd0044e823f735a4692
BLAKE2b-256 1d81f1624560edb448d3845a93e658fa339036c97e54e24e94defde9d6427ede

See more details on using hashes here.

Provenance

The following attestation bundles were made for psxdata-0.1.0a5-py3-none-any.whl:

Publisher: publish.yml on mtauha/psxdata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

1.1.0

2 files

1.0.0

2 files

This release

0.1.0a5 This release

2 files

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