# Python sentiment analysis libraries

Python sentiment analysis libraries score text as positive, negative, or neutral. A lexicon-based scorer applies a fixed dictionary and rules rather than a trained neural model. These libraries let support tools, social media monitors, and AI agents measure how people feel about a product.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [Transformers](#transformers) | 119.8M | 168.9K | Nov 2026 | Apache-2.0 |
| [NLTK](#nltk) | 48.3M | 14.8K | Oct 2026 | Apache-2.0 |
| [TextBlob](#textblob) | 3.2M | 9.6K | Jul 2026 | MIT |
| [VADER](#vader) | 1.2M | 5.1K | May 2020 | MIT |
| [Stanza](#stanza) | 1.0M | 7.9K | Nov 2026 | Apache-2.0 |
| [Polyglot](#polyglot) | 87.4K | 2.4K | Jul 2016 | GPLv3 |
| [Flair](#flair) | 65.0K | 14.4K | Feb 2025 | MIT |
| [pysentimiento](#pysentimiento) | 6.9K | 665 | Mar 2024 | Custom non-commercial/research-only |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[Transformers](#transformers) has the most monthly downloads in this comparison, at 119.8M, a count that covers every model task in the library.

## Capabilities

| Library | Non-English ready sentiment | Separate subjectivity score |
| --- | --- | --- |
| [Transformers](#transformers) | Yes | No |
| [NLTK](#nltk) | No | No |
| [TextBlob](#textblob) | No | Yes |
| [VADER](#vader) | No | No |
| [Stanza](#stanza) | Yes | No |
| [Polyglot](#polyglot) | Yes | No |
| [Flair](#flair) | No | No |
| [pysentimiento](#pysentimiento) | Yes | No |

## Libraries

### Transformers

[GitHub](https://github.com/huggingface/transformers) · [PyPI](https://pypi.org/project/transformers) · [Docs](https://huggingface.co/docs/transformers/en/tasks/sequence_classification)

Runs pretrained sentiment classifiers and supports fine-tuning on labeled datasets.

- Downloads / mo: 119.8M
- Stars: 168.9K
- Last release: 5.23.0
- License: Apache-2.0
- Capabilities: [From the Transformers docs](https://huggingface.co/docs/transformers/en/tasks/sequence_classification)

**Strengths**

- **Fine-tunes for a specific classification task.** Adapt a pretrained model using labeled examples from the target task.
- **Batches sentiment inference.** Pass lists, datasets, or generators to a pipeline with batching.

**Watch out for**

- **Long inputs need length handling.** Truncate or split inputs that exceed the model’s accepted sequence length.
- **Large batches can exhaust memory.** Reduce batch size when inference runs out of memory.

```sh
pip install "transformers[torch]"
```

**guia-matthieu/clawfu-skills** (150 stars)

[guia-matthieu/clawfu-skills](https://github.com/guia-matthieu/clawfu-skills) 

```python
def get_sentiment_transformer(text: str) -> dict:
    """Get sentiment using transformers (if available)."""
    try:
        from transformers import pipeline
        classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-finetuned-sst-2-english")
        result = classifier(text[:512])[0]  # Limit text length

        score = result['score'] if result['label'] == 'POSITIVE' else 1 - result['score']

        return {
            'score': score,
            'sentiment': 'positive' if score > 0.6 else ('negative' if score < 0.4 else 'neutral'),
            'label': get_label(score),
            'model': 'distilbert'
        }
    except ImportError:
        return get_sentiment_vader(text)

```

[skills/analytics/sentiment-analyzer/scripts/main.py](https://github.com/guia-matthieu/clawfu-skills/blob/4108f5c010ccaa8b5707fa05ca1d888ae167e548/skills/analytics/sentiment-analyzer/scripts/main.py#L64-L80) · [More projects using Transformers →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20that%20use%20transformers&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from transformers import pipeline
classifier = pipeline(model="distilbert/distilbert-base-uncased-finetuned-sst-2-english")
classifier("This movie is disgustingly good !")

```

From [text_classification.py](https://github.com/huggingface/transformers/blob/v5.23.0/src/transformers/pipelines/text_classification.py)

### NLTK

[GitHub](https://github.com/nltk/nltk) · [PyPI](https://pypi.org/project/nltk) · [Docs](https://www.nltk.org/howto/sentiment.html)

Provides a natural language toolkit.

- Downloads / mo: 48.3M
- Stars: 14.8K
- Last release: 3.10.4
- License: Apache-2.0
- Capabilities: [From the NLTK docs](https://www.nltk.org/howto/sentiment.html)

```sh
pip install nltk
```

**sloria/TextBlob** (9.6K stars)

[sloria/TextBlob](https://github.com/sloria/TextBlob) 

```python
def analyze(self, text):
    """Return the sentiment as a named tuple of the form:
    ``Sentiment(classification, p_pos, p_neg)``
    """
    # Lazily train the classifier
    super().analyze(text)
    tokens = word_tokenize(text, include_punc=False)
    filtered = (t.lower() for t in tokens if len(t) >= 3)
    feats = self.feature_extractor(filtered)
    prob_dist = self._classifier.prob_classify(feats)
    return self.RETURN_TYPE(
        classification=prob_dist.max(),
        p_pos=prob_dist.prob("pos"),
        p_neg=prob_dist.prob("neg"),
    )

```

[src/textblob/en/sentiments.py](https://github.com/sloria/TextBlob/blob/629e60e0b1cfc5fa6d7df4bed9ccc7b98ac8917d/src/textblob/en/sentiments.py#L94-L108) · [More projects using NLTK →](https://dashboard.exa.ai/playground/search?q=nltk%20GitHub%20projects)

**Quickstart**

```python
import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
nltk.download("vader_lexicon")
sid = SentimentIntensityAnalyzer()
sid.polarity_scores("VADER is smart, handsome, and funny.")

```

From [sentiment.doctest](https://www.nltk.org/howto/sentiment.html)

### TextBlob

[GitHub](https://github.com/sloria/TextBlob) · [PyPI](https://pypi.org/project/textblob) · [Docs](https://textblob.readthedocs.io/en/stable/quickstart.html)

Returns polarity and subjectivity scores and supports custom text classifiers.

- Downloads / mo: 3.2M
- Stars: 9.6K
- Last release: 0.20.1
- License: MIT
- Capabilities: [From the TextBlob docs](https://textblob.readthedocs.io/en/stable/quickstart.html)

**Strengths**

- **Separates polarity and subjectivity.** Read sentiment direction and subjectivity as separate values.
- **Trains custom text classifiers.** Train a classifier on custom labeled text examples.

**Watch out for**

- **Analyzer choice changes returned values.** NaiveBayesAnalyzer returns class probabilities instead of polarity and subjectivity.
- **Optional analyzer uses movie reviews.** The built-in NaiveBayesAnalyzer is trained on a movie-review corpus.

```sh
pip install -U textblob
```

**Roibal/Cryptocurrency-Trading-Bots-Python-Beginner-Advance** (1.4K stars)

[Roibal/Cryptocurrency-Trading-Bots-Python-Beginner-Advance](https://github.com/Roibal/Cryptocurrency-Trading-Bots-Python-Beginner-Advance) 

```python
def get_tweet_sentiment(self, tweet):
    '''
    Utility function to classify sentiment of passed tweet
    using textblob's sentiment method
    '''
    # create TextBlob object of passed tweet text
    analysis = TextBlob(self.clean_tweet(tweet))
    # set sentiment
    if analysis.sentiment.polarity > 0:
        return 'positive'
    elif analysis.sentiment.polarity == 0:
        return 'neutral'
    else:
        return 'negative'

```

[Crypto-Trading-Bots/Crypto_Sentiment_Analysis_SocialMedia_Bot.py](https://github.com/Roibal/Cryptocurrency-Trading-Bots-Python-Beginner-Advance/blob/6cd9f639ac7f9d914d556738ca3aeeef53618146/Crypto-Trading-Bots/Crypto_Sentiment_Analysis_SocialMedia_Bot.py#L79-L92) · [More projects using TextBlob →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20that%20use%20textblob&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from textblob import TextBlob
testimonial = TextBlob("Textblob is amazingly simple to use. What great fun!")
testimonial.sentiment

```

From [classifiers.html](https://textblob.readthedocs.io/en/stable/quickstart.html)

### VADER

[GitHub](https://github.com/cjhutto/vaderSentiment) · [PyPI](https://pypi.org/project/vaderSentiment) · [Docs](https://github.com/cjhutto/vaderSentiment/blob/master/README.rst)

Scores sentiment with a lexicon and rules designed for social-media language.

- Downloads / mo: 1.2M
- Stars: 5.1K
- Last release: 3.3.2
- License: MIT
- Capabilities: [From the VADER docs](https://github.com/cjhutto/vaderSentiment/blob/master/README.rst)

**Strengths**

- **Handles informal text signals.** Rules account for punctuation, emphasis, negation, and contrastive conjunctions.
- **Returns a composite sentiment score.** Use compound for the normalized score after lexical and rule adjustments.

**Watch out for**

- **Non-English examples use translation.** Translate non-English inputs separately; VADER does not provide its own translator.
- **Compound and category scores differ.** Use compound for overall sentiment; category ratios omit intensity rules.

```sh
pip install vaderSentiment
```

**shirosaidev/stocksight** (2.6K stars)

[shirosaidev/stocksight](https://github.com/shirosaidev/stocksight) 

```python
def sentiment_analysis(text):
    """Determine if sentiment is positive, negative, or neutral
    algorithm to figure out if sentiment is positive, negative or neutral
    uses sentiment polarity from TextBlob, VADER Sentiment and
    sentiment from text-processing URL
    could be made better :)
    """

    # pass text into sentiment url
    if args.websentiment:
        ret = get_sentiment_from_url(text, sentimentURL)
        if ret is None:
            sentiment_url = None
        else:
            sentiment_url, neg_url, pos_url, neu_url = ret
    else:
        sentiment_url = None

    # pass text into TextBlob
    text_tb = TextBlob(text)

    # pass text into VADER Sentiment
    analyzer = SentimentIntensityAnalyzer()
    text_vs = analyzer.polarity_scores(text)

    # determine sentiment from our sources
    if sentiment_url is None:
        if text_tb.sentiment.polarity < 0 and text_vs['compound'] <= -0.05:
            sentiment = "negative"
        elif text_tb.sentiment.polarity > 0 and text_vs['compound'] >= 0.05:
            sentiment = "positive"
        else:
            sentiment = "neutral"
    else:
        if text_tb.sentiment.polarity < 0 and text_vs['compound'] <= -0.05 and sentiment_url == "negative":
            sentiment = "negative"
        elif text_tb.sentiment.polarity > 0 and text_vs['compound'] >= 0.05 and sentiment_url == "positive":
            sentiment = "positive"
        else:
            sentiment = "neutral"

    # calculate average polarity from TextBlob and VADER
    polarity = (text_tb.sentiment.polarity + text_vs['compound']) / 2

    # output sentiment polarity
    print("************")
    print("Sentiment Polarity: " + str(round(polarity, 3)))

    # output sentiment subjectivity (TextBlob)
    print("Sentiment Subjectivity: " + str(round(text_tb.sentiment.subjectivity, 3)))

    # output sentiment
    print("Sentiment (url): " + str(sentiment_url))
    print("Sentiment (algorithm): " + str(sentiment))
    print("Overall sentiment (textblob): ", text_tb.sentiment) 
    print("Overall sentiment (vader): ", text_vs) 
    print("sentence was rated as ", round(text_vs['neg']*100, 3), "% Negative") 
    print("sentence was rated as ", round(text_vs['neu']*100, 3), "% Neutral") 
    print("sentence was rated as ", round(text_vs['pos']*100, 3), "% Positive") 
    print("************")

    return polarity, text_tb.sentiment.subjectivity, sentiment

```

[sentiment.py](https://github.com/shirosaidev/stocksight/blob/580d35876f2d9c0cb905b723c664f053abdd567c/sentiment.py#L467-L528) · [More projects using VADER →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20that%20use%20vaderSentiment&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**guia-matthieu/clawfu-skills** (150 stars)

[guia-matthieu/clawfu-skills](https://github.com/guia-matthieu/clawfu-skills) 

```python
def get_sentiment_vader(text: str) -> dict:
    """Get sentiment using VADER (if available)."""
    try:
        from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
        analyzer = SentimentIntensityAnalyzer()
        scores = analyzer.polarity_scores(text)
        compound = (scores['compound'] + 1) / 2  # Normalize to 0-1

        return {
            'score': compound,
            'sentiment': 'positive' if compound > 0.6 else ('negative' if compound < 0.4 else 'neutral'),
            'label': get_label(compound),
            'details': scores
        }
    except ImportError:
        return get_sentiment_simple(text)

```

[skills/analytics/sentiment-analyzer/scripts/main.py](https://github.com/guia-matthieu/clawfu-skills/blob/4108f5c010ccaa8b5707fa05ca1d888ae167e548/skills/analytics/sentiment-analyzer/scripts/main.py#L46-L61) · [More projects using VADER →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20that%20use%20vaderSentiment&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
analyzer = SentimentIntensityAnalyzer()
analyzer.polarity_scores("VADER is smart, handsome, and funny.")

```

From [README.rst](https://github.com/cjhutto/vaderSentiment/blob/master/README.rst)

### Stanza

[GitHub](https://github.com/stanfordnlp/stanza) · [PyPI](https://pypi.org/project/stanza) · [Docs](https://stanfordnlp.github.io/stanza/sentiment.html)

Processes text in many human languages.

- Downloads / mo: 1.0M
- Stars: 7.9K
- Last release: 1.15.1
- License: Apache-2.0
- Capabilities: [From the Stanza docs](https://stanfordnlp.github.io/stanza/sentiment.html)

```sh
pip install stanza
```

**Quickstart**

```python
import stanza
nlp = stanza.Pipeline(lang='en', processors='tokenize,sentiment')
doc = nlp('I hate that they banned Mox Opal')

```

From [sentiment.md](https://stanfordnlp.github.io/stanza/sentiment.html) · [Find projects using Stanza →](https://dashboard.exa.ai/playground/search?q=stanza%20GitHub%20projects)

### Polyglot

[GitHub](https://github.com/aboSamoor/polyglot) · [PyPI](https://pypi.org/project/polyglot) · [Docs](https://polyglot.readthedocs.io/en/latest/Sentiment.html)

Runs a multilingual natural language pipeline.

- Downloads / mo: 87.4K
- Stars: 2.4K
- Last release: 16.7.4
- License: GPLv3
- Capabilities: [From the Polyglot docs](https://polyglot.readthedocs.io/en/latest/Sentiment.html)

```sh
pip install polyglot
```

**Quickstart**

```python
from polyglot.text import Text
text = Text("The movie was really good.")
text.words[4].polarity

```

From [Sentiment.ipynb](https://polyglot.readthedocs.io/en/latest/Sentiment.html) · [Find projects using Polyglot →](https://dashboard.exa.ai/playground/search?q=polyglot%20GitHub%20projects)

### Flair

[GitHub](https://github.com/flairNLP/flair) · [PyPI](https://pypi.org/project/flair) · [Docs](https://flairnlp.github.io/docs/tutorial-training/how-to-train-text-classifier)

Loads sentiment models and trains text classifiers with configurable embeddings.

- Downloads / mo: 65.0K
- Stars: 14.4K
- Last release: 0.15.1
- License: MIT
- Capabilities: [From the Flair docs](https://flairnlp.github.io/docs/tutorial-training/how-to-train-text-classifier)

**Strengths**

- **Trains custom sentiment models.** Train a text classifier with a custom corpus and label dictionary.
- **Supports minibatched predictions.** Pass data points to predict() and configure mini_batch_size.

**Watch out for**

- **Standard sentiment model targets English.** The standard sentiment checkpoint classifies English movie and product reviews.
- **Standard sentiment labels are binary.** The standard sentiment models predict positive or negative, without a neutral label.

```sh
pip install flair
```

**prrao87/fine-grained-sentiment** (171 stars)

[prrao87/fine-grained-sentiment](https://github.com/prrao87/fine-grained-sentiment) 

```python
def score(self, text: str) -> int:
    from flair.data import Sentence
    doc = Sentence(text)
    self.model.predict(doc)
    pred = int(doc.labels[0].value)
    return pred

```

[classifiers.py](https://github.com/prrao87/fine-grained-sentiment/blob/a4401669eecbe9dda494faf36afe1e6a0b065a38/classifiers.py#L191-L196) · [More projects using Flair →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20that%20use%20flair&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
from flair.data import Sentence
from flair.nn import Classifier

# make a sentence
sentence = Sentence('I love Berlin .')

# load the NER tagger
tagger = Classifier.load('sentiment')

# run NER over sentence
tagger.predict(sentence)

# print the sentence with all annotations
print(sentence)

```

From [README.md](https://github.com/flairNLP/flair/blob/master/README.md)

### pysentimiento

[GitHub](https://github.com/pysentimiento/pysentimiento) · [PyPI](https://pypi.org/project/pysentimiento)

Runs Transformer models for social NLP tasks.

- Downloads / mo: 6.9K
- Stars: 665
- Last release: 0.7.3
- License: Custom non-commercial/research-only
- Capabilities: [From the pysentimiento docs](https://github.com/pysentimiento/pysentimiento)

```sh
pip install pysentimiento
```

**Quickstart**

```python
from pysentimiento import create_analyzer
analyzer = create_analyzer(task="sentiment", lang="es")
analyzer.predict("Qué gran jugador es Messi")

```

From [README.md](https://raw.githubusercontent.com/pysentimiento/pysentimiento/master/README.md) · [Find projects using pysentimiento →](https://dashboard.exa.ai/playground/search?q=pysentimiento%20GitHub%20projects)

## FAQ

### Which Python sentiment analysis library should I use?

[Transformers](#transformers) suits applications that run or fine-tune pretrained sentiment classifiers. [VADER](#vader) suits social media text scored by a lexicon and rules. [TextBlob](#textblob) suits code that needs separate polarity and subjectivity scores.

### What is VADER sentiment analysis?

[VADER](#vader) is a lexicon and rule-based sentiment analysis tool attuned to sentiments expressed in social media. It returns a composite score alongside its category scores.

### TextBlob vs VADER: which should I use?

[TextBlob](#textblob) returns separate polarity and subjectivity scores and trains custom text classifiers. [VADER](#vader) scores informal social media text with a lexicon and rules.

### What is Flair?

[Flair](#flair) loads sentiment models and trains text classifiers with configurable embeddings. Its standard sentiment model targets English with binary labels.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Python sentiment analysis libraries TextBlob VADER Transformers Flair polarity subjectivity training batching examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
