Skip to main content

Python client for the Finlight API

Project description

Finlight Client - Python Library

A Python client library for interacting with the Finlight News API. Finlight provides financial news articles, sentiment analysis, and market insights to help users stay updated on global financial trends. This library simplifies integration with the API, allowing developers to access articles and real-time data with ease.

Features

  • Fetch basic articles with metadata such as titles, authors, and links.
  • Retrieve extended articles with full content and summaries.
  • Stream articles in real-time using WebSocket connections.
  • Automatic retry for API requests with exponential backoff.
  • Fully type-annotated and Pythonic interface.

Installation

Install the package via pip:

pip install finlight-client

Quick Start

Basic Usage

from finlight_client import FinlightApi

# Initialize the client
config = {
    "api_key": "your_api_key",  # Replace with your API key
}
client = FinlightApi(config)

# Fetch basic articles
params = {
    "query": "financial market",
    "from": "2024-01-01",
    "to": "2024-01-31",
    "language": "en",
    "pageSize": 10,
}
response = client.articles.get_basic_articles(params)

# Print the articles
for article in response['articles']:
    print(article['title'], article['publishDate'])  # publishDate is a datetime object

Streaming Real-Time Articles

def on_message(article):
    print(f"Received article: {article['title']}")

# Set up WebSocket client
client.websocket.connect(
    {"query": "finance", "language": "en", "extended": True},
    on_message
)

# Keep the WebSocket running (use Ctrl+C to stop)
import time
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    print("Disconnecting WebSocket...")
    client.websocket.disconnect()

Configuration Options

The FinlightApi client accepts the following configuration parameters:

Parameter Type Description Default
api_key str Your API key for authenticating requests. Required
base_url str Base URL for API requests. https://api.finlight.me
timeout int Timeout for API requests in milliseconds. 5000
retry_count int Number of retries for failed requests. 3
wss_url str WebSocket server URL. wss://wss.finlight.me

API Methods

Articles

  1. Fetch Basic Articles

    Fetch articles with metadata like title, author, and source.

    client.articles.get_basic_articles(params)
    
    • Parameters:
      • query: Search query string.
      • from: Start date in YYYY-MM-DD format.
      • to: End date in YYYY-MM-DD format.
      • language: Language filter (default: en).
      • pageSize: Number of results per page (1-1000).
      • page: Page number.
  2. Fetch Extended Articles

    Fetch articles with full content and summaries.

    client.articles.get_extended_articles(params)
    

WebSocket

  1. Real-Time Article Streaming

    Stream articles in real-time using WebSocket. Supports both basic and extended articles.

    client.websocket.connect(request_payload, on_message)
    
    • Parameters:
      • query: Search query string.
      • language: Language filter (default: en).
      • extended: Boolean to enable full content.

Error Handling

  • HTTP errors are raised as exceptions with detailed messages.
  • WebSocket errors are logged to the console.

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Resources

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

finlight_client-0.4.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

finlight_client-0.4.1-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file finlight_client-0.4.1.tar.gz.

File metadata

  • Download URL: finlight_client-0.4.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.4

File hashes

Hashes for finlight_client-0.4.1.tar.gz
Algorithm Hash digest
SHA256 02e01eab6dfaaeb981360227c6ae6854ad6eee757a984e0b74b54ce6bad09805
MD5 47926a3520663cefe9ada862242885e8
BLAKE2b-256 3ca77d5b42dbeab05bf10c129f49e0ec44c8108aef35797f480ae6501b6a6c16

See more details on using hashes here.

File details

Details for the file finlight_client-0.4.1-py3-none-any.whl.

File metadata

File hashes

Hashes for finlight_client-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3b0914fecea3df87fae85a63c4800f82f6386c0d90f2880825ea28a1e85ea670
MD5 38c1196219ed73abfc1575285c43b639
BLAKE2b-256 e1eab0926447097893195de76f494390627c77fde0d103416bfdeb056e7eef8b

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