Skip to main content

Haystack 2.x integration for the Live Tennis API: live scores, matches and players as Documents

Project description

livetennisapi-haystack

Haystack 2.x integration for the Live Tennis API: live scores, matches and players as Haystack Documents for RAG and agent pipelines.

  • LiveTennisMatchFetcher — live / upcoming / completed matches (optionally one match by id, optionally filtered by tour) as Documents. content is a clean human-readable match summary; meta carries the structured fields (ids, players, sets/games/points, server, winner).
  • LiveTennisPlayerSearch — player search by name, ranked players first, same Document shape.

Built on the official livetennisapi Python client (retries, error mapping, typed models) — no hand-rolled HTTP.

Installation

pip install livetennisapi-haystack

You need a Live Tennis API key (free tier: 1000 requests/day, 30/min). Export it as an environment variable — the components read LIVETENNISAPI_KEY by default and never accept a plain-string key:

export LIVETENNISAPI_KEY="your-key"

Usage

Standalone

from livetennisapi_haystack import LiveTennisMatchFetcher

fetcher = LiveTennisMatchFetcher()          # key from LIVETENNISAPI_KEY
result = fetcher.run(status="live", limit=5)
for doc in result["documents"]:
    print(doc.content)
    # e.g. "Carlos Alcaraz (ESP, #2) vs Jannik Sinner (ITA, #1) — match at Wimbledon,
    #       grass court, round QF, best of 5. Live now. Score: sets 1-1, games 6-4, 3-6,
    #       2-1, points 30-15. Carlos Alcaraz (ESP, #2) is serving."

In a pipeline (runnable with only LIVETENNISAPI_KEY)

from haystack import Pipeline

from livetennisapi_haystack import LiveTennisMatchFetcher, LiveTennisPlayerSearch

pipe = Pipeline()
pipe.add_component("matches", LiveTennisMatchFetcher(limit=5))
pipe.add_component("players", LiveTennisPlayerSearch(limit=3))

result = pipe.run({"matches": {"status": "live"}, "players": {"query": "alcaraz"}})
for doc in result["matches"]["documents"] + result["players"]["documents"]:
    print("-", doc.content)

RAG over live scores

from haystack import Pipeline
from haystack.components.builders.chat_prompt_builder import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage

from livetennisapi_haystack import LiveTennisMatchFetcher

prompt_template = [
    ChatMessage.from_system("You are a tennis commentator."),
    ChatMessage.from_user(
        "Current matches:\n"
        "{% for document in documents %}{{ document.content }}\n{% endfor %}\n"
        "Answer the following question: {{ query }}\nAnswer:"
    ),
]

pipe = Pipeline()
pipe.add_component("matches", LiveTennisMatchFetcher(limit=10))
pipe.add_component("prompt_builder", ChatPromptBuilder(template=prompt_template, required_variables={"query", "documents"}))
pipe.add_component("llm", OpenAIChatGenerator(model="gpt-4o-mini"))
pipe.connect("matches.documents", "prompt_builder.documents")
pipe.connect("prompt_builder.prompt", "llm.messages")

query = "Who is closest to winning right now?"
result = pipe.run({"matches": {"status": "live"}, "prompt_builder": {"query": query}})
print(result["llm"]["replies"][0].text)

A complete runnable script lives at examples/live_demo.py.

Behavior worth knowing

  • 403 tier wall: when your key is valid but the plan does not unlock an endpoint, the component returns a single readable Document (tagged meta["error"] = "upgrade_required") instead of raising — an agent can tell the user; a RAG pipeline can filter it out. All other errors (bad key, network down, rate limit) still raise the official client's typed exceptions.
  • Sparse data is normal: score.server is nullable (between points the feed may not know who serves next — the summary simply omits the serving sentence), doubles teams have no individual rankings and a null data_completeness, and points are strings ("0", "15", "30", "40", "AD"). The components tolerate all of it.
  • Serialization: both components implement to_dict/from_dict; the API key is stored as a Secret environment-variable reference, never as a value, so pipelines serialize safely to YAML. Note that Haystack 3.0 refuses to deserialize third-party components unless their module is allow-listed, so reload pipelines with Pipeline.loads(yaml_str, allowed_modules=["livetennisapi_haystack.match_fetcher", "livetennisapi_haystack.player_search"]) (or haystack.core.serialization.allow_deserialization_module(...)).
  • tour filter: the API's documented tour query parameter is not yet exposed by livetennisapi 1.0.2's list_matches(), so the component routes that one call through the official client's transport layer (same auth/retries/error mapping).
  • Sync only for now: run() — no run_async yet, although the official client has an async twin. Planned.

Parameters

LiveTennisMatchFetcher(api_key, status="live", tour=None, limit=10, base_url=None, timeout=30.0)status/tour/limit can be overridden per run(), and run(match_id=...) fetches a single match. LiveTennisPlayerSearch(api_key, limit=10, base_url=None, timeout=30.0)run(query, limit=None).

Development

pip install -e . pytest ruff
pytest                    # unit tests, fully mocked, no network
ruff check src tests examples
LIVETENNISAPI_KEY=... pytest -m integration   # live tests, needs a key

License

livetennisapi-haystack is distributed under the terms of the MIT 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

livetennisapi_haystack-0.1.0.tar.gz (18.3 kB view details)

Uploaded Source

Built Distribution

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

livetennisapi_haystack-0.1.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file livetennisapi_haystack-0.1.0.tar.gz.

File metadata

  • Download URL: livetennisapi_haystack-0.1.0.tar.gz
  • Upload date:
  • Size: 18.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for livetennisapi_haystack-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c12239a2feec121883ba2fb6166a75e611efce2d47c4c2d94791b790ddc17e39
MD5 07b533cec6883deefee0b457885f6fa2
BLAKE2b-256 3ea8d27cd06c20f1272117961d4399317def314215e3044b6017569e7c74c612

See more details on using hashes here.

Provenance

The following attestation bundles were made for livetennisapi_haystack-0.1.0.tar.gz:

Publisher: publish.yml on livetennisapi/livetennisapi-haystack

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

File details

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

File metadata

File hashes

Hashes for livetennisapi_haystack-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8b090e92ceb9185f4bcafcfd65dadd1b945f67cc62b175f896c5459c2dd46423
MD5 d99754388788e6e4856162dac15dd83b
BLAKE2b-256 e080d0e1bd016d8e83f4cdd274ebef85449526310eae699a5fbc525904e71889

See more details on using hashes here.

Provenance

The following attestation bundles were made for livetennisapi_haystack-0.1.0-py3-none-any.whl:

Publisher: publish.yml on livetennisapi/livetennisapi-haystack

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