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.0.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.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: finlight_client-0.4.0.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.0.tar.gz
Algorithm Hash digest
SHA256 24212addcc6d47d9de260614a3a60f71e00238aedc3b4473ec47f761c5d6df51
MD5 7a7e5746ffa3e897b8f26e5bfbc938ca
BLAKE2b-256 499f4b6680a3d6cc505d311f086c343bd76914ab5e5ded6fd6fa3cb126c5d0ee

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlight_client-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ea114b00c0662e93f68c1337e8a49b4912dd9e8f5735ac6cdef371bf5205023
MD5 438415ac64db76f829d977329b9c1b3d
BLAKE2b-256 fc675c64b3b55cd95a6c97a70bd2699eff4012cec2f9ceaa8f03aadb680c7e1f

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