Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Sinling

A language processing toolkit for Sinhala (සිංහල).

PyPI version

Sinling 0.4 is in development. It is a redesign with a new API and is not compatible with 0.3. 0.4 pre-releases install only when you ask for them (pip install --pre sinling).

If your code uses the 0.3 API (SinhalaTokenizer, SinhalaStemmer, POSTagger, word_joiner, word_splitter, preprocess), pin the version: pip install "sinling<0.4", or sinling<0.4 in requirements.txt. The 0.3 documentation is in the 0.3.7 README.

Installation

pip install --pre sinling

Sinling 0.4 needs Python 3.11 or newer and has no dependencies.

Quick start

>>> import sinling

>>> sinling.normalize("\N{SINHALA VOWEL SIGN KOMBUVA}ගදර\N{NO-BREAK SPACE}යනවා")
'ගෙදර යනවා'

>>> print(" / ".join(sinling.aksharas("ශ්‍රී ලංකාව")))
ශ්‍රී /   / ලං / කා / ව

Normalization

Sinhala text reaches you in many encodings of the same words: typed in visual order, copied from PDFs, pasted with invisible characters. sinling.normalize() converts it to one canonical Unicode form. It applies these rules in order:

  1. Invisible characters — removes zero-width spaces, byte order marks, soft hyphens, word joiners and direction marks.
  2. Joiners — puts each zero-width joiner (ZWJ) where SLS 1134 expects it for yansaya, rakaransaya, repaya and touching letters, and drops stray ZWJ and ZWNJ. Joiners in emoji sequences are left alone.
  3. Doubled signs — two kombuvas typed for kombu deka become ෛ; the same for ෲ and ෳ.
  4. Visual order — moves a vowel sign typed before its consonant (ෙ + ක) after it.
  5. Vowel letters — replaces sequences such as අ + ා with ආ, following the Unicode Standard's list of sequences not to use.
  6. NFC — Unicode normalization, which merges two-part vowel signs such as ෙ + ා into ො.
  7. Whitespace — turns runs of spaces, tabs and other Unicode spaces into one space and trims each line. Line breaks are kept.

Two presets are available. "standard" (the default) is safe for display and storage. "search" also strips every ZWJ next to Sinhala letters, so spelling variants match. Turn a single rule off by name:

>>> sinling.normalize("ශ්‍රී", preset="search") == "ශ්රී"
True

>>> sinling.normalize("  \N{SINHALA VOWEL SIGN KOMBUVA}ගදර  ", reorder=False, whitespace="keep")
'  ෙගදර  '

The options are invisible, zwj ("canonical", "strip" or "keep"), doubled_signs, reorder, vowel_letters, nfc and whitespace ("collapse" or "keep").

Documents, pipelines and offsets

Task functions such as normalize() return plain values. To run several steps and keep everything, use a pipeline, which returns a Doc. A Doc keeps the original text, the working text and an alignment between them, so any result can be traced back to the input:

>>> nlp = sinling.pipeline(["normalize"])
>>> doc = nlp("\N{ZERO WIDTH SPACE}මම\N{NO-BREAK SPACE}\N{NO-BREAK SPACE}\N{SINHALA VOWEL SIGN KOMBUVA}ගදර")
>>> doc.text
'මම ගෙදර'
>>> start, end = doc.to_raw(3, 7)  # 'ගෙදර' in the normalized text
>>> doc.raw[start:end] == "\N{SINHALA VOWEL SIGN KOMBUVA}ගදර"
True

A Doc also holds tokens, sentences and labelled spans, and converts to and from JSON with doc.to_dict() and Doc.from_dict().

Backends and plugins

Each task can have several interchangeable backends, chosen with backend=:

>>> [(b.name, b.default) for b in sinling.backends("normalize")]
[('rules', True)]

Other packages can add backends without changes to Sinling, through the sinling.backends entry-point group. By convention they are published as sinling-<name>:

[project.entry-points."sinling.backends"]
"normalize.mybackend" = "sinling_mybackend:MyNormalizer"

A plugin is imported only when one of its backends is first used.

Resources and offline use

Larger models and dictionaries will be downloaded on first use, checked against a SHA-256 checksum and cached in ~/.cache/sinling. Set SINLING_HOME to use another directory, and SINLING_OFFLINE=1 to forbid downloads. Fetch a resource ahead of time with sinling.download(name). No resources are published yet.

Roadmap

0.4 is being built in milestones:

  • 0.4.0a1 — core API, Doc, pipelines, plugins, normalize() and akshara segmentation.
  • 0.4.0a2 — tokenization and stemming on the new core, legacy FM font to Unicode conversion, the first downloadable resources.
  • 0.4.0 — documentation in Sinhala and English, an evaluation harness, a stable API.

Development

pip install .
python -P -m unittest discover -s tests -t tests

The tests import the installed package, not the source tree. Every push is tested on Python 3.11 to 3.14.

License

Apache License 2.0. See LICENSE.

Metadata

Release files for sinling 0.4.0a1

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

Source distribution (sdist)

Source distribution for sinling 0.4.0a1
File Size Uploaded Provenance Actions
sinling-0.4.0a1.tar.gz 29.5 kB Without provenance Details for sinling-0.4.0a1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sinling 0.4.0a1
File Interpreter ABI Platform Actions
sinling-0.4.0a1-py3-none-any.whl Python 3 none any Details for sinling-0.4.0a1-py3-none-any.whl

Total release size: 53.0 kB

Release files / sinling-0.4.0a1.tar.gz

Download URL sinling-0.4.0a1.tar.gz
Size 29.5 kB
Tags Source
SHA-256 checksum
How to use checksums
97f8cc80e394917995e71264ce0143c14f46de6860e849d6353f067fc60595ba
BLAKE2b-256 checksum
How to use checksums
acf93b3999559903fc6ab51d542fc6745f0b6ebc047998bc4f45510eacaeaa9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / sinling-0.4.0a1-py3-none-any.whl

Download URL sinling-0.4.0a1-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e5933e54274ac914711231f3ca539c6e73a05e293cefdf70cf6ffd6b20e2087
BLAKE2b-256 checksum
How to use checksums
8b05041594b6249cf5f02a3762b5e42ad48262883adbf16a76180f641dd56e62
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.19 {"installer":{"name":"uv","version":"0.11.19","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for sinling 0.4.0a1

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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