Skip to main content

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 trends
  • impactful_events_and_implications: Impactful events and implications
  • sentiment_summary: Overall sentiment summary
  • actionable_insights: Actionable insights
  • importance: Importance score
  • timestamp: When the summary was created

SentimentData

  • sentiment: Sentiment value (positive/negative/neutral)
  • confidence: Confidence score
  • explanation: Explanation of the sentiment
  • news: Associated news item
  • temporal: Temporal aspect (past/present/future)
  • emotion: Detected emotion
  • strength: Sentiment strength

WorldNews

  • headline: News headline
  • source: News source
  • urgency: Urgency level
  • event_date: When the event occurred
  • type: 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


Download files

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

Source Distribution

cryptosenti-0.1.0.tar.gz (36.0 kB view details)

Uploaded Source

Built Distribution

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

cryptosenti-0.1.0-py3-none-any.whl (32.1 kB view details)

Uploaded Python 3

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

Hashes for cryptosenti-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8d30b0fde1a7d03eb0cc6ce379699ef99402533f0e1a903813f90806af468caa
MD5 efd83d2ba859676c19f2010c73099415
BLAKE2b-256 84a407640436c6557edf9c255326754a278d6ce73b40a62c554252d2a084942e

See more details on using hashes here.

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

Hashes for cryptosenti-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 44a4554a1387508cca5ed1e35befdaed2ae6bac98f393ea879a4ec4c30719e0a
MD5 90275da341a80990a36232eab66c66cd
BLAKE2b-256 b0a1529d0c39f0eac8e28651d20754fbc6e0791ef279365189aa64c8be6969d8

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