Installation¶
This guide covers installing Sentimatrix and configuring it for your use case.
Basic Installation¶
Install Sentimatrix using pip:
This installs the core library with minimal dependencies, suitable for basic sentiment analysis using transformer models.
Installation with Extras¶
Sentimatrix offers optional dependencies for extended functionality:
Install support for cloud LLM providers:
Includes: openai, anthropic, google-generativeai, groq, mistralai, together, cohere
Install web scraping capabilities:
Includes: playwright, selenium, beautifulsoup4, lxml
After installation, set up Playwright browsers:
Install local transformer models:
Includes: transformers, torch, tokenizers
Install visualization tools:
Includes: matplotlib, plotly, pandas
Install development dependencies:
Includes: pytest, pytest-asyncio, ruff, black, mypy
Alternative Package Managers¶
Setting Up Playwright¶
If you're using web scraping features, install Playwright browsers:
# Install Chromium (recommended)
playwright install chromium
# Or install all browsers
playwright install
# Install system dependencies (Linux)
playwright install-deps
Headless Mode
By default, Sentimatrix runs Playwright in headless mode. No display is required.
Environment Configuration¶
API Keys¶
Set up API keys for LLM providers:
# OpenAI
export OPENAI_API_KEY="sk-..."
# Anthropic
export ANTHROPIC_API_KEY="sk-ant-..."
# Google
export GOOGLE_API_KEY="..."
# Groq
export GROQ_API_KEY="gsk_..."
# Other providers
export MISTRAL_API_KEY="..."
export COHERE_API_KEY="..."
export TOGETHER_API_KEY="..."
export FIREWORKS_API_KEY="..."
export OPENROUTER_API_KEY="..."
export DEEPSEEK_API_KEY="..."
Using .env Files¶
Create a .env file in your project root:
# LLM Providers
OPENAI_API_KEY=sk-...
ANTHROPIC_API_KEY=sk-ant-...
GROQ_API_KEY=gsk_...
# Commercial Scraping APIs (optional)
SCRAPERAPI_KEY=...
APIFY_TOKEN=...
BRIGHTDATA_USERNAME=...
BRIGHTDATA_PASSWORD=...
# Local Providers
OLLAMA_HOST=http://localhost:11434
LMSTUDIO_HOST=http://localhost:1234
Sentimatrix automatically loads .env files using python-dotenv.
Verifying Installation¶
Verify your installation is working:
import sentimatrix
# Check version
print(f"Sentimatrix version: {sentimatrix.__version__}")
# Quick test
import asyncio
from sentimatrix import Sentimatrix
async def test():
async with Sentimatrix() as sm:
result = await sm.analyze("Hello, world!")
print(f"Sentiment: {result.sentiment}")
print(f"Confidence: {result.confidence:.2%}")
asyncio.run(test())
Expected output:
Troubleshooting¶
Common Issues¶
ModuleNotFoundError: No module named 'sentimatrix'
Ensure you've activated your virtual environment:
playwright._impl._errors.Error: Executable doesn't exist
Install Playwright browsers:
ImportError: cannot import name 'Sentimatrix'
You may have a naming conflict. Check for local files named sentimatrix.py:
Platform-Specific Notes¶
Install system dependencies for Playwright:
No additional dependencies required. If using Homebrew Python:
Next Steps¶
- Quick Start - Run your first sentiment analysis
- Configuration - Configure Sentimatrix for your needs
- LLM Providers - Set up LLM providers