Skip to main content

सन्देश Unicode

CI PyPI version Python Versions License Code Coverage

Efficient 1-Byte Encoding for Nepali Text — सन्देश encodes Nepali Unicode characters as single bytes instead of the 3-byte UTF-8 representation, achieving ~66% size reduction for pure Nepali text.

Metric UTF-8 सन्देश Savings
Pure Nepali 3 bytes/ch 1 byte/ch ~66%
Mixed Nepali+English varies varies ~40-50%
ASCII only 1 byte/ch 1 byte/ch 0%

Installation

pip install sandesh-unicode

For development:

pip install "sandesh-unicode[dev]"

Quick Start

CLI

# Encode Nepali text
sandesh encode "सन्देश"
# Output: b'\xaa\x9e\x9c\xb2\xa8'

# Decode bytes back to text
echo -ne '\xaa\x9e\x9c\xb2\xa8' | sandesh decode
# Output: सन्देश

# Show compression statistics
sandesh stats "सन्देश नेपाल"

# Encode/decode files
sandesh encode-file input.txt output.sndsh
sandesh decode-file output.sndsh decoded.txt

# View mapping table
sandesh table

# Package info
sandesh info

Python API

from sandesh_unicode import encode, decode, get_compression_ratio

# Basic encode/decode
encoded = encode("सन्देश")
print(encoded)           # b'\xaa\x9e\x9c\xb2\xa8'
decoded = decode(encoded)
print(decoded)           # सन्देश

# Mixed Nepali-English text
encoded = encode("नमस्ते नेपाल")
decoded = decode(encoded)
print(decoded)           # नमस्ते नेपाल

# Compression statistics
stats = get_compression_ratio("सन्देश")
print(f"Saved {stats['savings_percent']:.1f}%")  # Saved ~66.7%

# Permissive mode (skip unsupported characters)
encoded = encode("Hello सन्देश 中文", strict=False)

# File operations
from sandesh_unicode import encode_file, decode_file
encode_file("nepali.txt", "nepali.sndsh")
decode_file("nepali.sndsh", "nepali_decoded.txt")

# Validation
from sandesh_unicode import is_sandesh_encoded, validate
data = encode("सन्देश")
print(is_sandesh_encoded(data))   # True
errors = validate(data)
print(len(errors))                # 0

Architecture

┌─────────────┐     encode()     ┌──────────────┐
│  Unicode     │ ──────────────→ │  1-byte code  │
│  (UTF-8)     │ ←────────────── │  (0x80-0xFF)  │
│  3 bytes/ch  │     decode()    │  1 byte/ch    │
└─────────────┘                  └──────────────┘
     │                                │
     │ UTF-8 preserved for ASCII      │ ASCII passthrough
     │ (0x00-0x7F)                    │ (0x00-0x7F)
     └────────────────────────────────┘

Memory Layout

Range Category Count
0x00-0x7F ASCII (passthrough) 128
0x80-0x8A Vowels (अ-औ) 11
0x8B-0xAB Consonants (क-ह) 33
0xAC-0xB6 Matras/Vowel signs 11
0xB7-0xBA Special signs 4
0xBB-0xBC Punctuation 2
0xBE-0xC7 Nepali digits (०-९) 10
0xC8-0xFF Common conjuncts 56

Use Cases

  • Database storage: Store Nepali text using 66% less space
  • File compression: Compress .txt files containing Nepali text
  • Network transfer: Reduce bandwidth for Nepali text payloads
  • Embedded systems: Efficient storage on memory-constrained devices
  • APIs: Optimize Nepali text in REST/GraphQL payloads

See the examples/ directory for backend (FastAPI) and frontend (JavaScript) implementations.


Development

# Clone and install with dev dependencies
git clone https://github.com/sandesh-unicode/sandesh-unicode.git
cd sandesh-unicode
pip install -e ".[dev]"

# Run tests
pytest

# Run tests with coverage
pytest --cov=sandesh_unicode --cov-report=term

# Format code
black src/ tests/
isort --profile black src/ tests/

# Run pre-commit hooks
pre-commit run --all-files

Project Structure

sandesh-unicode/
├── src/
│   └── sandesh_unicode/
│       ├── __init__.py      # Public API exports
│       ├── tables.py         # Character mapping tables
│       ├── encoder.py        # Encode Unicode → सन्देश bytes
│       ├── decoder.py        # Decode सन्देश bytes → Unicode
│       ├── exceptions.py     # Custom exception hierarchy
│       └── cli.py            # Command-line interface
├── tests/
│   └── test_sandesh.py       # Comprehensive test suite
├── examples/
│   ├── backend/              # FastAPI storage API example
│   └── frontend/             # Browser-based encoder/decoder
├── pyproject.toml            # Build & tool configuration
└── .github/workflows/ci.yml  # CI pipeline (3 OS × 6 Python versions)

Limitations

  • Ecosystem-dependent: Only works within systems using this library
  • Display-agnostic: Must decode to Unicode for standard display
  • Not a Unicode replacement: Internal compression scheme only
  • Nepali-only: Currently supports Devanagari Nepali script

License

MIT

Release files for sandesh-unicode 1.0.1

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

Source distribution (sdist)

Source distribution for sandesh-unicode 1.0.1
File Size Uploaded
sandesh_unicode-1.0.1.tar.gz 27.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sandesh-unicode 1.0.1
File Interpreter ABI Platform
sandesh_unicode-1.0.1-cp314-cp314-win_amd64.whl CPython 3.14 CPython 3.14 Windows x86-64 Details

Total release size: 60.8 kB

Release files / sandesh_unicode-1.0.1.tar.gz

Download URL sandesh_unicode-1.0.1.tar.gz
Size 27.4 kB
Tags Source
SHA-256 checksum
How to use checksums
299daf724351813c03dcf213f4db12c98c888808a29ee5237fef65a04a2d8ec6
BLAKE2b-256 checksum
How to use checksums
0b00973ea58664cb52b8c35d80c3e66d9d5af6643930f613e716000a06c55c63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release files / sandesh_unicode-1.0.1-cp314-cp314-win_amd64.whl

Download URL sandesh_unicode-1.0.1-cp314-cp314-win_amd64.whl
Size 33.4 kB
Tags CPython 3.14 Windows x86-64
SHA-256 checksum
How to use checksums
61f0c53b20ac0d2e89d103fbf7387494ccd45e77b4cd0d20438e152e6659e617
BLAKE2b-256 checksum
How to use checksums
dcfbf683082e918a80d4643c0f1bd554224b46c8b7784b862064c63bcf3b9c8a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.5

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

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