A fast and simple Command Line Interface (CLI) tool to calculate the character length, byte count, or word count of a string. Built with Python, Typer, and managed with Poetry.
- Character Counting: Get the character length of a string (default).
- Byte Counting: Count the UTF-8 bytes of a string (useful for multi-byte characters/emojis).
- Word Counting: Count the number of whitespace-separated words in a string.
- Whitespace Trimming: Trim leading and trailing whitespace before calculation.
- Multiple Output Modes: Run one or multiple calculations simultaneously (using
length,bytes,words, orall).
Ensure you have Python 3.9+ installed.
-
Clone this repository:
git clone https://github.com/rudvfaden/textlen.git cd textlen -
Install the dependencies:
poetry install
If you have installed the package in editable mode or activated the virtual environment, you can run the CLI directly:
textlen "your string"Note: If the virtual environment is not activated, you can prepend poetry run:
poetry run textlen "your string"| Option | Short Flag | Description |
|---|---|---|
--trim |
-t |
Trim leading and trailing whitespace. |
--mode |
-m |
Metric(s) to calculate (length, bytes, words, all). Can be specified multiple times. Defaults to length. |
--help |
Show the help message and exit. |
textlen "Camila"Output:
String: Camila
Length: 6
textlen " hello world " --trimOutput:
String: hello world
Length: 11
textlen "café" --mode bytesOutput:
String: café
Bytes: 5
textlen "hello world from textlen" --mode wordsOutput:
String: hello world from textlen
Words: 4
textlen "test" --mode bytes --mode wordsOutput:
String: test
Bytes: 4
Words: 1
textlen "test" --mode allOutput:
String: test
Length: 4
Bytes: 4
Words: 1
We use pytest for unit testing. You can run all tests with:
poetry run pytesttextlen/main.py: Main entry point and CLI command logic.tests/test_main.py: Test suites checking various options and validation rules.