Python client for the Finlight API
Project description
Finlight Client – Python Library
A Python client library for interacting with the Finlight News API. Finlight delivers real-time and historical financial news articles, enriched with sentiment analysis, company tagging, and market metadata. This library makes it easy to integrate Finlight into your Python applications.
✨ Features
- Fetch structured news articles with date parsing and metadata.
- Filter by tickers, sources, languages, and date ranges.
- Stream real-time news updates via WebSocket.
- Auto-reconnect and ping/pong watchdog for WebSocket.
- Strongly typed models using
pydanticanddataclass. - Lightweight and developer-friendly.
📦 Installation
pip install finlight-client
🚀 Quick Start
Fetch Articles via REST API
from finlight_client import FinlightApi, ApiConfig
from finlight_client.models import GetArticlesParams
def main():
# Initialize the client
config = ApiConfig(api_key="your_api_key")
client = FinlightApi(config)
# Create query parameters
params = GetArticlesParams(
query="Nvidia",
language="en",
from_="2024-01-01",
to="2024-12-31",
includeContent=True
)
# Fetch articles
response = client.articles.fetch_articles(params=params)
# Print results
for article in response['articles']:
print(f"{article['publishDate']} | {article['title']}")
if __name__ == "__main__":
main()
Stream Real-Time Articles via WebSocket
import asyncio
from finlight_client import FinlightApi, ApiConfig
from finlight_client.models import GetArticlesWebSocketParams
def on_article(article):
print("📨 Received:", article.title)
async def main():
# Initialize the client
config = ApiConfig(api_key="your_api_key")
client = FinlightApi(config)
# Create WebSocket parameters
payload = GetArticlesWebSocketParams(
query="Nvidia",
sources=["www.reuters.com"],
language="en",
extended=True,
)
# Connect and listen for articles
await client.websocket.connect(
request_payload=payload,
on_article=on_article
)
if __name__ == "__main__":
asyncio.run(main())
⚙️ Configuration
ApiConfig allows fine-tuning of your API client:
| Parameter | Type | Description | Default |
|---|---|---|---|
api_key |
str |
Your API key | Required |
base_url |
AnyHttpUrl |
Base REST API URL | https://api.finlight.me |
wss_url |
AnyHttpUrl |
WebSocket server URL | wss://wss.finlight.me |
timeout |
int |
Request timeout in ms | 5000 |
retry_count |
int |
Retry attempts on failures | 3 |
📚 API Overview
ArticleService.fetch_articles(params: GetArticlesParams) -> dict
- Fetch articles with flexible filtering.
- Automatically parses ISO date strings into
datetime.
SourcesService.get_sources() -> List[Source]
- Retrieve available news sources.
- Returns list of sources with metadata about content availability.
WebSocketClient.connect(request_payload, on_article)
- Subscribe to live article updates.
- Reconnects automatically on disconnects.
- Pings the server every 30s to keep the connection alive.
🧯 Error Handling
- Invalid date strings raise clear Python
ValueErrors. - REST and WebSocket exceptions are logged and managed.
- WebSocket includes reconnect, watchdog, and ping/pong mechanisms.
📖 Additional Examples
Fetch Available Sources
from finlight_client import FinlightApi, ApiConfig
def main():
config = ApiConfig(api_key="your_api_key")
client = FinlightApi(config)
sources = client.sources.get_sources()
for source in sources:
print(f"{source['domain']} - Content: {source['isContentAvailable']}")
if __name__ == "__main__":
main()
🧰 Model Summary
GetArticlesParams
Query parameters to filter articles, including:
query: Search texttickers: List of ticker symbolssources,excludeSources: Source filteringlanguage: e.g.,"en","de"from_,to: Date range (YYYY-MM-DDor ISO)includeContent,includeEntities,excludeEmptyContentorder,page,pageSize
Article
Each article includes:
title,link,publishDate,source,languagesummary,content,sentiment,confidenceimages: List of image URLscompanies: List of taggedCompanyobjects
🤝 Contributing
We welcome contributions and suggestions!
- Fork this repo
- Create a feature branch
- Submit a pull request with tests if applicable
📄 License
MIT License – see LICENSE
🔗 Resources
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file finlight_client-1.1.1.tar.gz.
File metadata
- Download URL: finlight_client-1.1.1.tar.gz
- Upload date:
- Size: 9.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7bec540db1af458ad4aec05c334edde947a22694d42e3f0cdf92e01ff3942c02
|
|
| MD5 |
ec63eec4534090485fc587a59de3d696
|
|
| BLAKE2b-256 |
d4c731ac930657ecbb9b075e9e46774dc0a95f48bbc49e6aeb7a8ad6057f0357
|
File details
Details for the file finlight_client-1.1.1-py3-none-any.whl.
File metadata
- Download URL: finlight_client-1.1.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
854ac39ebbcf493f0914fcf336d426edaafe7eac40303d8e0d01ee9a17527a65
|
|
| MD5 |
7d48ec9b8ad7c432e3d058307fe9219e
|
|
| BLAKE2b-256 |
8be5b30894cb4580586d171e46a3e85234661609394d682e53a96c57f1d64306
|