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.1.0.tar.gz (5.6 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.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file finlight-client-0.1.0.tar.gz.

File metadata

  • Download URL: finlight-client-0.1.0.tar.gz
  • Upload date:
  • Size: 5.6 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.1.0.tar.gz
Algorithm Hash digest
SHA256 64a3b17877f0e8c91bfcb760020c03bf322442fa072c7522d5d5c94249c538c6
MD5 ad54387ada1533b3fe90473d3a8cc238
BLAKE2b-256 8cae463013ff250ca01904024465995d288255a3f9bbb50538fb30d511e5baf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for finlight_client-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d87f87e1448aeba61e2abf4a9fb4bf19e3e2a8fb0fab41c827cb3cb4dd5dba8b
MD5 43be7d035a2dc0a05aa5d6d434e5689d
BLAKE2b-256 d5fc1c07ac483b66b4d6446844bb870205deda9b3069d1698f532f93e605a1df

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