Python client for the Tatry Content Retrieval API
Project description
Tatry
Python client for the Tatry Content Retrieval API
Installation
Install from PyPI:
pip install tatry
To include LangChain integration:
pip install tatry[langchain]
Basic Usage
from tatry import TatryRetriever
# Initialize the client
retriever = TatryRetriever(api_key="your-api-key")
# Search for documents
results = retriever.retrieve(
query="example query",
max_results=5,
sources=["source1", "source2"],
min_score=0.7
)
# Access the results
for doc in results.documents:
print(f"Document ID: {doc.id}")
print(f"Content: {doc.content}")
print(f"Relevance: {doc.relevance_score}")
print(f"Source: {doc.metadata.source}")
print(f"Published Date: {doc.metadata.published_date}")
print("---")
Features
- Simple and intuitive interface for retrieving relevant content
- Support for multiple sources in a single query
- Batch retrieval for efficiently processing multiple queries
- Comprehensive error handling
- Rate limiting and retry capabilities
- Detailed document metadata
LangChain Integration
Tatry can be seamlessly integrated with LangChain:
from tatry.integrations.langchain import TatryRetriever
# Initialize the retriever
retriever = TatryRetriever(
api_key="your-api-key",
max_results=5,
sources=["source1", "source2"],
min_score=0.7
)
# Use it in any LangChain pipeline
documents = retriever.get_relevant_documents("your query")
# Example with a RetrievalQA chain
from langchain.chains import RetrievalQA
from langchain.llms import OpenAI
qa = RetrievalQA.from_chain_type(
llm=OpenAI(),
chain_type="stuff",
retriever=retriever
)
result = qa.run("What is the capital of France?")
API Endpoints
The client supports the following API endpoints:
Document Retrieval
# Simple retrieve
response = retriever.retrieve(query="example", max_results=10)
# Batch retrieve
queries = [
{"query": "example 1", "max_results": 5},
{"query": "example 2", "max_results": 10, "sources": ["source1"]}
]
batch_response = retriever.batch_retrieve(queries)
Authentication
# Validate your API key
validation = retriever.validate_api_key()
Error Handling
The client includes various exception types to help you handle errors:
from tatry import (
RetrieverError,
RetrieverAPIError,
RetrieverAuthError,
RetrieverConfigError,
RetrieverTimeoutError,
RetrieverConnectionError,
)
try:
retriever.retrieve("example")
except RetrieverAuthError:
print("Authentication failed")
except RetrieverTimeoutError:
print("Request timed out")
except RetrieverConnectionError:
print("Connection error")
except RetrieverAPIError as e:
print(f"API error: {e.status_code}")
print(f"Details: {e.details}")
except RetrieverError:
print("Generic error")
Development
To set up the development environment:
pip install -e ".[dev]"
Run tests:
pytest
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.1.1.tar.gz.
File metadata
- Download URL: tatry-1.1.1.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fab5e56b651ff3613caa73bf076cfb09ea58ce288232cc012f77f5552c3765d
|
|
| MD5 |
99e065771d71d11ffaa40da9b3688122
|
|
| BLAKE2b-256 |
49f509c0fa20939d93a9f769c687ad1d601bc17504dd100451a370dbc628f99a
|
Provenance
The following attestation bundles were made for tatry-1.1.1.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.1.1.tar.gz -
Subject digest:
7fab5e56b651ff3613caa73bf076cfb09ea58ce288232cc012f77f5552c3765d - Sigstore transparency entry: 179758486
- Sigstore integration time:
-
Permalink:
tatryai/tatry@b19f6f55c1d69b51302259689e34658c77133164 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/tatryai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b19f6f55c1d69b51302259689e34658c77133164 -
Trigger Event:
push
-
Statement type:
File details
Details for the file tatry-1.1.1-py3-none-any.whl.
File metadata
- Download URL: tatry-1.1.1-py3-none-any.whl
- Upload date:
- Size: 10.9 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 |
158760cb11e1db2e44f6b2922117f7c1fe1b39bdc6ffea4a08276b97eb75f2fc
|
|
| MD5 |
4b17693dcac387be81d550734ffca028
|
|
| BLAKE2b-256 |
9091ce12a886d8ca5f4541a408a66df3238ae68cb52380c1b38e88d32b007286
|
Provenance
The following attestation bundles were made for tatry-1.1.1-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.1.1-py3-none-any.whl -
Subject digest:
158760cb11e1db2e44f6b2922117f7c1fe1b39bdc6ffea4a08276b97eb75f2fc - Sigstore transparency entry: 179758489
- Sigstore integration time:
-
Permalink:
tatryai/tatry@b19f6f55c1d69b51302259689e34658c77133164 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/tatryai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b19f6f55c1d69b51302259689e34658c77133164 -
Trigger Event:
push
-
Statement type: