Python Interface to The Sanskrit Heritage Site
Project description
Heritage.py is a python interface to The Sanskrit Heritage Site.
Free software: GNU General Public License v3
Documentation: https://heritage-py.readthedocs.io.
Features
Morphological Analysis
Sandhi Formation
Declensions
Conjugations
Install
To install Heritage.py, run this command in your terminal:
$ pip install heritage
Usage
Heritage.py has two possible modes of operation,
Using a web mirror
This mode uses any compatible web mirror of The Heritage Platform (e.g. https://sanskrit.inria.fr/index.en.html) and does not require any installation, however, HTTP requests are made for every task resulting in a larger delay.
Using a local installation
Installation Instructions: https://sanskrit.inria.fr/manual.html#installation.
This mode requires a local installation of The Heritage Platform. As a result, it is considerably faster in obtaining results.
To use Heritage.py in a project,
import heritage
Quickstart
from heritage import HeritagePlatform
# Use the INRIA mirror (default behaviour)
heritage = HeritagePlatform(method="web")
analyses = heritage.get_analysis("रामः वनं गच्छति", sentence=True)
solution = analyses[1] # solutions are keyed by solution_id
first_word = solution["words"][0][0]
print(first_word["text"]) # -> 'रामः'
print(first_word["root"]) # -> 'राम'
print(first_word["analyses"]) # -> [['pr', 'mas', 'sg', 'nom']]
heritage.set_lexicon("SH") # Switch to the Heritage dictionary
declensions = heritage.get_declensions("राम", gender="m")
Choosing a data source
- Web mirror (default)
Nothing to install. Calls https://sanskrit.inria.fr (or any mirror you configure) for every request, so latency depends on network access.
- Local installation
Clone the upstream Heritage_Platform repository, compile the tools, and point Heritage.py at that checkout:
from pathlib import Path heritage = HeritagePlatform( base_dir=Path("~/git/Heritage_Platform").expanduser(), method="shell", )Shell mode is faster and works offline, but requires the compiled binaries to be available in <base_dir>/ML. If the directory is missing the helper falls back to web mode automatically.
Core API at a glance
- HeritagePlatform.get_analysis(text, sentence=True, unsandhied=False, meta=False)
Run the Reader Companion and receive structured morphological analyses.
- HeritagePlatform.get_parse(text, solution_id=None, ...)
Fetch semantic roles for a sentence from the Reader Assistant.
- HeritagePlatform.get_declensions(word, gender, headers=True)
Retrieve declension tables from the Grammarian.
- HeritagePlatform.get_conjugations(word, gana, lexicon=None)
Request conjugation tables (parsing into structured data is planned).
- HeritagePlatform.search_lexicon(word, lexicon=None)
Query the dictionary interface (returns raw HTML for now).
- heritage.utils.devanagari_to_velthuis(text)
Convert Devanagari script to the Velthuis scheme expected upstream.
- heritage.utils.build_query_string(options)
Assemble query strings for direct Heritage CGI calls.
Network configuration
The wrapper exposes simple knobs for HTTP behaviour when you rely on the online mirror.
heritage = HeritagePlatform(
method="web",
request_timeout=5, # seconds per HTTP request
request_attempts=4, # number of retries before failing
)
Requests are retried with exponential backoff and decoded as UTF-8 even when the server omits a charset header, preventing garbled Sanskrit text (mojibake) in the parsed output.
Troubleshooting
Enable logging to inspect low-level behaviour:
import logging logging.basicConfig(level=logging.INFO)
set_method("shell") falls back to web mode automatically when the local installation is missing.
Network calls use retries with exponential backoff; expect short delays on transient failures.
The CLI entry point currently prints a placeholder message. Contributions to build a feature-rich CLI are welcome.
Credits
This package was created with Cookiecutter and the hrishikeshrt/cookiecutter-pypackage project template.
History
0.1.0 (2022-03-23)
First release on PyPI.
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 heritage-0.1.2.tar.gz.
File metadata
- Download URL: heritage-0.1.2.tar.gz
- Upload date:
- Size: 28.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05a06a15384aff363e2b80e8d50e1b63b2ddb942efddce0057d6a3c89cb60348
|
|
| MD5 |
d19888e3ecc981efaec3dfb3a598e699
|
|
| BLAKE2b-256 |
0c759f992c689fe20c711c8c20e4887d919f5c16566ddb2dd93758c02b60e3fe
|
File details
Details for the file heritage-0.1.2-py2.py3-none-any.whl.
File metadata
- Download URL: heritage-0.1.2-py2.py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a457a330e50fbf35b82c46220e9997cc56b1dd73004af4a608c9864dfba14a0f
|
|
| MD5 |
a0e7e25498781ab4979360f5332218c9
|
|
| BLAKE2b-256 |
42ffddcddd0d5cb9a17fc577e053bdc1896c691221cfa8d260fcd82b9efaeee6
|