Skip to main content

Nepali Unicoder

Documentation PyPI version

A robust Python package for converting Romanized Nepali text and Preeti font text into Unicode Devanagari script. It uses a greedy matching algorithm for Roman transliteration and a two-phase conversion process for Preeti with contextual rules.

Read the Full Documentation for detailed usage guides, Preeti mapping references, and API details.

Features

  • Accurate Transliteration: Uses a greedy matching algorithm to prioritize longer phonetic matches (e.g., 'kha' is matched before 'k' and 'h').
  • Preeti Font Support: Full support for Preeti to Unicode conversion with 30+ contextual rules for accurate transformation.
  • Smart Vowel Handling: Distinguishes between independent vowels (e.g., 'aa' -> 'आ') and vowel signs/matras (e.g., 'ka' -> 'क', 'kaa' -> 'का').
  • Contextual Rules: Handles complex Devanagari rules like reph positioning, matra reordering, and special character combinations.
  • Mixed Content Support: Allows keeping English words or specific text in Roman script using {} blocks.
  • Customizable: Supports custom word-level overrides via word_maps.json or Converter(word_map={...}).
  • CLI Support: Can be used directly from the command line.

Installation

You can install the package locally:

pip install nepali-unicoder

Usage

Command Line Interface (CLI)

You can use the converter directly from the terminal:

# Using the installed command
nepali-unicoder "namaste"
# Output: नमस्ते

# Or using python module
python -m nepali_unicoder "namaste"
# Output: नमस्ते

# Pipe input
echo "mero naam sanjeev ho" | nepali-unicoder
# Output: मेरो नाम् सन्जीव् हो

Python API

from nepali_unicoder.convert import Converter

converter = Converter()

# Basic conversion
text = "namaste nepal"
print(converter.convert(text))
# Output: नमस्ते नेपाल

# Using 'as-is' blocks for English text
mixed_text = "mero naam {Sanjeev} ho"
print(converter.convert(mixed_text))
# Output: मेरो नाम् Sanjeev हो

# Your own whole-word mappings (override the bundled ones)
converter = Converter(word_map={"sanjeev": "सञ्जीव"})
print(converter.convert("Sanjeev"))
# Output: सञ्जीव

Preeti Mode

Convert Preeti font text to Unicode with full support for contextual rules:

from nepali_unicoder.convert import Converter

# Create converter in Preeti mode
preeti_converter = Converter(mode="preeti")

# Basic conversion
preeti_text = "s{sf"  # Preeti characters
print(preeti_converter.convert(preeti_text))
# Output: र्कका

# The converter handles:
# - Reph positioning: { → र् (moves before consonant)
# - Matra reordering: l (ि) moves after consonant
# - Special m transformations
# - Vowel combinations
# - Literal brackets: { and } are treated as normal characters in Preeti mode

Preeti Character Examples

Preeti Unicode Description
s क Consonant ka
s{ र्क Reph + ka (contextual)
sl कि ka + short i (reordered)
qm क्र Special m transformation
!@# १२३ Nepali numbers
Ù / Ú ; / : Literal punctuation
« / » ्र Ra-foot (for ट, ठ, ड, ढ)
¿ रू Combined ruu
å द्व Combined dva
ˆ फ् Half ph
ª ङ Consonant nga
æ / Æ “ / ” Curly quotes
¥ र् Half ra
ठ्ठ Combined thth
§ ट्ट Combined tt
£ घ् Half gh
Ë / Í ङ्ग / ङ्क Combined nga-ga / nga-ka
‰ झ् Half jh

CLI for Preeti

python -m nepali_unicoder --preeti "s{sf"
# Output: र्कका

Transliteration Rules

  • Consonants: k -> क्, ka -> क, kh -> ख्, kha -> ख
  • Vowels: a -> अ, aa -> आ, i -> इ, u -> उ
  • Matras: ki -> कि, ko -> को
  • Special: . -> ।, .. -> ॥
  • Numbers: 0-9 -> ०-९ (Decimal points are preserved: 1.5 -> १.५)

Advanced Usage

Handling Complex Text

The converter handles mixed content gracefully. You can use {} to keep text as-is (e.g., for English words or code snippets).

text = "mero naam {Sanjeev} ho ra ma 12.5 barsa ko bhaye."
print(converter.convert(text))
# Output: मेरो नाम् Sanjeev हो र म १२.५ बर्स को भये।

Configuration

The package uses word_maps.json for custom word-level overrides, located in the src/nepali_unicoder directory.

  1. word_maps.json: Defines custom word-level overrides. Use this for words that don't follow standard phonetic rules.

Example word_maps.json:

{
    "nepal": "नेपाल",
    "kathamandu": "काठमाडौँ"
}

Contribution

We welcome contributions! Here's how you can help:

  1. Clone the repository:

    git clone https://github.com/realsanjeev/nepali_unicoder.git
    cd nepali_unicoder
    
  2. Set up a virtual environment:

    python3 -m venv .venv
    source .venv/bin/activate
    pip install -e .
    
  3. Run tests:

    python -m unittest discover tests
    
  4. Submit a Pull Request: Create a new branch, make your changes, and submit a PR.

Development

To run tests:

python -m unittest discover tests

License

MIT

Metadata

Release files for nepali-unicoder 0.3.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 nepali-unicoder 0.3.0
File Size Uploaded Provenance Actions
nepali_unicoder-0.3.0.tar.gz 19.0 kB With provenance Details for nepali_unicoder-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nepali-unicoder 0.3.0
File Interpreter ABI Platform Actions
nepali_unicoder-0.3.0-py3-none-any.whl Python 3 none any Details for nepali_unicoder-0.3.0-py3-none-any.whl

Total release size: 33.2 kB

Release files / nepali_unicoder-0.3.0.tar.gz

Download URL nepali_unicoder-0.3.0.tar.gz
Size 19.0 kB
Tags Source
SHA-256 checksum
How to use checksums
68f8dae7d094ca51305a0a97580f0c51ef4c1c7589c5eee0c8733e1fae16eb6b
BLAKE2b-256 checksum
How to use checksums
d28fdd887c1c96f130c357603701bdcc9dac71c1d0386f3106570f7848253491
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 19, 2026.

Transparency log

Release files / nepali_unicoder-0.3.0-py3-none-any.whl

Download URL nepali_unicoder-0.3.0-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e79cc7a9158911d1028bfadcf6ce082e30a7ade73ab4847e57980eaa44bcfe6e
BLAKE2b-256 checksum
How to use checksums
81f0c27195b63fc5793d4d393fc91091d50e88b854203635b49c61ca15964cea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 19, 2026.

Transparency log

Security for nepali-unicoder 0.3.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 nepali_unicoder-0.3.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 Nov 19, 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