
Textstat is a Python library that enables you to calculate various readability and text complexity measures.
In our previous articles, we learned how to do general text statistics, interpret readability metrics, and analyze text properties. Now, let’s create something more interactive: a real-time readability checker.
Why a Real-Time Readability Checker?
Most of our previous examples have focused on static text files or blocks of text. However, a real-time checker can be helpful if:
- you want an on-the-fly tool for writing improvement
- you’re teaching writing skills and want students to test text clarity quickly
- you’re building a simple command-line or web-based text editor that offers immediate feedback
This article will show how to build a basic terminal application that continually prompts for text and displays readability metrics in real time. You can expand this to a GUI or web application later.
As a reminder, you can find more details on the metrics in these previous posts:
- Getting Started with Basic Text Statistics Using Textstat
- Calculating and Interpreting Readability Metrics with Textstat
- Performing Statistical Analysis of Text Properties with Textstat
Let’s take a look at the implementation process in the following 4 simple steps.
Step 1: Basic Setup
Before we begin, you’ll need to have Python installed along with textstat.
pip install textstat
We’ll also import re for basic cleaning for real-time user input.
Step 2: Create a Helper Function
Let’s create a function to quickly grab the most common readability metrics we’ve introduced in this series.
import textstat
import re
def get_readability_metrics(text):
return {
'flesch_ease': textstat.flesch_reading_ease(text),
'flesch_grade': textstat.flesch_kincaid_grade(text),
'gunning_fog': textstat.gunning_fog(text),
'smog': textstat.smog_index(text),
'automated_index': textstat.automated_readability_index(text),
}
Step 3: Build the Real-Time Loop
Our terminal application will continually prompt the user for new text input. As soon as the user hits Enter, we’ll display the updated readability metrics.
def run_readability_checker():
print("Real-Time Readability Checker. Type your text (or 'quit' to exit):")
while True:
user_input = input("\nEnter text: ")
if user_input.lower() == 'quit':
print("Exiting the readability checker.")
break
# Optional cleaning
cleaned_text = re.sub(r'\s+', ' ', user_input.strip())
metrics = get_readability_metrics(cleaned_text)
print("\nReadability metrics:")
for metric, score in metrics.items():
print(f"{metric}: {score:.2f}")
Step 4: Running the Application
After defining the above functions in a Python script file (e.g., readability_checker.py), and adding a function call to the bottom of the script such as this:
run_readability_checker()
you can now run that file from your terminal like so:
python readability_checker.py
You should see the prompt as outlined in the run_readability_checker() function, and once you enter some text and hit Enter, you should see something such as this:
Real-Time Readability Checker. Type your text (or 'quit' to exit): Enter text: The quick brown fox jumped over the lazy dog. It paused to look back, wagging its tail with satisfaction. Across the field, a group of children played under the shade of a large oak tree. Laughter filled the air, blending with the chirping of nearby birds. Readability metrics: flesch_ease: 93.64 flesch_grade: 3.10 gunning_fog: 5.47 smog: 6.00 automated_index: 5.90 Enter text:
Now you can supply different text each time to see how the metrics adjust in real time.
As you test out the interactive command line app, or any adaptation you create on your own, make sure that you don’t test with very short texts, as readability scores become unreliable under ~50 words. Encourage users to type enough content. Also guard against excessive punctuation or symbols; if your input is noisy, clean it before passing to textstat. Also keep in mind that every readability formula measures slightly different aspects of text complexity.
Wrapping Up
You can customize this further by creating a simple GUI with frameworks like tkinter or PyQt, or instead build a small web app with Flask or Streamlit if that suits you better. You could also expand the metrics to include additional textstat functionalities, including more of what was presented in previous articles.
A real-time readability checker is a fun way to experiment with textstat — and you can quickly see how changes in wording affect complexity. If you’re an educator, content creator, or software developer, this approach offers a practical way to ensure your writing meets a target audience’s reading level. With just a few lines of Python code, you can get immediate feedback on various aspects of your text quality.
