DEV Community

Pulsebit News Sentiment API
Pulsebit News Sentiment API

Posted on

How to Detect Biotech Sentiment Shifts with the Pulsebit API (Python)

# How to Detect Biotech Sentiment Shifts with the Pulsebit API (Python)

## The Problem

If you’ve ever tried scraping sentiment data, you know it’s a painful process. You’re wrestling with multiple data sources, trying to ensure you’re reading the right metrics, and ultimately, you’re left with a lot of noise and not much signal. The biotech sector is notoriously volatile, and keeping track of sentiment shifts can feel like a full-time job on its own. Especially when you realize that sentiment can pivot quickly, affecting your strategies or alerts.

## The Solution

Enter the Pulsebit API. With just one endpoint, it allows you to retrieve sentiment data in a structured way, significantly simplifying your workflow. Instead of piecing together various data streams, you can pull in everything you need with a single GET request. Right now, the biotech sentiment is sitting at a neutral +0.00, but with a notable momentum of +1.40 over the last 24 hours. What’s interesting here is the **confidence** level at 0.87, indicating that there’s strong backing behind this sentiment shift. 

## The Code

To get started, you’ll need to install the `requests` library if you haven’t already:

Enter fullscreen mode Exit fullscreen mode


bash
pip install requests


Here’s a simple Python script to make a GET request to the Pulsebit API’s `/news_semantic` endpoint:

Enter fullscreen mode Exit fullscreen mode


python
import requests

Left: Python GET /news_semantic call for 'biotech'. Right: l
Left: Python GET /news_semantic call for 'biotech'. Right: live JSON response structure. Three lines of Python. Clean JSON. No infrastructure required. Source: Pulsebit /news_semantic.

def get_biotech_sentiment():
url = "https://pulsebit.lojenterprise.com/api/news_semantic"
params = {
"topic": "biotech"
}

response = requests.get(url, params=params)

if response.status_code == 200:
    return response.json()
else:
    print(f"Error: {response.status_code}, {response.text}")
    return None
Enter fullscreen mode Exit fullscreen mode

sentiment_data = get_biotech_sentiment()
print(sentiment_data)


## Reading the Response

When you call the Pulsebit API, you will receive a payload that looks like this:

Enter fullscreen mode Exit fullscreen mode


json
{
"topic": "biotech",
"momentum_24h": 1.400,
"sentiment_score": 0.000,
"confidence": 0.870,
"sentiment_index_0_100": 67.5,
"direction": "rising",
"semantic_clusters": 19,
"region": "us",
"semantic_similarity_avg": 0.221
}


Here’s a breakdown of each field:

- **topic**: The sector you’re analyzing (biotech, in this case).
- **momentum_24h**: The current momentum indicates a shift, which is noteworthy since it’s positive at +1.40. This suggests that sentiment is gaining traction.
- **sentiment_score**: At +0.00, this indicates neutrality, but combined with momentum, it hints at a potential shift.
- **confidence**: A score of 0.87 shows strong backing for the current sentiment, which is crucial when making decisions.
- **sentiment_index_0_100**: The score of 67.5 gives you a quantitative measure of how sentiment is trending.
- **direction**: "Rising" indicates that sentiment is on an upward trajectory, which is valuable to note.
- **semantic_clusters**: 19 clusters show diverse opinions within the biotech space, which could mean varied impacts on specific stocks or trends.
- **region**: Indicates the geographical focus of the sentiment data.
- **semantic_similarity_avg**: A measure at 0.221 provides insights into how closely related the news articles are within those clusters.

![Geographic detection output for biotech filter. No geo data ](https://aace88ba921016d861eaeb8858550e91.r2.cloudflarestorage.com/pulsebit-marketing/figures/g3_geo_output_1772435672622.png)
*Geographic detection output for biotech filter. No geo data leads by article count. Bar colour: sentiment direction. Source: Pulsebit articles[].country.*


## Three Use Cases

1. **Algo Alert**: Set up an alert system that triggers when momentum crosses a certain threshold (e.g., +1.50), indicating a significant sentiment shift.

2. **Slack Bot**: Create a bot that posts daily sentiment updates to your team’s Slack channel, summarizing shifts and confidence levels to keep everyone aligned.

3. **Dashboard**: Build a visual dashboard that displays real-time sentiment scores and momentum for multiple topics, allowing you to monitor biotech trends at a glance.

## Get Started

If you want to dive deeper into the Pulsebit API, check out their documentation [here](https://pulsebit.lojenterprise.com/docs). It’s straightforward and provides easy-to-follow instructions to get you set up quickly.

By leveraging the Pulsebit API, you can cut down on the noise from DIY scraping and focus on making data-driven decisions based on solid sentiment analysis. The biotech sector is dynamic, and being able to detect these shifts efficiently can give you a significant edge.
Enter fullscreen mode Exit fullscreen mode

Arabic coverage led by 4.2 hours. English at T+4.2h. Confide
Arabic coverage led by 4.2 hours. English at T+4.2h. Confidence scores: Arabic 0.82, Mandarin 0.68, English 0.41 Source: Pulsebit /sentiment_by_lang.

Top comments (0)