Python library and REST API for Pakistan Stock Exchange (PSX) data
Project description
psxdata
⚠ This package is under active development and is not yet usable. No PyPI release exists. The library, scrapers, and REST API are being built in phases — see the development roadmap for current status.
Python library and REST API for Pakistan Stock Exchange (PSX) data — being built from scratch to be resilient to PSX's frequent HTML changes.
Why psxdata
The existing psx-data-reader library hardcodes date formats and column positions that break silently when PSX changes its HTML. psxdata is designed differently: dynamic column extraction from <th> tags, multi-format date parsing with fuzzy fallback, exponential backoff retries, and a disk cache that keeps historical data forever.
Planned API
These signatures are the target interface. They do not work yet — implementation starts in Phase 2.
import psxdata
# Historical OHLCV data for ENGRO
df = psxdata.stocks("ENGRO", start="2024-01-01", end="2024-12-31")
# All listed tickers
tickers = psxdata.tickers()
# KSE-100 constituents only
kse100 = psxdata.tickers(index="KSE-100")
# Current index values
indices = psxdata.indices()
| Function | Description |
|---|---|
psxdata.stocks(symbol, start, end) |
Historical OHLCV DataFrame for one or more tickers |
psxdata.tickers(index=None) |
All listed tickers, optionally filtered by index |
psxdata.indices() |
Current index values (KSE-100, KSE-30, KMI-30) |
psxdata.sectors() |
Sector aggregates DataFrame |
psxdata.fundamentals(symbol) |
P/E ratio, EPS, book value for a ticker |
psxdata.market.debt() |
Debt market instruments (TFCs, Sukuks) |
psxdata.market.eligible_scrips() |
Margin trading eligible stocks |
Planned REST API
The FastAPI layer is planned for Phase 4 and does not exist yet.
| 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 |
Index values |
GET /sectors |
Sector aggregates |
GET /debt-market |
Debt instruments |
GET /eligible-scrips |
Margin eligible stocks |
All responses will follow: {"data": ..., "meta": {"timestamp": "...", "cached": bool}}
Development Status
See the roadmap issue for the full phase breakdown. Current state:
- ✅ 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
- 🔲 Phase 3 API — Public Python package interface
- 🔲 Phase 4 — FastAPI REST layer
- 🔲 Phase 5 — Full test suite
- 🔲 Phase 6 — Packaging & PyPI publish
- 🔲 Phase 7 — Documentation
Contributing
Contributions are welcome once Phase 2 is underway. 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.0a1.tar.gz.
File metadata
- Download URL: psxdata-0.1.0a1.tar.gz
- Upload date:
- Size: 26.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0610d4049348705d539b6a67a1903820409fd5fb22c48815ea6c90a178ad3056
|
|
| MD5 |
cb3ec275a3a663cb6f3315c6c2827f52
|
|
| BLAKE2b-256 |
7003d22b8bf41e4cb6e08a90b7560a3dbc9dc56df59be52f19c50cb566658d97
|
Provenance
The following attestation bundles were made for psxdata-0.1.0a1.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.0a1.tar.gz -
Subject digest:
0610d4049348705d539b6a67a1903820409fd5fb22c48815ea6c90a178ad3056 - Sigstore transparency entry: 1340786130
- Sigstore integration time:
-
Permalink:
mtauha/psxdata@3af010a17d07f65ce8f3585a4890c4cda6a24ed1 -
Branch / Tag:
refs/tags/v0.1.0a1 - Owner: https://github.com/mtauha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3af010a17d07f65ce8f3585a4890c4cda6a24ed1 -
Trigger Event:
push
-
Statement type:
File details
Details for the file psxdata-0.1.0a1-py3-none-any.whl.
File metadata
- Download URL: psxdata-0.1.0a1-py3-none-any.whl
- Upload date:
- Size: 33.2 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 |
775be2d5076a3a437d72d75e1f3686dfcabb6f28849f416edc0a9647b17287b7
|
|
| MD5 |
57d4ed49195ce09518260a8c37792e61
|
|
| BLAKE2b-256 |
00f5aa037e36b8069f9e6c5e8470f6aa9ea76387017615d453ecc7b27c2ce835
|
Provenance
The following attestation bundles were made for psxdata-0.1.0a1-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.0a1-py3-none-any.whl -
Subject digest:
775be2d5076a3a437d72d75e1f3686dfcabb6f28849f416edc0a9647b17287b7 - Sigstore transparency entry: 1340786131
- Sigstore integration time:
-
Permalink:
mtauha/psxdata@3af010a17d07f65ce8f3585a4890c4cda6a24ed1 -
Branch / Tag:
refs/tags/v0.1.0a1 - Owner: https://github.com/mtauha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3af010a17d07f65ce8f3585a4890c4cda6a24ed1 -
Trigger Event:
push
-
Statement type: