Textstat

0.7.13 · active · verified Sun Apr 12

Textstat is a Python library (version 0.7.13) for calculating a wide array of statistical features from text. It provides utilities for determining readability, complexity, and grade level using various metrics like Flesch Reading Ease, Gunning Fog, and SMOG Index. The library is actively maintained with regular patch releases addressing bug fixes and minor improvements.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `textstat` to calculate the Flesch Reading Ease score, determine an approximate readability grade level, and count syllables in a given text. Note that for English (en_US) syllable counting, `nltk` and its 'cmudict' corpus might be required.

import textstat

text = (
    "Playing games has always been thought to be important to "
    "the development of well-balanced and creative children; "
    "however, what part, if any, they should play in the lives "
    "of adults has never been researched that deeply. I believe "
    "that playing games is every bit as important for adults "
    "as for children. Not only is taking time out to play games "
    "with our children and other adults valuable to building "
    "interpersonal relationships but is also a wonderful way "
    "to release built up tension."
)

# Calculate Flesch Reading Ease score
flesch_score = textstat.flesch_reading_ease(text)
print(f"Flesch Reading Ease: {flesch_score}")

# Get the overall readability grade level
grade_level = textstat.text_standard(text)
print(f"Readability Grade Level: {grade_level}")

# Syllable count (may require NLTK cmudict download for en_US)
syllable_count = textstat.syllable_count(text)
print(f"Syllable Count: {syllable_count}")

# If NLTK cmudict is not downloaded for syllable_count:
# import nltk
# nltk.download('cmudict')

view raw JSON →