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
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.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca95f65e2ac83bff09c9c819933e98adba505d7563b71dd8ead93d4d0496f4e3
|
|
| MD5 |
405623fcb0bf124be723cee8e3e6125b
|
|
| BLAKE2b-256 |
f04ece719d2b3f5720e982e1f089acf2ce2f78c1ecb33f83e20ac18abd7141f8
|
Provenance
The following attestation bundles were made for tatry-1.0.8.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.0.8.tar.gz -
Subject digest:
ca95f65e2ac83bff09c9c819933e98adba505d7563b71dd8ead93d4d0496f4e3 - Sigstore transparency entry: 172987878
- Sigstore integration time:
-
Permalink:
tatryai/tatry@9166d2640f05eb5e3b47db18121dea267d07a84b -
Branch / Tag:
refs/tags/v1.0.8 - Owner: https://github.com/tatryai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9166d2640f05eb5e3b47db18121dea267d07a84b -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6d51516d78f635c044f66b9262f985ed275f79c29633671af4f18e9a3d5a484
|
|
| MD5 |
0e4b122dcc5f7cd908010dfac6c6194e
|
|
| BLAKE2b-256 |
b221cab2236a32d8754b2fce37148013dfcae0566c58a68a5886091f6b95cef7
|
Provenance
The following attestation bundles were made for tatry-1.0.8-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.0.8-py3-none-any.whl -
Subject digest:
f6d51516d78f635c044f66b9262f985ed275f79c29633671af4f18e9a3d5a484 - Sigstore transparency entry: 172987881
- Sigstore integration time:
-
Permalink:
tatryai/tatry@9166d2640f05eb5e3b47db18121dea267d07a84b -
Branch / Tag:
refs/tags/v1.0.8 - Owner: https://github.com/tatryai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@9166d2640f05eb5e3b47db18121dea267d07a84b -
Trigger Event:
push
-
Statement type: