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.2.tar.gz (7.1 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.2-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: finlight_client-0.4.2.tar.gz
  • Upload date:
  • Size: 7.1 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.2.tar.gz
Algorithm Hash digest
SHA256 de70e20d7103f9104e6ad7f59ae6d9fd5ed7f3252a78a70b39f66c026e7490d5
MD5 eb1f139d6c86da2b09b46e3afd914170
BLAKE2b-256 98aeda3f50846cff4f7c10dac82b188c6e81d349e2b63b5c4f25c2a818e95d1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlight_client-0.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d441c7cc70ed772b0c8948546731f91780732c304fa9d2150acce4f86aea374c
MD5 1c2bc29cb494d38fc2c5e523692422de
BLAKE2b-256 5af451f92e9d8f4e118a795f97fae1526f15ac04a0bcaeaf1b343899713518fc

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