Skip to main content

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

tatry-1.1.2.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

tatry-1.1.2-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file tatry-1.1.2.tar.gz.

File metadata

  • Download URL: tatry-1.1.2.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

Hashes for tatry-1.1.2.tar.gz
Algorithm Hash digest
SHA256 7771e06951186f788fabcd2bcadd7ff43416ae445642a2bc2f4634be1818e132
MD5 2741bbe3b23cd082fcad3281d121de10
BLAKE2b-256 2587e2af9a9346aa40a9731ee65985a497b3f061f329bc264b0a44ce9a6ecd37

See more details on using hashes here.

Provenance

The following attestation bundles were made for tatry-1.1.2.tar.gz:

Publisher: publish.yml on tatryai/tatry

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

File details

Details for the file tatry-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: tatry-1.1.2-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

Hashes for tatry-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 08694f20899576c1f3c171d41d430c81c9a7f44221a57cdf6bd909b8dcb8f7e6
MD5 dbf1cfb692a9a22dc7b7aca14dd161bf
BLAKE2b-256 f85fc4e620c87a2429022a4e4279354035079d86a48b0a1dbd920eda8e0be6af

See more details on using hashes here.

Provenance

The following attestation bundles were made for tatry-1.1.2-py3-none-any.whl:

Publisher: publish.yml on tatryai/tatry

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