Skip to main content

A modern sentiment analysis library with optional LLM support

Project description

🎭 Sentimetric - Modern Sentiment Analysis

PyPI version Python 3.8+ License: MIT

Sentimetric is a modern, fast, and accurate sentiment analysis library with optional LLM support for complex emotions, sarcasm, and nuanced context.

✨ Features

  • Fast Rule-Based Analysis
  • Multi-LLM Support (OpenAI, Google Gemini, Anthropic Claude, Cohere, Hugging Face, DeepSeek)
  • Cost-Aware Model Selection with automatic fallback to cheaper models
  • Batch Processing with parallel execution
  • High Accuracy with modern slang & emojis
  • Simple API: from sentimetric import analyze

🚀 Quick Start

Installation

pip install sentimetric

Basic Usage

from sentimetric import analyze

# Quick analysis
result = analyze("This is amazing!")
print(result)
# Example output: SentimentResult(polarity=+0.90, category='positive', confidence=0.85)

Multi-LLM Usage

Sentimetric now supports multiple LLM providers! Choose from OpenAI, Google Gemini, Anthropic Claude, Cohere, or Hugging Face.

Basic LLM Usage

from sentimetric import LLMAnalyzer

# Auto-selects the best available provider
analyzer = LLMAnalyzer()  # Automatically detects available API keys

# Or specify a provider
analyzer = LLMAnalyzer(provider="openai", model="gpt-3.5-turbo")
# analyzer = LLMAnalyzer(provider="google", model="gemini-1.5-flash")
# analyzer = LLMAnalyzer(provider="anthropic", model="claude-3-haiku-20240307")
# analyzer = LLMAnalyzer(provider="cohere", model="command")
# analyzer = LLMAnalyzer(provider="huggingface", model="mistralai/Mixtral-8x7B-Instruct-v0.1")
# analyzer = LLMAnalyzer(provider="deepseek", model="deepseek-chat")

result = analyzer.analyze("Oh great, another bug 🙄")
print(result.category)  # 'negative' (catches sarcasm)
print(result.reasoning) # Explanation from the LLM

Environment Variables

Set your API keys as environment variables:

# OpenAI
export OPENAI_API_KEY="your-openai-key"

# Google Gemini
export GOOGLE_API_KEY="your-google-key"

# Anthropic Claude
export ANTHROPIC_API_KEY="your-anthropic-key"

# Cohere
export COHERE_API_KEY="your-cohere-key"

# Hugging Face
export HUGGINGFACE_API_KEY="your-hf-key"

# DeepSeek
export DEEPSEEK_API_KEY="your-deepseek-key"

Cost-Aware Features

# Auto-select cheapest model
analyzer = LLMAnalyzer(provider="openai", model="auto")  # Uses gpt-3.5-turbo

# Fallback to cheaper models on failure
analyzer = LLMAnalyzer(
    provider="openai",
    model="gpt-4",
    fallback_to_cheaper=True  # Falls back to gpt-3.5-turbo if gpt-4 fails
)

📚 Examples

See examples.py for comprehensive usage examples. Use python examples.py to run them locally.

🛠️ API Reference

Core Functions

  • analyze(text, method='auto') - Quick sentiment analysis
  • analyze_batch(texts, method='rule') - Batch sentiment analysis
  • compare_methods(text, api_key=None) - Compare rule-based vs LLM analysis

Classes

  • Analyzer - Fast rule-based sentiment analyzer
  • LLMAnalyzer - Multi-provider LLM analyzer (OpenAI, Google, Anthropic, Cohere, Hugging Face, DeepSeek)
  • SentimentResult - Result container with polarity, category, confidence, reasoning, emotions, tone
  • Benchmark - Accuracy testing and comparison utilities

LLMAnalyzer Constructor Parameters

  • provider - LLM provider ('openai', 'google', 'anthropic', 'cohere', 'huggingface', 'deepseek', or 'auto')
  • model - Model name or 'auto' for cheapest available
  • api_key - API key (optional, uses environment variables)
  • fallback_to_cheaper - Whether to fall back to cheaper models if requested model fails (default: True)

📞 Support


Made with ❤️ by Abel Peter

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sentimetric-1.0.5.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sentimetric-1.0.5-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file sentimetric-1.0.5.tar.gz.

File metadata

  • Download URL: sentimetric-1.0.5.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for sentimetric-1.0.5.tar.gz
Algorithm Hash digest
SHA256 d5d98bbf7d35973025c2ad30fb9eab0336ec5b3ab72556a0fc26d44177d86c40
MD5 1164e8e51a1978748685a7c9c6a54f8a
BLAKE2b-256 d7c6243bf70723870e3d96930e4c70ff572924ad20a9a8ab5c2d806f51a68862

See more details on using hashes here.

File details

Details for the file sentimetric-1.0.5-py3-none-any.whl.

File metadata

  • Download URL: sentimetric-1.0.5-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for sentimetric-1.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 19da6fefe36dd6e2b0353e1f51d1d3cb08644fd4330d05e60927edaa9c4fa712
MD5 eb6ac0aa55306b3e97f7f95bdfff1dfd
BLAKE2b-256 896a67270fe003ada2413a6db928b0236c3195dd60c9fa7266b48be12d788344

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page