Skip to main content

Python library and REST API for Pakistan Stock Exchange (PSX) data

Project description

psxdata

CI PyPI Status

⚠ 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


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.0a1.tar.gz (26.3 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.0a1-py3-none-any.whl (33.2 kB view details)

Uploaded Python 3

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

Hashes for psxdata-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 0610d4049348705d539b6a67a1903820409fd5fb22c48815ea6c90a178ad3056
MD5 cb3ec275a3a663cb6f3315c6c2827f52
BLAKE2b-256 7003d22b8bf41e4cb6e08a90b7560a3dbc9dc56df59be52f19c50cb566658d97

See more details on using hashes here.

Provenance

The following attestation bundles were made for psxdata-0.1.0a1.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.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

Hashes for psxdata-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 775be2d5076a3a437d72d75e1f3686dfcabb6f28849f416edc0a9647b17287b7
MD5 57d4ed49195ce09518260a8c37792e61
BLAKE2b-256 00f5aa037e36b8069f9e6c5e8470f6aa9ea76387017615d453ecc7b27c2ce835

See more details on using hashes here.

Provenance

The following attestation bundles were made for psxdata-0.1.0a1-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.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page