Skip to main content

Add your description here

Project description

NEPSE Client

PyPI version Python License: MIT Code style: black

A comprehensive, professional-grade Python client library for interacting with the Nepal Stock Exchange (NEPSE) API. Built with modern Python best practices, type hints, and both synchronous and asynchronous support.

๐ŸŒŸ Features

  • โœจ Both Sync and Async Support - Choose the programming paradigm that fits your needs
  • ๐Ÿ”’ Automatic Token Management - Handles authentication and token refresh automatically
  • ๐Ÿ“Š Complete API Coverage - Access all NEPSE endpoints including market data, company info, floor sheets, and more
  • ๐Ÿ›ก๏ธ Robust Error Handling - Comprehensive exception hierarchy for better error management
  • ๐Ÿ“ Type Hints - Full type annotations for better IDE support and code quality
  • ๐Ÿ”„ Retry Logic - Built-in retry mechanisms for network failures
  • ๐Ÿ“ˆ Progress Tracking - Optional progress bars for long-running operations
  • ๐Ÿงช Well Tested - Comprehensive test suite with high coverage
  • ๐Ÿ“š Excellent Documentation - Detailed docs with examples

๐Ÿ“ฆ Installation

From PyPI (Recommended)

pip install nepse-client

From Source

git clone https://github.com/yourusername/nepse-client.git
cd nepse-client
pip install -e .

Development Installation

pip install -e ".[dev]"

๐Ÿš€ Quick Start

Synchronous Usage

from nepse_client import Nepse

# Initialize client
client = Nepse()

# Get market status
market_status = client.getMarketStatus()
print(f"Market is: {market_status['isOpen']}")

# Get today's prices
prices = client.getPriceVolume()

# Get company list
companies = client.getCompanyList()

# Get floor sheet
floor_sheet = client.getFloorSheet()

Asynchronous Usage

import asyncio
from nepse_client import AsyncNepse

async def main():
    # Initialize client
    client = AsyncNepse()
    
    # Get market status
    market_status = await client.getMarketStatus()
    print(f"Market is: {market_status['isOpen']}")
    
    # Get today's prices
    prices = await client.getPriceVolume()
    
    # Get company list
    companies = await client.getCompanyList()
    
    # Get floor sheet with progress bar
    floor_sheet = await client.getFloorSheet(show_progress=True)

# Run async function
asyncio.run(main())

๐Ÿ“– Documentation

Core Methods

Market Information

# Get market status (open/closed)
status = client.getMarketStatus()

# Get market summary
summary = client.getSummary()

# Get NEPSE index
index = client.getNepseIndex()

# Get sub-indices
sub_indices = client.getNepseSubIndices()

# Get live market data
live_market = client.getLiveMarket()

Company Information

# Get list of all companies
companies = client.getCompanyList()

# Get security list
securities = client.getSecurityList()

# Get company details by symbol
details = client.getCompanyDetails('NABIL')

# Get company price history
history = client.getCompanyPriceVolumeHistory(
    symbol='NABIL',
    start_date='2024-01-01',
    end_date='2024-12-31'
)

# Get company financial details
financials = client.getCompanyFinancialDetails(company_id='123')

# Get company AGM information
agm = client.getCompanyAGM(company_id='123')

# Get company dividend information
dividend = client.getCompanyDividend(company_id='123')

Trading Data

# Get floor sheet
floor_sheet = client.getFloorSheet()

# Get floor sheet for specific company
company_floor_sheet = client.getFloorSheetOf('NABIL', business_date='2024-01-15')

# Get trading average
trading_avg = client.getTradingAverage(business_date='2024-01-15', nDays=180)

# Get market depth
depth = client.getSymbolMarketDepth('NABIL')

Top Performers

# Get top gainers
gainers = client.getTopGainers()

# Get top losers
losers = client.getTopLosers()

# Get top 10 by trade volume
top_trade = client.getTopTenTradeScrips()

# Get top 10 by transaction count
top_transaction = client.getTopTenTransactionScrips()

# Get top 10 by turnover
top_turnover = client.getTopTenTurnoverScrips()

News and Announcements

# Get company news
news = client.getCompanyNewsList(page=1, page_size=100, is_strip_tags=True)

# Get news and alerts
alerts = client.getNewsAndAlertList(page=1, page_size=100, is_strip_tags=True)

# Get press releases
press_releases = client.getPressRelease()

# Get NEPSE notices
notices = client.getNepseNotice(page=0)

Other Data

# Get holiday list
holidays = client.getHolidayList(year=2025)

# Get debenture and bond list
debentures = client.getDebentureAndBondList(type='debenture')

# Get supply and demand
supply_demand = client.getSupplyDemand()

Advanced Features

Caching and ID Mappings

# Get company ID to symbol mapping (cached)
company_map = client.getCompanyIDKeyMap()

# Get security ID to symbol mapping (cached)
security_map = client.getSecurityIDKeyMap()

# Force update cache
company_map = client.getCompanyIDKeyMap(force_update=True)

# Get sector-wise scrips
sector_scrips = client.getSectorScrips()

TLS Verification

# Disable TLS verification (not recommended for production)
client.setTLSVerification(False)

# Re-enable TLS verification
client.setTLSVerification(True)

Custom Logging

import logging

# Create custom logger
logger = logging.getLogger('my_nepse_app')
logger.setLevel(logging.DEBUG)

# Initialize client with custom logger
client = Nepse()
client.logger = logger

๐Ÿ—๏ธ Project Structure

nepse-client/
โ”œโ”€โ”€ nepse_client/
โ”‚   โ”œโ”€โ”€ __init__.py          # Package entry point
โ”‚   โ”œโ”€โ”€ client.py            # Base client class
โ”‚   โ”œโ”€โ”€ sync_client.py       # Synchronous implementation
โ”‚   โ”œโ”€โ”€ async_client.py      # Asynchronous implementation
โ”‚   โ”œโ”€โ”€ token_manager.py     # Token management
โ”‚   โ”œโ”€โ”€ dummy_id_manager.py  # Dummy ID management
โ”‚   โ”œโ”€โ”€ errors.py            # Custom exceptions
โ”‚   โ””โ”€โ”€ data/
โ”‚       โ”œโ”€โ”€ API_ENDPOINTS.json
โ”‚       โ”œโ”€โ”€ DUMMY_DATA.json
โ”‚       โ”œโ”€โ”€ HEADERS.json
โ”‚       โ””โ”€โ”€ css.wasm
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ test_sync_client.py
โ”‚   โ”œโ”€โ”€ test_async_client.py
โ”‚   โ””โ”€โ”€ test_token_manager.py
โ”œโ”€โ”€ examples/
โ”‚   โ”œโ”€โ”€ basic_usage.py
โ”‚   โ”œโ”€โ”€ async_usage.py
โ”‚   โ””โ”€โ”€ advanced_examples.py
โ”œโ”€โ”€ docs/
โ”‚   โ””โ”€โ”€ ... (Sphinx documentation)
โ”œโ”€โ”€ setup.py
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ LICENSE
โ”œโ”€โ”€ CHANGELOG.md
โ”œโ”€โ”€ MANIFEST.in
โ”œโ”€โ”€ .gitignore
โ”œโ”€โ”€ .pre-commit-config.yaml
โ””โ”€โ”€ requirements.txt

๐Ÿงช Testing

Run the test suite:

# Run all tests
pytest

# Run with coverage
pytest --cov=nepse_client --cov-report=html

# Run specific test file
pytest tests/test_sync_client.py

# Run with verbose output
pytest -v

๐Ÿค Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run tests and ensure they pass
  5. Run code formatters: black . and isort .
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. Open a Pull Request

Development Setup

# Clone the repository
git clone https://github.com/yourusername/nepse-client.git
cd nepse-client

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install

# Run tests
pytest

๐Ÿ“ Code Style

This project uses:

  • Black for code formatting
  • isort for import sorting
  • flake8 for linting
  • mypy for type checking

Run all formatters:

black .
isort .
flake8 .
mypy nepse_client

๐Ÿ› Error Handling

The library provides a comprehensive exception hierarchy:

from nepse_client import (
    NepseError,                  # Base exception
    NepseInvalidClientRequest,   # 400 errors
    NepseTokenExpired,           # 401 errors
    NepseBadGatewayError,        # 502 errors
    NepseServerError,            # Other 5xx errors
    NepseNetworkError            # Network/unexpected errors
)

try:
    data = client.getMarketStatus()
except NepseTokenExpired:
    print("Token expired, will auto-refresh")
except NepseServerError as e:
    print(f"Server error: {e}")
except NepseError as e:
    print(f"NEPSE error: {e}")

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Nepal Stock Exchange for providing the API
  • All contributors who have helped improve this library

๐Ÿ“ง Contact

๐Ÿ”— Links

โญ Star History

If you find this library useful, please consider giving it a star on GitHub!

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

nepse_client-0.1.0.tar.gz (29.3 kB view details)

Uploaded Source

Built Distribution

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

nepse_client-0.1.0-py3-none-any.whl (29.6 kB view details)

Uploaded Python 3

File details

Details for the file nepse_client-0.1.0.tar.gz.

File metadata

  • Download URL: nepse_client-0.1.0.tar.gz
  • Upload date:
  • Size: 29.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for nepse_client-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a9e44140f6727c3f408808ca6d8f2441343ae3863da9796167e6b5da6cca392e
MD5 431529dd1008b1587f7a461ec0ed2cb8
BLAKE2b-256 133fd19c455ad9e7fb9e4e14fb1483ef273bdf89b4ab6ca6d4235a0f6790293e

See more details on using hashes here.

File details

Details for the file nepse_client-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nepse_client-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 29.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for nepse_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f31b2ddfd69cbf68d6b3f45719bc4aa1439b44a9f053adbd248a54b1f8046874
MD5 f540cdb55298880428227098980a8c04
BLAKE2b-256 7295c98fed5fcec3833e52fae00156459add241122ed0fd57f288975dd6ff981

See more details on using hashes here.

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