Python client for Marlo sentiment analysis API
Project description
marlo-sentiment
Python client for the Marlo sentiment analysis API with industry-specific intelligence.
Installation
pip install marlo-sentiment
Usage
Basic Usage
from marlo_sentiment import MarloClient
client = MarloClient(api_key='your-rapidapi-key')
# Analyze text sentiment
result = client.analyze('I love this product!')
print(result)
# {
# 'sentiment': 'positive',
# 'confidence': 0.9162,
# 'scores': {
# 'positive': 0.647,
# 'neutral': 0.353,
# 'negative': 0.0,
# 'compound': 0.9162
# },
# 'text_length': 20
# }
Industry-Specific Analysis
# Healthcare context
healthcare_result = client.analyze(
'Strong medication led to successful treatment',
industry='healthcare'
)
# Gaming context
gaming_result = client.analyze(
'Epic gameplay but pay-to-win ruins it',
industry='gaming'
)
# Technology context
tech_result = client.analyze(
'Memory leak in the application',
industry='technology'
)
Batch Analysis
texts = [
'Great customer service!',
'Product arrived damaged',
'Fast shipping, excellent quality'
]
results = client.batch_analyze(texts, industry='retail')
Supported Industries
industries = client.get_supported_industries()
print(industries)
# ['healthcare', 'technology', 'gaming', 'finance', 'restaurant',
# 'automotive', 'real_estate', 'fitness', 'education', 'retail']
Configuration
Using Configuration Dict
from marlo_sentiment import MarloClient
client = MarloClient({
'api_key': 'your-rapidapi-key',
'base_url': 'https://custom-endpoint.com', # optional
'timeout': 5.0 # optional, default 10.0 seconds
})
Using API Key String
client = MarloClient('your-rapidapi-key')
Error Handling
from marlo_sentiment import MarloClient, MarloError, MarloValidationError
try:
result = client.analyze('')
except MarloValidationError as e:
print(f"Validation error: {e}")
except MarloError as e:
print(f"API error {e.status_code}: {e.message}")
Context Manager Support
with MarloClient('your-api-key') as client:
result = client.analyze('Great service!')
print(result.sentiment)
Type Hints
Full type hint support:
from marlo_sentiment import MarloClient, SentimentResponse, Industry
client = MarloClient('your-key')
result: SentimentResponse = client.analyze('text', industry='healthcare')
Requirements
- Python 3.8+
- requests >= 2.28.0
Development
Install Development Dependencies
pip install -e ".[dev]"
Run Tests
pytest
Code Formatting
black src/
isort src/
Type Checking
mypy src/
License
MIT
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
marlo_sentiment-1.0.0.tar.gz
(5.6 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file marlo_sentiment-1.0.0.tar.gz.
File metadata
- Download URL: marlo_sentiment-1.0.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cf873bc8f85ff31e17dd9c9155b6aaf5332d208ffff1253e937681a8fdb79170
|
|
| MD5 |
924e21d7a9915d175701c4b3b9c9b2af
|
|
| BLAKE2b-256 |
3a79cd49f34b6229567b49bde30c2975c01be176a89e6a7175a1d6e4085c152f
|
File details
Details for the file marlo_sentiment-1.0.0-py3-none-any.whl.
File metadata
- Download URL: marlo_sentiment-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7f7ee8df5096ce509d2209c92b7bb69c1075d58dad033edad4d4875589e1617b
|
|
| MD5 |
9936b692c50048d84a993de41714429d
|
|
| BLAKE2b-256 |
ffec63cb9e7d61296a53e05da322f759739f9f41a2efdd62453ca64d97f5e691
|