Python client for PySenti crypto sentiment analysis SignalR API
Project description
CryptoSenti
A Python client library for connecting to the PySenti crypto sentiment analysis SignalR API at crypto.pysenti.com.
About
crypto.pysenti.com is a real-time news sentiment analysis platform that provides live sentiment data and summaries for cryptocurrency and financial news. This Python client allows you to connect to the SignalR API and receive real-time sentiment updates and news summaries.
Installation
pip install cryptosenti
Quick Start
import asyncio
from cryptosenti import SentimentClient, CryptoSentiConfig
async def main():
# Create client with default configuration
async with SentimentClient() as client:
# Register event handlers
client.on_summary_received(lambda summary: print(f"Summary: {summary.sentiment_summary}"))
client.on_sentiment_received(lambda sentiment: print(f"Sentiment: {sentiment.sentiment}"))
# Keep the connection alive
await asyncio.sleep(60)
if __name__ == "__main__":
asyncio.run(main())
Configuration
You can customize the client behavior using CryptoSentiConfig:
from cryptosenti import SentimentClient, CryptoSentiConfig
config = CryptoSentiConfig(
hub_url="https://crypto.pysenti.com/sentimentHub",
connection_timeout=30,
reconnect_attempts=5,
log_level="DEBUG"
)
client = SentimentClient(config)
Usage
Connecting and Subscribing
import asyncio
from cryptosenti import SentimentClient
async def main():
client = SentimentClient()
# Connect to the hub
await client.connect()
# Join SignalR groups
await client.join_summary_group()
await client.join_sentiment_group()
# Register handlers
client.on_summary_received(handle_summary)
client.on_sentiment_received(handle_sentiment)
client.on_connection_changed(handle_connection_change)
# Keep alive
await asyncio.sleep(3600) # Run for 1 hour
# Disconnect
await client.disconnect()
def handle_summary(summary):
print(f"Received summary with importance: {summary.importance}")
print(f"Key themes: {', '.join(summary.key_themes_trends)}")
def handle_sentiment(sentiment):
print(f"Sentiment: {sentiment.sentiment}")
print(f"Confidence: {sentiment.confidence}")
def handle_connection_change(connected):
if connected:
print("Connected to SignalR hub")
else:
print("Disconnected from SignalR hub")
if __name__ == "__main__":
asyncio.run(main())
Data Models
The library provides strongly-typed data models that match the C# backend:
NewsSummary
key_themes_trends: Key themes and trendsimpactful_events_and_implications: Impactful events and implicationssentiment_summary: Overall sentiment summaryactionable_insights: Actionable insightsimportance: Importance scoretimestamp: When the summary was created
SentimentData
sentiment: Sentiment value (positive/negative/neutral)confidence: Confidence scoreexplanation: Explanation of the sentimentnews: Associated news itemtemporal: Temporal aspect (past/present/future)emotion: Detected emotionstrength: Sentiment strength
WorldNews
headline: News headlinesource: News sourceurgency: Urgency levelevent_date: When the event occurredtype: Type of news (breaking/regular/analysis/opinion)
Development
Setup
git clone https://github.com/pysenti/cryptosenti.git
cd cryptosenti
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -e ".[dev]"
Testing
pytest
Linting and Formatting
ruff check .
ruff format .
mypy src/
License
This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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 cryptosenti-0.1.0.tar.gz.
File metadata
- Download URL: cryptosenti-0.1.0.tar.gz
- Upload date:
- Size: 36.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d30b0fde1a7d03eb0cc6ce379699ef99402533f0e1a903813f90806af468caa
|
|
| MD5 |
efd83d2ba859676c19f2010c73099415
|
|
| BLAKE2b-256 |
84a407640436c6557edf9c255326754a278d6ce73b40a62c554252d2a084942e
|
File details
Details for the file cryptosenti-0.1.0-py3-none-any.whl.
File metadata
- Download URL: cryptosenti-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.10.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
44a4554a1387508cca5ed1e35befdaed2ae6bac98f393ea879a4ec4c30719e0a
|
|
| MD5 |
90275da341a80990a36232eab66c66cd
|
|
| BLAKE2b-256 |
b0a1529d0c39f0eac8e28651d20754fbc6e0791ef279365189aa64c8be6969d8
|