1-byte encoding for Nepali text - 66% smaller than UTF-8
Project description
सन्देश Unicode
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
.txtfiles 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
Project details
Release history Release notifications | RSS feed
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 sandesh_unicode-1.0.1.tar.gz.
File metadata
- Download URL: sandesh_unicode-1.0.1.tar.gz
- Upload date:
- Size: 27.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
299daf724351813c03dcf213f4db12c98c888808a29ee5237fef65a04a2d8ec6
|
|
| MD5 |
5b2335fede33e9c6a62a07cae75a6644
|
|
| BLAKE2b-256 |
0b00973ea58664cb52b8c35d80c3e66d9d5af6643930f613e716000a06c55c63
|
File details
Details for the file sandesh_unicode-1.0.1-cp314-cp314-win_amd64.whl.
File metadata
- Download URL: sandesh_unicode-1.0.1-cp314-cp314-win_amd64.whl
- Upload date:
- Size: 33.4 kB
- Tags: CPython 3.14, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61f0c53b20ac0d2e89d103fbf7387494ccd45e77b4cd0d20438e152e6659e617
|
|
| MD5 |
7dbda5b400ad2df0dbddface86fa2b4b
|
|
| BLAKE2b-256 |
dcfbf683082e918a80d4643c0f1bd554224b46c8b7784b862064c63bcf3b9c8a
|