Skip to main content

Python client for the Tatry Content Retrieval API

Project description

Tatry Python SDK

Official Python SDK for the Tatry Content Retrieval API.

Installation

pip install tatry

Quick Start

from tatry import TatryRetriever

# Initialize the retriever
retriever = TatryRetriever(api_key="your_api_key")

# Search for documents
results = retriever.retrieve("quantum computing", max_results=5, ["medical"])
for doc in results.documents:
    print(f"Citation: {doc.metadata.citation}")
    print(f"Content: {doc.content[:200]}...")
    print(f"Relevance: {doc.relevance_score}")
    print("---")

Features

  • 🔍 Content Search: Search across multiple sources with relevance scoring
  • 📚 Source Management: Browse and access different content sources
  • 📊 Usage Statistics: Track your API usage
  • 🔒 Authentication: Secure API key management
  • 💬 Feedback System: Submit and track user feedback
  • Batch Operations: Perform multiple searches in one request
  • 🛡️ Type Safety: Full type hinting support with Pydantic models
  • 🔄 Automatic Retries: Built-in retry mechanism with exponential backoff

Authentication

from tatry import TatryRetriever

retriever = TatryRetriever(api_key="your_api_key")

# Validate your API key
validation = retriever.auth.validate_api_key()
print(f"API Key Valid: {validation.data.valid}")
print(f"Permissions: {validation.data.permissions}")
print(f"Rate Limits: {validation.data.rate_limits.requests_per_minute}/min")

# List all API keys
keys = retriever.auth.list_keys(status="active")
for key in keys:
    print(f"Key: {key.id}")
    print(f"Last Used: {key.last_used_at}")

Content Retrieval

Single Search

# Basic search
results = retriever.retrieve.retrieve("artificial intelligence")

# Search with parameters
results = retriever.retrieve.retrieve(
    query="machine learning frameworks",
    max_results=10
)

Batch Search

# Perform multiple searches at once
queries = [
    {"query": "neural networks", "max_results": 5},
    {"query": "deep learning", "max_results": 3}
]
results = retriever.retrieve.batch_retrieve(queries)

Source Management

# List all available sources
sources = retriever.sources.list_sources()
for source in sources:
    print(f"Source: {source.name}")
    print(f"Type: {source.type}")
    print(f"Coverage: {', '.join(source.coverage)}")

# Get detailed information about a specific source
wikipedia = retriever.sources.get_source("wikipedia")
print(f"Total Documents: {wikipedia.metadata.total_documents}")
print(f"Languages: {', '.join(wikipedia.metadata.languages)}")

Usage Statistics

# Get current month's usage
usage = retriever.utils.get_usage()
print(f"Total Queries: {usage.data.usage.queries.total}")
print(f"Documents Retrieved: {usage.data.usage.documents.total}")

# Get usage for a specific month
usage = retriever.utils.get_usage(month="2024-01")

Feedback System

# Submit feedback
feedback = retriever.utils.submit_feedback(
    feedback_type="feature",
    description="Would love to see more academic sources",
    metadata={"user_type": "researcher"}
)
print(f"Feedback ID: {feedback.data.id}")

Error Handling

from tatry import TatryError, TatryAPIError, TatryAuthError

try:
    results = retriever.retrieve.search("quantum computing")
except TatryAuthError:
    print("Authentication failed")
except TatryAPIError as e:
    print(f"API error: {e.status_code}")
except TatryError as e:
    print(f"General error: {str(e)}")

Configuration

retriever = TatryRetriever(
    api_key="your_api_key",
    timeout=30,                         # Request timeout in seconds
    max_retries=3                      # Maximum retry attempts
)

Development

# Clone the repository
git clone https://github.com/tatryai/tatry.git
cd tatry

# Create virtual environment
python -m venv venv
source venv/bin/activate  # or `venv\Scripts\activate` on Windows

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

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.0.8.tar.gz (13.8 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.0.8-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tatry-1.0.8.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for tatry-1.0.8.tar.gz
Algorithm Hash digest
SHA256 ca95f65e2ac83bff09c9c819933e98adba505d7563b71dd8ead93d4d0496f4e3
MD5 405623fcb0bf124be723cee8e3e6125b
BLAKE2b-256 f04ece719d2b3f5720e982e1f089acf2ce2f78c1ecb33f83e20ac18abd7141f8

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: tatry-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 9.7 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.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 f6d51516d78f635c044f66b9262f985ed275f79c29633671af4f18e9a3d5a484
MD5 0e4b122dcc5f7cd908010dfac6c6194e
BLAKE2b-256 b221cab2236a32d8754b2fce37148013dfcae0566c58a68a5886091f6b95cef7

See more details on using hashes here.

Provenance

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