Metadata-Version: 2.4
Name: indialend
Version: 1.0.0
Summary: Unified Credit Decision Engine for Indian NBFC Lending - scoring, bureau, policy, risk, compliance
Author-email: IndiaLend Team <team@indialend.dev>
Maintainer-email: IndiaLend Team <team@indialend.dev>
License: MIT License
        
        Copyright (c) 2026 IndiaLend Team
        
        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/indialend/indialend
Project-URL: Documentation, https://github.com/indialend/indialend#readme
Project-URL: Repository, https://github.com/indialend/indialend
Project-URL: Issues, https://github.com/indialend/indialend/issues
Project-URL: Changelog, https://github.com/indialend/indialend/blob/main/CHANGELOG.md
Keywords: credit-scoring,nbfc,lending,fintech,india,rbi,cibil,bureau,risk-assessment,machine-learning,apple-silicon,metal-gpu
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Office/Business :: Financial
Classifier: Topic :: Office/Business :: Financial :: Accounting
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Classifier: Typing :: Typed
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24.0
Requires-Dist: pandas>=2.0.0
Requires-Dist: scikit-learn>=1.3.0
Requires-Dist: scipy>=1.11.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: joblib>=1.3.0
Requires-Dist: python-dateutil>=2.8.0
Provides-Extra: lightgbm
Requires-Dist: lightgbm>=4.0.0; extra == "lightgbm"
Provides-Extra: xgboost
Requires-Dist: xgboost>=2.0.0; extra == "xgboost"
Provides-Extra: gpu
Requires-Dist: torch>=2.0.0; extra == "gpu"
Provides-Extra: api
Requires-Dist: fastapi>=0.100.0; extra == "api"
Requires-Dist: uvicorn>=0.23.0; extra == "api"
Provides-Extra: dev
Requires-Dist: pytest>=7.4.0; extra == "dev"
Requires-Dist: pytest-cov>=4.1.0; extra == "dev"
Requires-Dist: build>=1.0.0; extra == "dev"
Requires-Dist: twine>=4.0.0; extra == "dev"
Provides-Extra: all
Requires-Dist: lightgbm>=4.0.0; extra == "all"
Requires-Dist: xgboost>=2.0.0; extra == "all"
Requires-Dist: torch>=2.0.0; extra == "all"
Requires-Dist: fastapi>=0.100.0; extra == "all"
Requires-Dist: uvicorn>=0.23.0; extra == "all"
Dynamic: license-file

# IndiaLend

**Unified Credit Decision Engine for Indian NBFC Lending**

[![PyPI version](https://badge.fury.io/py/indialend.svg)](https://pypi.org/project/indialend/)
[![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)

One-stop Python library for Indian fintech credit decisioning: credit scoring, bureau integration, income verification, policy engine, risk assessment, and RBI compliance.

## Why IndiaLend?

Indian NBFCs and fintechs face unique challenges that global credit scoring libraries don't address:

- **RBI CAT/NonCAT segmentation** - Regulatory requirement for different risk treatment based on income threshold (Rs 30 lakh)
- **Bureau integration** - CIBIL, Equifax, CRIF with consent tracking and smart caching
- **CIBIL-scale scoring** - 300-900 scale that Indian lenders understand
- **Indian document validation** - PAN, Aadhaar, GSTIN, IFSC validators
- **NPA classification** - SMA-0/1/2, Sub-Standard, Doubtful, Loss per RBI norms
- **Alternative scoring** - UPI, phone, e-commerce data for thin-file applicants (~300M credit-invisible Indians)

## Features

### Credit Scoring
- Multi-model ensemble (HistGBM, Random Forest, Extra Trees, Logistic Regression)
- PyTorch neural network with **Apple Silicon Metal GPU** acceleration
- CAT/NonCAT segment-specific models
- Probability calibration (Platt scaling)
- Alternative data scoring for thin-file applicants

### Bureau Integration
- CIBIL, Equifax, CRIF bureau simulation with deterministic responses
- Consent tracking (RBI mandate)
- Smart caching and fallback ordering
- Bureau call cost optimization

### Income Verification
- Priority-based: ITR > GST > Salary Slip > Bank Statement
- Tax estimation (new regime slabs)
- GST turnover analysis
- Salary consistency checking

### Policy Engine
- Business Rules Engine (BRE) with eligibility knockout + approval criteria
- Risk-based dynamic pricing
- EMI calculation
- Batch evaluation

### Risk Assessment
- PD/LGD/EAD/Expected Loss (Basel III IRB approach)
- Portfolio monitoring with NPL tracking
- Default prediction (6/12/24 month horizons)
- Early Warning System
- Stress testing (5 scenarios)

### RBI Compliance
- NPA classification per RBI norms
- Divergence tracking (bureau vs internal)
- Fairness auditing (4/5ths rule)
- Provisioning rate calculation

## Installation

```bash
pip install indialend
```

With optional dependencies:

```bash
# Apple Silicon Metal GPU support (neural network)
pip install indialend[gpu]

# All optional dependencies
pip install indialend[all]
```

## Quick Start

```python
from indialend import CreditScorer, load_sample_data

# Load sample data (1000 synthetic Indian credit applications)
X_train, X_test, y_train, y_test = load_sample_data()

# Train credit scoring model
scorer = CreditScorer()
scorer.fit(X_train, y_train)

# Score applicants (CIBIL-like 300-900 scale)
scores = scorer.score(X_test)
print(scores.head())
#    default_probability  cibil_score risk_grade segment
# 0             0.023145          886          A  NonCAT
# 1             0.156789          806          A     CAT
# 2             0.892345          365          E  NonCAT
```

### Neural Network with Metal GPU

```python
from indialend import NeuralCreditScorer

# Train on Apple Silicon Metal GPU
neural = NeuralCreditScorer(
    epochs=100,
    batch_size=2048,
    device="auto",  # auto-detects MPS/CUDA/CPU
    verbose=True,
)
neural.fit(X_train, y_train, X_val=X_test, y_val=y_test)
scores = neural.score(X_test)
```

### Multi-Model Ensemble

```python
from indialend import EnsembleCreditScorer

# Train 6+ models and combine with AUC-weighted averaging
ensemble = EnsembleCreditScorer(verbose=True)
ensemble.fit(X_train, y_train, X_val=X_test, y_val=y_test)

# Compare all models
comparison = ensemble.compare_models(X_test, y_test)
print(comparison)
```

### Full Training Pipeline

```bash
# Train all models on 200K synthetic data with Metal GPU
python train_models.py

# Quick test run
python train_models.py --quick

# Large dataset with more epochs
python train_models.py --samples 500000 --epochs 200
```

### Bureau + Income + Policy Decision

```python
from indialend import BureauManager, IncomeVerifier, PolicyEngine

# Bureau check
bureau = BureauManager()
report = bureau.fetch("ABCDE1234F", bureau_type="CIBIL")

# Income verification
verifier = IncomeVerifier()
income = verifier.verify({"itr_income": 800000, "salary_monthly": 65000})

# Policy decision
engine = PolicyEngine()
decision = engine.evaluate({
    "annual_income": 800000,
    "cibil_score": 720,
    "loan_amount": 500000,
    "employment_type": "Salaried",
    "age": 32,
})
print(decision["decision"])  # "APPROVED" / "REJECTED" / "MANUAL_REVIEW"
```

## Synthetic Data

Generate realistic Indian credit application data:

```python
from indialend import generate_synthetic_data

# 200K applications with 69 correlated features
df = generate_synthetic_data(n_samples=200_000)
print(f"Shape: {df.shape}")
print(f"Default rate: {df['default_flag'].mean():.2%}")
print(f"CAT segment: {(df['cat_segment'] == 'CAT').mean():.1%}")
```

Features include demographics, geography (4-tier cities), employment, income, bureau history, alternative data (UPI, phone, e-commerce), and realistic correlations.

## Architecture

```
indialend/
  credit_scoring.py    - CreditScorer, AlternativeScorer, CAT/NonCAT
  neural_scorer.py     - NeuralCreditScorer (PyTorch + Metal GPU)
  ensemble_scorer.py   - EnsembleCreditScorer, ModelFactory
  bureau_integration.py - BureauManager, ConsentTracker
  income_verification.py - IncomeVerifier, ITR/GST/Salary parsers
  policy_engine.py     - PolicyEngine, BRE, DecisionRules
  risk_assessment.py   - PD/LGD/EAD, PortfolioMonitor, StressTest
  compliance.py        - NPA classification, fairness auditing
  data_management.py   - Validators, KYC, deduplication
  utils.py             - Synthetic data, PAN/Aadhaar validators
```

## Hardware Requirements

- **Minimum**: Any machine with Python 3.9+ and 4GB RAM
- **Recommended**: Apple Silicon Mac (M1/M2/M3/M4) for Metal GPU acceleration
- **Training 200K samples**: ~16GB RAM, ~5 minutes on M4

## License

MIT License. See [LICENSE](LICENSE) for details.
