Python client for the Tatry Content Retrieval API
Project description
Tatry
A Python client for interacting with the Tatry API to retrieve documents based on search queries.
Installation
pip install tatry
Quick Start
from tatry import TatryRetriever
# Initialize the client
retriever = TatryRetriever(
api_key="your_api_key"
)
# Validate your API key
validation = retriever.validate_api_key()
print(f"API key valid: {validation.data.valid}")
print(f"Permissions: {validation.data.permissions}")
# Perform a simple search
results = retriever.retrieve(
query="climate change impact on agriculture",
max_results=5,
sources=["source_id_1", "source_id_2"] # optional
)
# Print retrieved documents
for doc in results.documents:
print(f"Document ID: {doc.id}")
print(f"Score: {doc.relevance_score}")
print(f"Source: {doc.metadata.source}")
print(f"Content: {doc.content[:100]}...")
print("-" * 50)
API Reference
Validation
validate_api_key()
Validates the API key and returns information about associated permissions and rate limits.
Returns:
ValidateResponseobject containing:status: API response statusdata: Validation data including:valid: Boolean indicating if the key is validpermissions: List of permissions granted to this keyorganization_id: Organization ID for the key
Example:
validation = retriever.validate_api_key()
if validation.data.valid:
print("API key is valid")
print(f"Permissions: {validation.data.permissions}")
else:
print("Invalid API key")
Document Retrieval
retrieve(query, max_results=10, sources=[])
Searches for documents using a text query.
Parameters:
query: String containing the search querymax_results: Maximum number of results to return (default: 10)sources: Optional list of source IDs to restrict the search to
Returns:
DocumentResponseobject containing:documents: List of matchingDocumentobjectstotal: Total number of matches found
Example:
results = retriever.retrieve(
query="renewable energy developments",
max_results=5,
sources=["news_source", "academic_papers"]
)
print(f"Found {results.total} documents")
for doc in results.documents:
print(f"{doc.id}: {doc.content[:50]}... (score: {doc.relevance_score})")
batch_retrieve(queries)
Performs multiple searches in a single request.
Parameters:
queries: List of query dictionaries, each containing:query: The search query stringmax_results: Maximum results to return for this query (optional)sources: List of source IDs to search (optional)
Returns:
- List of
BatchQueryResultobjects, each containing:query_id: The query identifier that was provideddocuments: List of matchingDocumentobjects
Example:
batch_results = retriever.batch_retrieve([
{"query": "electric vehicles", "max_results": 3},
{"query": "solar panel efficiency", "max_results": 5, "sources": ["technical_reports"]},
])
for result in batch_results:
print(f"Query ID: {result.query_id}")
print(f"Found {len(result.documents)} documents")
for doc in result.documents:
print(f"- {doc.metadata.source}: {doc.content[:40]}...")
Error Handling
The library provides several exception types to handle different error scenarios:
try:
results = retriever.retrieve("my query")
except RetrieverAuthError as e:
print(f"Authentication failed: {e}")
except RetrieverTimeoutError as e:
print(f"Request timed out: {e}")
except RetrieverConnectionError as e:
print(f"Connection issue: {e}")
except RetrieverAPIError as e:
print(f"API error: {e} (Status: {e.status_code})")
except RetrieverError as e:
print(f"General error: {e}")
Configuration
When initializing the client, you can configure several parameters:
retriever = TatryRetriever(
api_key="your_api_key",
timeout=30, # Request timeout in seconds
max_retries=3 # Maximum number of retry attempts
)
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
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 tatry-1.0.9.tar.gz.
File metadata
- Download URL: tatry-1.0.9.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0046d2bf68a5b73ffe9def02c85c15527cb4e874d3cb25a0b2bb82d3f28de8d
|
|
| MD5 |
a4e86475870373d31bd4420b9138408e
|
|
| BLAKE2b-256 |
8a1b32defa30c5fba75bbcfc78dfb5d83cef45f47a9a165ce7eb9e2dc98b9595
|
Provenance
The following attestation bundles were made for tatry-1.0.9.tar.gz:
Publisher:
publish.yml on tatryai/tatry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tatry-1.0.9.tar.gz -
Subject digest:
d0046d2bf68a5b73ffe9def02c85c15527cb4e874d3cb25a0b2bb82d3f28de8d - Sigstore transparency entry: 176483951
- Sigstore integration time:
-
Permalink:
tatryai/tatry@63254aba5e0598018fc44ee55bbb5f436f4474b8 -
Branch / Tag:
refs/tags/v1.0.9 - Owner: https://github.com/tatryai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@63254aba5e0598018fc44ee55bbb5f436f4474b8 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tatry-1.0.9-py3-none-any.whl.
File metadata
- Download URL: tatry-1.0.9-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2f9698b810c7f7aed37d0fe814d9228a69aa83b597222f4236fc07d98fd6ecc
|
|
| MD5 |
1816c4d8b25ce7c1ea22cfa317d65762
|
|
| BLAKE2b-256 |
58680cc717bd11e04e882dbadd9d4d364e781b46d127b50fc6fb3e7d7c4fba89
|
Provenance
The following attestation bundles were made for tatry-1.0.9-py3-none-any.whl:
Publisher:
publish.yml on tatryai/tatry
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tatry-1.0.9-py3-none-any.whl -
Subject digest:
b2f9698b810c7f7aed37d0fe814d9228a69aa83b597222f4236fc07d98fd6ecc - Sigstore transparency entry: 176483963
- Sigstore integration time:
-
Permalink:
tatryai/tatry@63254aba5e0598018fc44ee55bbb5f436f4474b8 -
Branch / Tag:
refs/tags/v1.0.9 - Owner: https://github.com/tatryai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@63254aba5e0598018fc44ee55bbb5f436f4474b8 -
Trigger Event:
push
-
Statement type: