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"]
)

# 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"]
)

# 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.0.tar.gz (14.0 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.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tatry-1.1.0.tar.gz
  • Upload date:
  • Size: 14.0 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.0.tar.gz
Algorithm Hash digest
SHA256 bd7e9c1d64f1356cb25c41b91c55bcc75edd6e37a78cdfc87a2a5a1d56f6e984
MD5 a5fef86b4d034137cf99c0e4ae7f5995
BLAKE2b-256 6aa540f2467d2e8872c1eaf459f1e0f1445bcb702a085400ccbae565c9ecb425

See more details on using hashes here.

Provenance

The following attestation bundles were made for tatry-1.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: tatry-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b41501b2cb82a24370d3a9ab4828ca50ede5cb21dd666db98d2c513a9154e6a
MD5 e863620bba19c949668ccbbce19373ff
BLAKE2b-256 67ee91592245dd253dab473d43acc0bb5d15abf3b6784856765e531e8cb6bcce

See more details on using hashes here.

Provenance

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