Skip to main content

len_sentence

A Python library for counting words and characters in sentences across different languages and writing systems.

Overview

len_sentence provides intelligent sentence length counting that adapts to different languages and writing systems. It uses ISO15924 script codes to determine the appropriate counting method for each language, handling everything from space-separated languages like English to character-based languages like Chinese and Japanese.

Features

  • Multi-language support: Handles various writing systems including Latin, Chinese (Traditional/Simplified), Japanese, Thai, Khmer, Myanmar, Tibetan, and more
  • ISO15924 compliance: Uses standard 4-letter script codes for language identification
  • Special character handling: Properly processes numbers, punctuation, and language-specific separators
  • Intelligent counting: Automatically switches between word counting and character counting based on the script type

Installation

pip install len_sentence

Supported Language Scripts

The goal of the script is able to count the words from all the langauge of the world.

API Reference

count_sentence(sentence, lang_code)

Count the number of words or characters in a sentence based on the language script.

Parameters:

  • sentence (str): The sentence to count
  • lang_code (str): 4-letter ISO15924 script code, limited support for 2 letters ISO639-1 code

Returns:

  • int: Number of words or characters in the sentence

Raises:

  • ValueError: If the language code is not valid

Examples

from len_sentence import count_sentence

# Different scripts, different counting methods
count_sentence("Hello world!", "Latn")
count_sentence("你好世界", "Hans")
count_sentence("こんにちは", "Jpan")
count_sentence("བཀྲ་ཤིས་བདེ་ལེགས", "Tibt")
count_sentence("مرحبا بالعالم", "Arab")
count_sentence("Привет мир", "Cyrl")

Development

Setup

git clone <repository-url>
cd len-sentence
pip install -e .

Building and Publishing

python setup.py sdist bdist_wheel
twine upload dist/*

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.

Author

JackyHe398
Email: hekinghung@gmail.com


Note: This library uses ISO15924 script codes. For a complete list of supported scripts, refer to the Unicode Script Codes specification.

Metadata

Release files for len-sentence 0.1.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 len-sentence 0.1.1
File Size Uploaded
len_sentence-0.1.1.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for len-sentence 0.1.1
File Interpreter ABI Platform
len_sentence-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.7 kB

Release files / len_sentence-0.1.1.tar.gz

Download URL len_sentence-0.1.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
5fbe5b683587231995855394d7d80be1ae074bae2bf626058ad5e6270d1f1f41
BLAKE2b-256 checksum
How to use checksums
09103fd0cef04a1a1f9a652db0cf29fdc2156d58d87fc245ef4ba44417b6f5f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Sep 18, 2025.

Transparency log

Release files / len_sentence-0.1.1-py3-none-any.whl

Download URL len_sentence-0.1.1-py3-none-any.whl
Size 4.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2da9466cb0168fbb7c667d787fca613a2ea2f9878be016a6d2fe2c2e203da483
BLAKE2b-256 checksum
How to use checksums
d3096d77eff1243d2dfd1b57eccf0cadafaf06d8c4b9d5dfb4b60630878281fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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 Sep 18, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.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