Chanda
Sanskrit Meter Identification and Analysis Library
A comprehensive Python library for identifying and analyzing Sanskrit poetic meters. Supports 200+ meters including Sama-vṛtta, Ardhasama-vṛtta, Viṣama-vṛtta, and Mātrā-vṛtta.
- Chandojñānam Web Interface: https://sanskrit.iitk.ac.in/jnanasangraha/chanda/
- Chandojñānam Web Interface Source Code: https://github.com/hrishikeshrt/chandojnanam/
Features
-
200+ Meter Database: Comprehensive coverage of Sanskrit meters
- Sama-vṛtta (meters with identical padas)
- Ardhasama-vṛtta & Viṣama-vṛtta (meters with varying padas)
- Mātrā-vṛtta (matra-based meters like Āryā, Gīti)
-
Smart Identification:
- Exact pattern matching
- Fuzzy matching with syllable-level correction suggestions
- Verse-level analysis (4-line grouping)
-
Multi-Script Support: 15+ scripts and transliteration schemes
- Devanagari, IAST, ITRANS, Harvard-Kyoto, SLP1, WX, Velthuis, and more
-
Detailed Analysis:
- Syllable segmentation
- Laghu-Guru (light-heavy) marking
- Gana notation conversion
- Mātrā (morae) counting
- Jāti (classification) identification
Installation
From PyPI
pip install chanda
From Source
git clone https://github.com/hrishikeshrt/chanda.git
cd chanda
pip install -e .
Quick Start
Python API
from chanda import analyze_line
# Simple example - Anuṣṭubh (most common meter)
text = "को न्वस्मिन् साम्प्रतं लोके गुणवान् कश्च वीर्यवान्"
result = analyze_line(text)
meters = [name for name, _ in result.chanda]
print(meters) # Output: ['अनुष्टुभ्']
# Gana-based meter example - shows gana pattern
text = "नमस्ते सदा वत्सले मातृभूमे"
result = analyze_line(text)
meters = [name for name, _ in result.chanda]
print(meters) # Output: ['भुजङ्गप्रयात']
print(result.gana) # Output: यययय
Results are objects (ChandaResult / TextAnalysisResult).
Use result.to_dict() or result.to_json() for serialization.
Command-Line Interface
# Analyze a single line
chanda "को न्वस्मिन् साम्प्रतं लोके गुणवान् कश्च वीर्यवान्"
# Analyze a file
chanda -f bhagavad_gita.txt --verse --summary
# Interactive mode
chanda -i
# Get help
chanda --help
Detailed Usage
Single Line Analysis
from chanda import analyze_line
text = "रामो राजमणिः सदा विजयते रामं रमेशं भजे"
result = analyze_line(text, fuzzy=True)
if result.found:
print(f"Meter(s): {[name for name, _ in result.chanda]}")
print(f"Syllables: {result.syllables}")
print(f"Pattern (LG): {' '.join(result.lg)}")
print(f"Gana: {result.gana}")
print(f"Syllable count: {result.length}")
print(f"Mātrā count: {result.matra}")
else:
# Check fuzzy matches
if result.fuzzy:
best_match = result.fuzzy[0]
from chanda import format_chanda_list
print(f"Closest meter: {format_chanda_list(best_match['chanda'])}")
print(f"Similarity: {best_match['similarity']:.2%}")
Verse Analysis
from chanda import analyze_text
verse = """को न्वस्मिन् साम्प्रतं लोके गुणवान् कश्च वीर्यवान्।
धर्मज्ञश्च कृतज्ञश्च सत्यवाक्यो दृढव्रतः॥"""
results = analyze_text(verse, verse_mode=True, fuzzy=True)
for verse_result in results.result.verse:
if not verse_result.chanda:
continue
best_meters, _score = verse_result.chanda
# is_partial is True when fewer lines than expected were available
partial_note = " (partial)" if verse_result.is_partial else ""
print(f"Verse meter: {' / '.join(best_meters)}{partial_note}")
# Detailed per-meter breakdown via MeterScore
winner = verse_result.scores[0]
print(f" Match extent: {winner.match_extent:.0%}") # fraction of padas explained
for ev in winner.evidence:
line_idx = ev['line_idx'] # None for mātrā evidence
mtype = ev['match_type'] # 'exact', 'fuzzy', or 'matra'
sim = ev['similarity'] # 1.0 for exact
pada = ev['pada'] # e.g. ['1', '2']
valid_pos = ev['pada_position_valid']
print(f" line {line_idx}: {mtype}, similarity={sim:.2f}, pada={pada}, pos_valid={valid_pos}")
Note on aliases: meters with multiple traditional names are joined with
=, e.g."कलहंस = कुटजा = सिंहनाद = नन्दिनी". A tie between distinct meters appears as separate entries inverse_result.scores.Note on
scorevsmatch_extent:scoreinMeterScoreis an internal ranking accumulator and should not be displayed. Usematch_extent(0.0–1.0) to show users how well a meter fits the verse.
Documentation
Full documentation is available at chanda.readthedocs.io
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes with tests
- Run the test suite
- Submit a pull request
Citation
If you use Chandojñānam in your research, please cite:
@inproceedings{terdalkar2023chandojnanam,
title = "Chandojnanam: A {S}anskrit Meter Identification and Utilization System",
author = "Terdalkar, Hrishikesh and
Bhattacharya, Arnab",
booktitle = "Proceedings of the Computational {S}anskrit {\&} Digital Humanities: Selected papers presented at the 18th World {S}anskrit Conference",
month = jan,
year = "2023",
address = "Canberra, Australia (Online mode)",
publisher = "Association for Computational Linguistics",
url = "https://aclanthology.org/2023.wsc-csdh.8",
pages = "113--127",
}
License
GNU Affero General Public License v3.0 - see LICENSE file for details.
Acknowledgments
- Based on traditional chandaśāstra texts
- Meter definitions compiled from various classical sources
- Built on the excellent
sanskrit-textandindic-transliterationlibraries
Links
- PyPI: https://pypi.org/project/chanda/
- GitHub: https://github.com/hrishikeshrt/chanda
- Documentation: https://chanda.readthedocs.io
- Issues: https://github.com/hrishikeshrt/chanda/issues
Metadata
Release files for chanda 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| chanda-1.1.0.tar.gz | 76.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| chanda-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 132.9 kB
Release files / chanda-1.1.0.tar.gz
| Download URL | chanda-1.1.0.tar.gz |
|---|---|
| Size | 76.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6b304984ac2da0dde9b0147645c9512e4b1df0c88527b6b2b2c9bff5ab22b145
|
|
BLAKE2b-256 checksum How to use checksums |
d743eb07645d25c60451f9c726a20d0a431359bb5e58a91276cc45b349c21388
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|
Release files / chanda-1.1.0-py3-none-any.whl
| Download URL | chanda-1.1.0-py3-none-any.whl |
|---|---|
| Size | 56.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
491ac9859555a252dde2bbd9bd2b393d0e5e1acf66438cbd23400650cbaa4de2
|
|
BLAKE2b-256 checksum How to use checksums |
262694fe2d8b5a208ec151a034e14d831fc755f70320c958b3ee14a3d4779013
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.5
|