Skip to main content

Sanskrit Morph Converter

PyPI version License: GPL v3 Python 3.8+

A Python engine for unifying, standardizing, and converting Sanskrit morphological tags across multiple computational paradigms.

In Sanskrit Computational Linguistics, different tools like the Sanskrit Heritage engine, Samsaadhanii, neural models like ByT5, and baseline grammars like Svarupa output morphological analyses in vastly different formats and vocabularies. sanskrit-morph-converter provides a centralized, pivot-based architecture to translate these tagsets into a unified Canonical Representation.

Installation

Install the package directly from PyPI:

pip install sanskrit-morph-converter

Python API Usage

You can import the converter directly into your Python scripts to process strings or JSON outputs from various platforms. The core .convert() method takes a source platform, a target platform, and the raw input.

from sanskrit_morph_converter.converter import RepresentationConverter

# Initialize the converter (automatically loads the compiled mapping TSVs)
converter = RepresentationConverter()

Example 1: Converting ByT5 Output to Canonical

ByT5 outputs rely on underscore and pipe-separated strings. The converter easily parses these into standard Canonical properties.

byt5_raw = "devam_deva_Case=Acc|Gender=Masc|Number=Sing"

# Convert ByT5 to Canonical
canonical_tags = converter.convert('ByT5', 'Canonical', byt5_raw)
print(canonical_tags)
# Output: [{'input': 'देवम्', 'stem': 'देव', 'root': '', 'morph': 'Case=Accusative|Gender=Masculine|Number=Singular'}]

Example 2: Converting Sanskrit Heritage (SH) to DCS

The Sanskrit Heritage engine returns nested JSON dictionaries. You can pass the JSON string directly to convert it to another format, such as DCS.

sh_raw = """{
    "input": "गच्छति", 
    "status": "Success", 
    "morph": [{"word": "गच्छति", "root": "गम्", "inflectional_morphs": ["pr. [1] ac. sg. 3"]}]
}"""

# Convert SH to DCS
dcs_tags = converter.convert('SH', 'DCS', sh_raw, output_format='string')
print(dcs_tags)
# Output (Example): ['gacchati\tgam\tMood=Ind|Number=Sing|Person=3|Tense=Pres']

Command Line Interface (CLI)

The package includes a built-in CLI for batch processing files or testing quick strings directly from your terminal.

Convert a single string:

smc convert ByT5 Canonical -i "devam_deva_Case=Acc|Gender=Masc|Number=Sing"

Process an entire file and save the output:

smc convert SH Canonical -f data/sh_analysis.tsv -o data/canonical_results.tsv

Change the output script (e.g., to WX or IAST):

smc convert ByT5 SH -i "devam_deva_Case=Acc|Gender=Masc|Number=Sing" --script WX

Architecture

This library operates on a flexible, three-stage pipeline: Adapters (to read the source format), a Mapper (to route to a mathematical Pivot), and an Converter (to format the target platform output).

The Google Sheets Integration

To ensure this tool remains accessible to linguists and researchers who may not write code, the mapping vocabulary is not hardcoded. Instead, tag standardizations and lexical exceptions (like pronouns and causatives) are maintained collaboratively in a Master Google Sheet.

When linguistic rules are updated in the sheet, you can use the built-in compiler to fetch the latest data and rebuild the internal .tsv files (pivot_mapping.tsv, normalization.tsv, etc.) without altering the Python engine.

To fetch the latest mappings from the Google Sheet:

sanskrit-morph update

(Note: The pre-compiled .tsv files are already bundled with the PyPI package, so standard users do not need to run the compiler to use the tool).

📜 License

This project is licensed under the GNU GENERAL PUBLIC LICENSE v3 - see the LICENSE file for details.

Metadata

Release files for sanskrit-morph-converter 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sanskrit-morph-converter 0.2.0
File Size Uploaded Provenance Actions
sanskrit_morph_converter-0.2.0.tar.gz 55.5 kB With provenance Details for sanskrit_morph_converter-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sanskrit-morph-converter 0.2.0
File Interpreter ABI Platform Actions
sanskrit_morph_converter-0.2.0-py3-none-any.whl Python 3 none any Details for sanskrit_morph_converter-0.2.0-py3-none-any.whl

Total release size: 110.5 kB

Release files / sanskrit_morph_converter-0.2.0.tar.gz

Download URL sanskrit_morph_converter-0.2.0.tar.gz
Size 55.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c2ef65d2ad904a606d0b0ccb5e60c77f892f933253e4241b9d4b0ebb5ff31989
BLAKE2b-256 checksum
How to use checksums
b3f3490e2d2e6aa60509e1f54dfd699ce7567f5a4e3ddb4494296bd860b84188
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 1, 2026.

Transparency log

Release files / sanskrit_morph_converter-0.2.0-py3-none-any.whl

Download URL sanskrit_morph_converter-0.2.0-py3-none-any.whl
Size 54.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d83b6c203ac5dc64a540aed7588101a6b8ddf831cb71338ef1014a08ab63d670
BLAKE2b-256 checksum
How to use checksums
3cad725045ffaabb95d36372bcfce6157b130a245700929ec9770190f2007608
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 1, 2026.

Transparency log

Security for sanskrit-morph-converter 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for sanskrit_morph_converter-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on May 1, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page