Metadata-Version: 2.4
Name: psxdata
Version: 0.1.0a1
Summary: Python library and REST API for Pakistan Stock Exchange (PSX) data
License: Copyright 2026 Muhammad Tauha
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
Project-URL: Homepage, https://github.com/mtauha/psxdata
Project-URL: Source, https://github.com/mtauha/psxdata
Project-URL: Bug Tracker, https://github.com/mtauha/psxdata/issues
Keywords: psx,pakistan,stock,market,finance,data
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Office/Business :: Financial :: Investment
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE.md
Requires-Dist: requests>=2.28
Requires-Dist: httpx>=0.24
Requires-Dist: beautifulsoup4>=4.11
Requires-Dist: lxml>=4.9
Requires-Dist: pandas>=2.0
Requires-Dist: pyarrow>=14.0
Requires-Dist: python-dateutil>=2.8
Requires-Dist: tqdm>=4.64
Requires-Dist: diskcache>=5.4
Requires-Dist: pydantic>=2.0
Provides-Extra: api
Requires-Dist: fastapi>=0.100; extra == "api"
Requires-Dist: uvicorn>=0.22; extra == "api"
Requires-Dist: slowapi>=0.1; extra == "api"
Requires-Dist: redis>=4.5; extra == "api"
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: pytest-asyncio; extra == "dev"
Requires-Dist: pytest-timeout>=2.1; extra == "dev"
Requires-Dist: httpx>=0.24; extra == "dev"
Requires-Dist: ruff>=0.4; extra == "dev"
Requires-Dist: mypy>=1.0; extra == "dev"
Requires-Dist: types-requests>=2.28; extra == "dev"
Requires-Dist: types-python-dateutil>=2.8; extra == "dev"
Dynamic: license-file

# psxdata

[![CI](https://github.com/mtauha/psxdata/actions/workflows/ci.yml/badge.svg)](https://github.com/mtauha/psxdata/actions/workflows/ci.yml)
![PyPI](https://img.shields.io/badge/pypi-not%20yet%20published-lightgrey)
![Status](https://img.shields.io/badge/status-in%20development-orange)

> **⚠ 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](https://github.com/mtauha/psxdata/issues/4) 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`](https://github.com/FarhanZizvi/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.

```python
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](https://github.com/mtauha/psxdata/issues/4) 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](CONTRIBUTING.md) and open an issue before starting non-trivial work.

---

## Architecture

See [ARCHITECTURE.md](ARCHITECTURE.md) for the component diagram, data flow, and design decisions.
