Add your description here
Project description
NEPSE Client
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:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Run tests and ensure they pass
- Run code formatters:
black .andisort . - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - 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
- Author: Your Name
- Email: your.email@example.com
- GitHub: @yourusername
๐ 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9e44140f6727c3f408808ca6d8f2441343ae3863da9796167e6b5da6cca392e
|
|
| MD5 |
431529dd1008b1587f7a461ec0ed2cb8
|
|
| BLAKE2b-256 |
133fd19c455ad9e7fb9e4e14fb1483ef273bdf89b4ab6ca6d4235a0f6790293e
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f31b2ddfd69cbf68d6b3f45719bc4aa1439b44a9f053adbd248a54b1f8046874
|
|
| MD5 |
f540cdb55298880428227098980a8c04
|
|
| BLAKE2b-256 |
7295c98fed5fcec3833e52fae00156459add241122ed0fd57f288975dd6ff981
|