This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is a Python CLI tool for interacting with Bangladesh Power Development Board (BPDB) smart meter APIs. It provides OTP-based authentication and allows users to retrieve consumer information and recharge history through a command-line interface.
bpdb/bpdb.py - API Client Layer
BPDBSmartMeterAPIclass handles all HTTP communication with BPDB endpoints- Base URL:
http://202.51.186.182:33262/api/v1 - Token-based authentication using Bearer tokens
- Token persistence via configparser stored at
~/.python-bpdb-api-config - Methods:
send_otp(),login(),consumer_info(),recharge_info()
bpdb/main.py - CLI Layer
- Click-based CLI with command group pattern
- Commands registered via
app.add_command()pattern - Error handling through
handle_api_errordecorator wrapper - Entry point:
app()function mapped tobpdb-cliin pyproject.toml - Uses tabulate for formatted output display
bpdb/init.py - Package Entry Point
- Exports
BPDBSmartMeterAPIclass for programmatic use - Version controlled by GitHub Actions during release (format:
1.{run_number}.0)
- User calls
send-otpwith phone number → API sends OTP - User calls
loginwith phone number and OTP → API returns Bearer token - Token saved to
~/.python-bpdb-api-configusing configparser - Subsequent commands (
consumer-info,recharge-info) auto-load token from config file - Token passed as
Authorization: Bearer {token}header
# Install in development mode
pip install -e .
# Or create virtual environment first
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -e .# Test OTP send
bpdb-cli send-otp 01710123456
# Test login
bpdb-cli login 01710123456 123456
# Test consumer info (requires prior login)
bpdb-cli consumer-info
# Test recharge info (requires prior login)
bpdb-cli recharge-info 01710123456 0120100112233# Build distribution packages
python -m pip install build
python -m build
# Output: dist/*.whl and dist/*.tar.gz- Version is defined in
bpdb/__init__.pyas__version__ = "1.0.0" - GitHub Actions workflow (
.github/workflows/pypi.yml) auto-updates version on push to main - Version format:
1.{github.run_number}.0 - Workflow uses sed to replace version string:
sed -i "s/__version__ = \".*\"/__version__ = \"$VERSION\"/" bpdb/__init__.py
Automated via GitHub Actions on push to main:
- Version number updated automatically
- Build artifacts created with
python -m build - Published to PyPI using trusted publisher with OIDC token
Manual workflow dispatch also available via GitHub Actions UI.
Extracts these fields from response.json()["user"]["prepaid_data"]:
- division, meterType, accountType, sndDivision
- sanctionLoad, customerName, customerAddress, tariffCategory
Parses response.json()["message"]["orders"]["order"] array:
- Each order contains: date, grossAmount, energyCost, tokens
All commands follow this pattern:
- Click decorator defines command with arguments
@handle_api_errordecorator catches exceptions and exits with error code 1- Print status message with emoji
- Instantiate
BPDBSmartMeterAPI() - Call API method
- Format output with tabulate (or simple echo for OTP/login)
- This is part of a multi-repository project with sibling repositories:
python-descoandpython-nesco(similar utility tools for other Bangladesh power companies) - All three repositories share similar structure and patterns
- Token storage uses simple configparser format (not encrypted)
- No test suite currently exists
- API endpoints are HTTP (not HTTPS)