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.1.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.1-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

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

Hashes for tatry-1.1.1.tar.gz
Algorithm Hash digest
SHA256 7fab5e56b651ff3613caa73bf076cfb09ea58ce288232cc012f77f5552c3765d
MD5 99e065771d71d11ffaa40da9b3688122
BLAKE2b-256 49f509c0fa20939d93a9f769c687ad1d601bc17504dd100451a370dbc628f99a

See more details on using hashes here.

Provenance

The following attestation bundles were made for tatry-1.1.1.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.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

Hashes for tatry-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 158760cb11e1db2e44f6b2922117f7c1fe1b39bdc6ffea4a08276b97eb75f2fc
MD5 4b17693dcac387be81d550734ffca028
BLAKE2b-256 9091ce12a886d8ca5f4541a408a66df3238ae68cb52380c1b38e88d32b007286

See more details on using hashes here.

Provenance

The following attestation bundles were made for tatry-1.1.1-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