A unified Python SDK for multiple translation providers
Project description
Deka 🌍
A unified Python SDK for multiple translation providers with advanced model selection and African language support. Compare translations from Google Translate, DeepL, OpenAI, Anthropic, Gemini, and GhanaNLP with a single, simple interface.
✨ Features
- 🎯 Model Selection: Choose specific AI models (gpt-4, claude-3-5-sonnet, gemini-2.0-flash)
- 🌍 African Languages: Dedicated support for 11 African languages via GhanaNLP
- 🔄 Provider Comparison: Compare translations side-by-side across providers and models
- 🚀 6 Providers: Google Translate, DeepL, OpenAI, Anthropic, Gemini, GhanaNLP
- 📝 Language Normalization: Use natural language names ("french") or ISO codes ("fr")
- ⚡ Async Support: Full async/await support for better performance
- 🔒 Type Safety: Complete type hints for better development experience
- 🔑 Bring Your Own Keys: Use your own API keys, no vendor lock-in
- ⚠️ Permissive Validation: Try new models without SDK updates
🚀 Quick Start
Installation
pip install deka
Basic Usage
import deka
# Configure with your API keys
deka.configure({
'google_api_key': 'your-google-key',
'deepl_api_key': 'your-deepl-key',
'openai_api_key': 'your-openai-key',
'anthropic_api_key': 'your-anthropic-key',
'gemini_api_key': 'your-gemini-key',
'ghananlp_api_key': 'your-ghananlp-key',
})
# Simple translation
result = deka.translate("Hello world", "french", provider="google")
print(result.text) # "Bonjour le monde"
# Model selection - choose specific AI models
result = deka.translate("Hello", "spanish", provider="openai/gpt-4")
print(result.text) # "Hola"
# African languages with GhanaNLP
result = deka.translate("Thank you", "twi", provider="ghananlp")
print(result.text) # "Meda wo ase"
# Compare multiple providers and models
comparison = deka.compare("Hello world", "spanish", providers=[
"google",
"openai/gpt-4",
"anthropic/claude-3-5-sonnet"
])
for result in comparison.results:
print(f"{result.provider}: {result.text}")
Async Usage
import asyncio
import deka
async def main():
# Configure first
deka.configure({'openai_api_key': 'your-key'})
# Async translation
result = await deka.translate_async("Hello", "japanese", provider="openai")
print(result.text)
# Async comparison (runs providers concurrently)
comparison = await deka.compare_async("Hello", "korean", providers=["google", "openai"])
print(f"Fastest: {comparison.fastest_provider}")
asyncio.run(main())
🔧 Supported Providers
| Provider | Type | Languages | Models | Features |
|---|---|---|---|---|
| Google Translate | API | 100+ | - | Fast, reliable, auto-detection |
| DeepL | API | 30+ | - | High quality, European languages |
| OpenAI | LLM | Any | 5 models | Context-aware, creative translations |
| Anthropic Claude | LLM | Any | 5 models | Nuanced, culturally-aware translations |
| Google Gemini | LLM | Any | 5 models | Latest Google AI, multimodal |
| GhanaNLP | API | 11 African | - | Specialized African languages |
🤖 Available Models
OpenAI Models:
gpt-4- Most capable, slowergpt-4-turbo- Faster than gpt-4gpt-4o- Optimized for speed and costgpt-3.5-turbo- Fast, cheap (default)gpt-4o-mini- Smallest, fastest
Anthropic Models:
claude-3-5-sonnet-20241022- Latest, most capable (default)claude-3-sonnet-20240229- Balanced performanceclaude-3-haiku-20240307- Fastest, cheapestclaude-3-opus-20240229- Most capable (older)
Gemini Models:
gemini-2.0-flash-001- Latest, fastest (default)gemini-1.5-pro- High capability, longer contextgemini-1.5-flash- Fast, efficient
GhanaNLP Languages:
- Ghanaian: Twi, Ga, Ewe, Fante, Dagbani, Gurene
- Other African: Yoruba, Kikuyu, Luo, Kimeru
📖 Documentation
Configuration
import deka
# Configure all providers at once
deka.configure({
'google_api_key': 'your-google-translate-api-key',
'deepl_api_key': 'your-deepl-api-key',
'openai_api_key': 'your-openai-api-key',
'anthropic_api_key': 'your-anthropic-api-key',
})
# Or configure individual providers
deka.configure({'google_api_key': 'your-key'})
Translation
# Basic translation
result = deka.translate(
text="Hello world",
target_language="french",
provider="google"
)
# Model selection - choose specific AI models
result = deka.translate(
text="Hello world",
target_language="french",
provider="openai/gpt-4" # Use GPT-4 specifically
)
result = deka.translate(
text="Hello world",
target_language="french",
provider="anthropic/claude-3-5-sonnet-20241022" # Use latest Claude
)
# African languages with GhanaNLP
result = deka.translate(
text="Good morning",
target_language="twi", # Ghanaian language
provider="ghananlp"
)
# With source language specified
result = deka.translate(
text="Bonjour",
target_language="english",
source_language="french",
provider="deepl"
)
# Auto-select provider (uses first configured)
result = deka.translate("Hello", "spanish")
Comparison
# Compare specific providers
comparison = deka.compare(
text="Hello world",
target_language="german",
providers=["google", "deepl", "openai"]
)
# Access results
for result in comparison.results:
print(f"{result.provider}: {result.text} ({result.response_time_ms}ms)")
# Get fastest/best result
fastest = comparison.fastest_provider
best_confidence = comparison.highest_confidence
google_result = comparison.get_result_by_provider("google")
Language Support
# List all supported languages
languages = deka.list_languages()
print(languages[:5]) # ['english', 'french', 'spanish', 'german', 'italian']
# Normalize language names
normalized = deka.normalize_language("français") # returns "french"
normalized = deka.normalize_language("zh") # returns "chinese"
# List configured providers
providers = deka.list_providers()
🔑 API Keys Setup
Google Translate
- Go to Google Cloud Console
- Enable the Cloud Translation API
- Create credentials and get your API key
DeepL
- Sign up at DeepL API
- Get your authentication key
- Note: Free tier keys end with
:fx
OpenAI
- Sign up at OpenAI
- Go to API Keys section
- Create a new API key
Anthropic
- Sign up at Anthropic
- Go to API Keys section
- Create a new API key
Google Gemini
- Go to Google AI Studio
- Create a new API key
- Note: Different from Google Translate API
GhanaNLP
- Visit GhanaNLP Translation API
- Sign up for an API key
- Specialized for African languages
🎯 Use Cases
- A/B Testing Translations: Compare quality across providers
- Fallback Systems: Try multiple providers for reliability
- Cost Optimization: Compare pricing and choose best value
- Quality Assessment: Find the best translation for your content
- Multi-Provider Apps: Let users choose their preferred provider
🤝 Contributing
We welcome contributions! Please see our Contributing Guide for details.
📄 License
MIT License - see LICENSE file for details.
🔗 Links
Made with ❤️ by Josue Godeme
Project details
Release history Release notifications | RSS feed
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 deka-0.1.0.tar.gz.
File metadata
- Download URL: deka-0.1.0.tar.gz
- Upload date:
- Size: 21.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
37e56643e127ae10f5684318277122a8928b99c585c0a3672bda5a7ba1ef76b2
|
|
| MD5 |
d14d215cad5e761d3fe3a84823f6f90e
|
|
| BLAKE2b-256 |
f4efaf069a86e7b2277ad0fbd594263e957c213ac4243e899c093868b4ad07c2
|
File details
Details for the file deka-0.1.0-py3-none-any.whl.
File metadata
- Download URL: deka-0.1.0-py3-none-any.whl
- Upload date:
- Size: 27.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9fc3718ccdf3f403f217abedc52ed49a799384b5c7d11cd2336f60b11ee5a70f
|
|
| MD5 |
bf8334bdb29109d7c0e0034f9be5eb37
|
|
| BLAKE2b-256 |
1844fb643ec18bf345d6127ca58af415b972377227aae688e7a90b512e51b772
|