Skip to main content

discourses.io

discourses.io Python SDK

Official Python SDK for discourses.io — the financial social media platform and financial language processing API

PyPI version Python 3.8+ License: MIT

📄 Read the Whitepaper   ·   🔬 Methodology   ·   📖 Documentation   ·   🔑 Get API Key


Why discourses.io?

discourses.io is a financial social media platform and financial language processing API built for the modern market.

Traditional sentiment analysis treats language as static. But financial language evolves—"diamond hands" meant nothing in 2008, but signals strong conviction today. discourses.io solves this with era-calibrated lexicons built on academic and industrial quantitative research.

Era Period Lexicon Use Case
Primitive < 2016 5,557 tokens Historical filings, early Twitter, pre-social sentiment
Ramp 2016 — 2019 7,751 tokens Fintech emergence, crypto adoption, algorithmic trading era
Meme 2019 — 2023 9,822 tokens WSB, Reddit, meme stocks, retail revolution vernacular
Present > 2023 11,195 tokens Current analysis with aggregate of all eras

Installation

pip install discourses

Quick Start

from discourses import Discourses

client = Discourses(api_key="your-api-key")
result = client.analyze("Strong growth with excellent outlook ahead")

print(result.label)      # "very_bullish"
print(result.outlook)    # 0.99

API Reference

🔑 Initialize the Client

Every request requires authentication with your API key. Get yours at discourses.io/dashboard.

from discourses import Discourses

client = Discourses(api_key="your-api-key")
Parameter Type Default Description
api_key str required Your discourses.io API key
base_url str https://discourses.io/api/v1 API base URL
timeout int 30 Request timeout in seconds

Endpoints


📊 Analyze — Single Text Sentiment

POST /analyze — Documentation

Analyze sentiment of any financial text. Returns classification, confidence, and detailed sentiment scores.

from discourses import Discourses

# Initialize client
client = Discourses(api_key="your-api-key")

# Analyze text
result = client.analyze("Strong growth with excellent outlook ahead")

# Access the results
print(f"Label:      {result.label}")
print(f"Confidence: {result.confidence:.2%}")
print(f"Outlook:    {result.outlook:.4f}")
print(f"Bullish:    {result.scores['bullish']:.4f}")
print(f"Bearish:    {result.scores['bearish']:.4f}")
print(f"Words:      {result.word_count}")

Expected Output:

Label:      very_bullish
Confidence: 80.05%
Outlook:    0.9257
Bullish:    0.4917
Bearish:    0.2981
Words:      6
Response Object: AnalysisResult
Field Type Description
label str "very_bullish", "bullish", "neutral", "bearish", "very_bearish"
confidence float Model confidence (0.0 to 1.0)
outlook float Overall sentiment score (0.0 to 1.0)
scores dict Detailed scores: bullish, bearish, neutral, confusion
word_count int Number of words analyzed
matched_count int Sentiment words matched

Helper Properties:

  • result.is_bullish → True if label contains "bullish"
  • result.is_bearish → True if label contains "bearish"
  • result.is_neutral → True if label is "neutral"


🔄 Compare Eras — Cross-Era Analysis

POST /analyze/compare-eras — Documentation

Analyze how the same text is interpreted across different market eras. Essential for understanding semantic drift and backtesting strategies.

from discourses import Discourses

# Initialize client
client = Discourses(api_key="your-api-key")

# Compare sentiment across eras
result = client.compare_eras(
    text="This stock is going to the moon! Diamond hands!",
    eras=["primitive", "ramp", "meme", "present"]
)

# View per-era results
print("Era-by-Era Sentiment:")
print("-" * 50)
for era, data in result.results.items():
    label = data['classification']['label']
    outlook = data['scores']['outlook']
    print(f"  {era:12} {label:14} (outlook: {outlook:.4f})")

# Check semantic drift
print()
print(f"Drift Direction: {result.drift['direction']}")
print(f"Drift Magnitude: {result.drift['magnitude']:.4f}")
print(f"Peak Era:        {result.drift['peak_era']}")

Expected Output:

Era-by-Era Sentiment:
--------------------------------------------------
  primitive    bullish        (outlook: 0.6912)
  ramp         bullish        (outlook: 0.7845)
  meme         very_bullish   (outlook: 0.9933)
  present      very_bullish   (outlook: 0.9977)

Drift Direction: positive_shift
Drift Magnitude: 0.3065
Peak Era:        present

💡 Notice how "diamond hands" and "to the moon" have much stronger bullish signals in the meme and present eras compared to primitive!

Response Object: CompareResult
Field Type Description
results dict Per-era analysis results
drift dict Semantic drift metrics
meta dict Processing metadata

Drift Fields:

Field Type Description
direction str "positive_shift", "negative_shift", or "stable"
magnitude float Size of the drift (0.0 to 1.0)
min_era str Era with lowest sentiment
peak_era str Era with highest sentiment


⚡ Batch — High-Volume Processing

POST /analyze/batch — Documentation

Efficiently analyze multiple texts in a single request. Perfect for processing feeds, historical data, or real-time streams.

from discourses import Discourses

# Initialize client
client = Discourses(api_key="your-api-key")

# Texts to analyze (with custom IDs)
texts = [
    {"id": "post_1", "text": "Diamond hands! This is going to the moon"},
    {"id": "post_2", "text": "Bearish on this one, expecting a pullback"},
    {"id": "post_3", "text": "Strong growth with excellent outlook ahead"},
]

# Batch analyze with specific era
result = client.batch(texts=texts, era="meme")

# Process results
print("Batch Sentiment Analysis")
print("=" * 55)
for post_id, data in result.results.items():
    label = data['classification']['label']
    outlook = data['scores']['outlook']
    emoji = "🟢" if "bullish" in label else "🔴" if "bearish" in label else "⚪"
    print(f"{emoji} {post_id}: {label:14} (outlook: {outlook:.4f})")

print()
print(f"Processed: {result.meta['texts_processed']}")
print(f"Failed:    {result.meta['texts_failed']}")

Expected Output:

Batch Sentiment Analysis
=======================================================
🟢 post_1: bullish        (outlook: 0.6735)
🟢 post_2: very_bullish   (outlook: 0.9353)
🟢 post_3: very_bullish   (outlook: 0.9257)

Processed: 3
Failed:    0
Response Object: BatchResult
Field Type Description
results dict Results keyed by your custom IDs
meta dict Processing metadata

Meta Fields:

Field Type Description
era str Era used for analysis
texts_processed int Successfully processed count
texts_failed int Failed count
processing_time_ms int Total processing time

Era Selection Guide

Use Case Recommended Era
Modern social media sentiment present
Meme stock / crypto analysis meme
Fintech / crypto adoption era ramp
Traditional financial news primitive
Understanding semantic drift compare_eras()
# Modern analysis (> 2023)
client.analyze(text, era="present")

# Meme-era analysis (2019-2023, WSB, crypto culture)
client.analyze(text, era="meme")

# Ramp era (2016-2019, fintech emergence)
client.analyze(text, era="ramp")

# Traditional financial language (< 2016)
client.analyze(text, era="primitive")

# Compare across all eras
client.compare_eras(text, eras=["primitive", "ramp", "meme", "present"])

Error Handling

The SDK provides typed exceptions for robust error handling:

from discourses import (
    Discourses,
    AuthenticationError,
    RateLimitError,
    ValidationError,
    DiscoursesError,
)

client = Discourses(api_key="your-api-key")

try:
    result = client.analyze("Market analysis text")
    
except AuthenticationError:
    # Invalid or expired API key
    print("Check your API key at https://discourses.io/dashboard")
    
except RateLimitError as e:
    # Too many requests
    print(f"Rate limited. Retry after {e.retry_after} seconds")
    
except ValidationError as e:
    # Invalid input (empty text, too long, etc.)
    print(f"Invalid input: {e.message}")
    
except DiscoursesError as e:
    # Catch-all for other API errors
    print(f"API error: {e}")

📄 Whitepaper
Academic research & methodology
📖 Documentation
Full API reference
🔬 Methodology
How era-calibration works
🔑 Dashboard
Get your API key
💬 Issues
Report bugs & requests
📦 PyPI
Package & versions

License

MIT License — see LICENSE for details.


Built with ❤️ by discourses.io

Metadata

Release files for discourses 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for discourses 1.1.4
File Size Uploaded
discourses-1.1.4.tar.gz 17.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for discourses 1.1.4
File Interpreter ABI Platform
discourses-1.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 33.6 kB

Release files / discourses-1.1.4.tar.gz

Download URL discourses-1.1.4.tar.gz
Size 17.9 kB
Tags Source
SHA-256 checksum
How to use checksums
16a270cf404ffede5bd9f2157a14eb229619d56f22aa8d57b54e9670db34b1a5
BLAKE2b-256 checksum
How to use checksums
d457a7d99ac3187b88f6d8e8b86214730cc99f638d772dcf1ed0e9ae78e35f17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.5

Release files / discourses-1.1.4-py3-none-any.whl

Download URL discourses-1.1.4-py3-none-any.whl
Size 15.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90b8a970f44770d2daec8d0611a49d15f4ffbf9bffd90dff8bbb0d62ae6cef79
BLAKE2b-256 checksum
How to use checksums
17d2e8aaf80c28fcd6f56623b02ab255d0a34f17bbe378586ef135b947b3d21c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.5

Release history Release notifications | RSS feed

This release

1.1.4 This release

2 release files

1.1.3

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.0

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page