Python library and REST API for Pakistan Stock Exchange (PSX) data
Project description
psxdata — Python Library for Pakistan Stock Exchange (PSX) Data
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 and full documentation are in progress. 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.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
Planned REST API
The FastAPI layer is planned for Phase 4.
| Endpoint | Description |
|---|---|
GET /health |
Health check |
GET /stocks |
All tickers |
GET /stocks/{symbol}/historical?start=&end= |
Historical OHLCV |
GET /stocks/{symbol}/quote |
Real-time quote |
GET /stocks/{symbol}/fundamentals |
Fundamentals |
GET /indices/{name} |
Index constituents |
GET /sectors |
Sector aggregates |
GET /debt-market |
Debt instruments |
GET /eligible-scrips |
Margin eligible stocks |
All responses: {"data": ..., "meta": {"timestamp": "...", "cached": bool}}
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
- 🔲 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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file psxdata-0.1.0a2.tar.gz.
File metadata
- Download URL: psxdata-0.1.0a2.tar.gz
- Upload date:
- Size: 26.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
67c35de96ff147bae68ce590c0d4a5c05be77832663025056a9ebf2f890f861f
|
|
| MD5 |
3d918b9156dca1c16dafa709c89771d1
|
|
| BLAKE2b-256 |
462526f65cc24328e53afeace5698fc68ce2a69c952cb9de4ee46c2899443750
|
Provenance
The following attestation bundles were made for psxdata-0.1.0a2.tar.gz:
Publisher:
publish.yml on mtauha/psxdata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psxdata-0.1.0a2.tar.gz -
Subject digest:
67c35de96ff147bae68ce590c0d4a5c05be77832663025056a9ebf2f890f861f - Sigstore transparency entry: 1340896268
- Sigstore integration time:
-
Permalink:
mtauha/psxdata@5e570bf266db17d4543ee078ec715d4086b2626a -
Branch / Tag:
refs/tags/v0.1.0a2 - Owner: https://github.com/mtauha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5e570bf266db17d4543ee078ec715d4086b2626a -
Trigger Event:
push
-
Statement type:
File details
Details for the file psxdata-0.1.0a2-py3-none-any.whl.
File metadata
- Download URL: psxdata-0.1.0a2-py3-none-any.whl
- Upload date:
- Size: 33.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cea671f5146e2463b24faec4d3e7ed18e802932f1b8a95193c743d20308afba8
|
|
| MD5 |
0bebe334480545f60d1cea77ba3a844c
|
|
| BLAKE2b-256 |
f1435dea4a8a351a86b7242f373322edb95acdd44e7a668ba0012e6472234d56
|
Provenance
The following attestation bundles were made for psxdata-0.1.0a2-py3-none-any.whl:
Publisher:
publish.yml on mtauha/psxdata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
psxdata-0.1.0a2-py3-none-any.whl -
Subject digest:
cea671f5146e2463b24faec4d3e7ed18e802932f1b8a95193c743d20308afba8 - Sigstore transparency entry: 1340896272
- Sigstore integration time:
-
Permalink:
mtauha/psxdata@5e570bf266db17d4543ee078ec715d4086b2626a -
Branch / Tag:
refs/tags/v0.1.0a2 - Owner: https://github.com/mtauha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@5e570bf266db17d4543ee078ec715d4086b2626a -
Trigger Event:
push
-
Statement type: