Skip to main content

A Python library for retrieving financial data using the LSEG Knowledge Direct API

Project description

LSEG Knowledge Direct Python API

Python CI codecov License: MIT

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/lseg-knowledge-direct.git
cd lseg-knowledge-direct
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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

lsegkd-0.1.2.tar.gz (60.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

lsegkd-0.1.2-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file lsegkd-0.1.2.tar.gz.

File metadata

  • Download URL: lsegkd-0.1.2.tar.gz
  • Upload date:
  • Size: 60.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lsegkd-0.1.2.tar.gz
Algorithm Hash digest
SHA256 ae691fe3ca0e513b300aa3ce5a2f535d411f5f2c77abc0857163cb1a9ce7b39d
MD5 33a3dc01293907c886747a1539768a95
BLAKE2b-256 498053cce852d1d92584442e6b9f95c8ba4dc042af381fa28ea32e5cf3a6873d

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsegkd-0.1.2.tar.gz:

Publisher: release.yml on yurukatsu/lsegkd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file lsegkd-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: lsegkd-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for lsegkd-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8565fcc4e1fe15a85cfa8450afb756347fc4db1a202a11ffc90b6af9f48ede91
MD5 aebaf205c2f2fe067bd34a63ad5afa3c
BLAKE2b-256 48ab2188cfaef31e1de393fa875a2c439fc91c6a87e029c6fb6c70998d1faedc

See more details on using hashes here.

Provenance

The following attestation bundles were made for lsegkd-0.1.2-py3-none-any.whl:

Publisher: release.yml on yurukatsu/lsegkd

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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