A Python library for retrieving financial data using the LSEG Knowledge Direct API
Project description
LSEG Knowledge Direct Python API
A Python client for the LSEG Knowledge Direct REST API. It authenticates, downloads event headlines + transcripts, parses transcript XML into typed Pydantic models, and ships a Typer-based CLI for bulk download.
Features
- Authentication and short-lived service token issuance
- Paginated event-headline retrieval (
GetEventHeadlines) with country and publication-status filters - Sync and async transcript document fetching with automatic public-URL →
signed-URL fallback (
GetDocument) - Pydantic models for headlines and parsed transcripts
- Typer CLI with progress bar, idempotent re-runs, and pagination loop
Installation
From PyPI
uv add lsegkd
or
pip install lsegkd
From source (development)
git clone https://github.com/yurukatsu/lsegkd.git
cd lsegkd
uv sync --all-groups
Authentication
Set the three environment variables (e.g. via a .env file — see
.env.sample):
LSEG_KNOWLEDGE_DIRECT_USERNAME=your_username
LSEG_KNOWLEDGE_DIRECT_APP_ID=your_app_id
LSEG_KNOWLEDGE_DIRECT_PASSWORD=your_password
Or pass them directly when constructing Credentials:
from lsegkd import Credentials
credentials = Credentials(
username="your_username",
app_id="your_app_id",
password="your_password",
)
CLI usage
# Minimum: a date range
uv run lsegkd -d .env fetch-transcripts --from-date 2025-11-22 --to-date 2025-11-23
# Multiple countries (comma-separated or repeated)
uv run lsegkd -d .env fetch-transcripts \
--from-date 2025-11-22 --to-date 2025-11-23 \
--countries US,UK,JP
# All transcript statuses, force re-download, custom output dir
uv run lsegkd -d .env fetch-transcripts \
--from-date 2025-11-22 --to-date 2025-11-23 \
--transcript-status any \
--no-skip-existing \
--output-dir ./data/raw
Run uv run lsegkd fetch-transcripts --help for the full option list.
Output layout
The fetch-transcripts command writes three files per event under output_dir:
<output_dir>/
├── xml/<EventId>.xml raw transcript XML
├── headlines/<EventId>.json EventHeadline metadata
└── transcripts/<EventId>.json parsed EventTranscript
Re-runs skip events whose xml/ and transcripts/ JSON already exist
(--skip-existing is on by default; pass --no-skip-existing to force).
Python API usage
import asyncio
from lsegkd import (
Credentials,
EventTranscriptParser,
StreetEventsServiceClient,
TokenManagementServiceClient,
)
async def main() -> None:
credentials = Credentials() # reads env vars
# Exchange username/password for a short-lived service token
token = TokenManagementServiceClient(credentials).create_service_token()
client = StreetEventsServiceClient(
credentials=credentials,
token=token.token,
async_mode=True,
)
try:
response = client.get_event_headlines(
from_date=..., # datetime
to_date=..., # datetime
countries=["US", "UK"],
transcript_status="Final",
)
for headline in response.extract_event_headlines():
if headline.Transcript is None:
continue
xml = await client.aget_document(
transcript_id=headline.Transcript.TranscriptId
)
event = EventTranscriptParser.from_string(xml).parse()
# event is a Pydantic EventTranscript — use it however you need
finally:
await client.aclose()
asyncio.run(main())
Pydantic data types (EventHeadline, Duration, Organization, Symbol,
PaginationResult, ...) live in lsegkd.api.types
and are also re-exported from lsegkd.api. Parsed transcript types
(EventTranscript, Speaker, Episode, Section, Turn, ...) live in
lsegkd.xml.transcript.
Development
uv sync --all-groups
uv run poe check # ruff format + ruff check + ty + pytest
uv run poe test # tests only
See CLAUDE.md for architecture notes and the conventions enforced by the codebase (HTTP / endpoint base classes, type-naming rules, the LSEG-API quirks pinned by tests).
License
MIT — see LICENSE.
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 lsegkd-0.2.0.tar.gz.
File metadata
- Download URL: lsegkd-0.2.0.tar.gz
- Upload date:
- Size: 60.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d3d7264e157c4c48fd21b30fcaf9385d6e90fbc7122be3a6b8ef72639498883
|
|
| MD5 |
9720304ec5b839a46492346ffd987faa
|
|
| BLAKE2b-256 |
25f0eb1e64a20c4643c0c6163fdfd5f81f02a5ce4d5cc925b451b5334bb9e40a
|
Provenance
The following attestation bundles were made for lsegkd-0.2.0.tar.gz:
Publisher:
release.yml on yurukatsu/lsegkd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lsegkd-0.2.0.tar.gz -
Subject digest:
5d3d7264e157c4c48fd21b30fcaf9385d6e90fbc7122be3a6b8ef72639498883 - Sigstore transparency entry: 1461917495
- Sigstore integration time:
-
Permalink:
yurukatsu/lsegkd@84e96014b676197b0823f560f258c137023b79f4 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/yurukatsu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84e96014b676197b0823f560f258c137023b79f4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file lsegkd-0.2.0-py3-none-any.whl.
File metadata
- Download URL: lsegkd-0.2.0-py3-none-any.whl
- Upload date:
- Size: 22.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1308fe2ae3508d2f016f691a9a129bb93c1653fa20b537d06b2213e2be72f30d
|
|
| MD5 |
dfaeed449f3793128b91b9aedf9dee9b
|
|
| BLAKE2b-256 |
5432b931a505f624cbb343d93a3e151faf7fa553d611e919c859b7ca4f81c4c8
|
Provenance
The following attestation bundles were made for lsegkd-0.2.0-py3-none-any.whl:
Publisher:
release.yml on yurukatsu/lsegkd
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lsegkd-0.2.0-py3-none-any.whl -
Subject digest:
1308fe2ae3508d2f016f691a9a129bb93c1653fa20b537d06b2213e2be72f30d - Sigstore transparency entry: 1461917549
- Sigstore integration time:
-
Permalink:
yurukatsu/lsegkd@84e96014b676197b0823f560f258c137023b79f4 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/yurukatsu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@84e96014b676197b0823f560f258c137023b79f4 -
Trigger Event:
push
-
Statement type: