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) asDocuments.contentis a clean human-readable match summary;metacarries the structured fields (ids, players, sets/games/points, server, winner).LiveTennisPlayerSearch— player search by name, ranked players first, sameDocumentshape.
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(taggedmeta["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.serveris 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 nulldata_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 aSecretenvironment-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 withPipeline.loads(yaml_str, allowed_modules=["livetennisapi_haystack.match_fetcher", "livetennisapi_haystack.player_search"])(orhaystack.core.serialization.allow_deserialization_module(...)). tourfilter: the API's documentedtourquery parameter is not yet exposed bylivetennisapi1.0.2'slist_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()— norun_asyncyet, 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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c12239a2feec121883ba2fb6166a75e611efce2d47c4c2d94791b790ddc17e39
|
|
| MD5 |
07b533cec6883deefee0b457885f6fa2
|
|
| BLAKE2b-256 |
3ea8d27cd06c20f1272117961d4399317def314215e3044b6017569e7c74c612
|
Provenance
The following attestation bundles were made for livetennisapi_haystack-0.1.0.tar.gz:
Publisher:
publish.yml on livetennisapi/livetennisapi-haystack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
livetennisapi_haystack-0.1.0.tar.gz -
Subject digest:
c12239a2feec121883ba2fb6166a75e611efce2d47c4c2d94791b790ddc17e39 - Sigstore transparency entry: 2233075429
- Sigstore integration time:
-
Permalink:
livetennisapi/livetennisapi-haystack@e37f39fa355e0606f09bdf40c496038173570671 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/livetennisapi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e37f39fa355e0606f09bdf40c496038173570671 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file livetennisapi_haystack-0.1.0-py3-none-any.whl.
File metadata
- Download URL: livetennisapi_haystack-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b090e92ceb9185f4bcafcfd65dadd1b945f67cc62b175f896c5459c2dd46423
|
|
| MD5 |
d99754388788e6e4856162dac15dd83b
|
|
| BLAKE2b-256 |
e080d0e1bd016d8e83f4cdd274ebef85449526310eae699a5fbc525904e71889
|
Provenance
The following attestation bundles were made for livetennisapi_haystack-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on livetennisapi/livetennisapi-haystack
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
livetennisapi_haystack-0.1.0-py3-none-any.whl -
Subject digest:
8b090e92ceb9185f4bcafcfd65dadd1b945f67cc62b175f896c5459c2dd46423 - Sigstore transparency entry: 2233076090
- Sigstore integration time:
-
Permalink:
livetennisapi/livetennisapi-haystack@e37f39fa355e0606f09bdf40c496038173570671 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/livetennisapi
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e37f39fa355e0606f09bdf40c496038173570671 -
Trigger Event:
workflow_dispatch
-
Statement type: