Python SDK
Official Python client library for TranslatePlus API - Professional translation service for text, HTML, emails, subtitles, and i18n files in 100+ languages.
Package Information
Package: translateplus-python
Version: 2.0.5+ (Production/Stable)
Python Support: Python 3.8+
License: MIT
Official Repositories
- PyPI: https://pypi.org/project/translateplus-python/ (opens in a new tab)
- GitHub Repository: https://github.com/translateplus/translateplus-python (opens in a new tab)
Installation
pip install translateplus-pythonQuick Start
from translateplus import TranslatePlusClient
# Initialize client
client = TranslatePlusClient(api_key="your-api-key")
# Translate a single text
result = client.translate(
text="Hello, world!",
source="en",
target="fr"
)
print(result["translations"]["translation"])
# Output: "Bonjour le monde !"
# Translate multiple texts
texts = ["Hello", "Goodbye", "Thank you"]
result = client.translate_batch(texts, source="en", target="fr")
for translation in result["translations"]:
print(translation["translation"])Features
- ✅ Full API Support - All endpoints including text, batch, HTML, email, subtitles, and i18n translation
- ✅ Concurrent Requests - Built-in support for parallel translations with configurable concurrency limits
- ✅ Error Handling - Comprehensive exception handling with detailed error messages
- ✅ Type Hints - Full type annotations for better IDE support and code completion
- ✅ Production Ready - Retry logic, rate limiting, and connection pooling
- ✅ 100+ Languages - Support for all languages available in TranslatePlus
API Reference
Client Configuration
from translateplus import TranslatePlusClient
client = TranslatePlusClient(
api_key="your-api-key", # Required: Your TranslatePlus API key
base_url="https://api.translateplus.io", # Optional: API base URL
timeout=30, # Optional: Request timeout in seconds (default: 30)
max_retries=3, # Optional: Maximum retries (default: 3)
max_concurrent=5 # Optional: Max concurrent requests (default: 5)
)Translation Methods
Translate Text
result = client.translate(
text="Hello, world!",
source="en", # Optional, defaults to 'auto'
target="fr" # Required
)
print(result["translations"]["translation"])Batch Translation
texts = ["Hello", "Goodbye", "Thank you"]
result = client.translate_batch(texts, source="en", target="fr")
for translation in result["translations"]:
print(translation["translation"])Translate HTML
html = "<p>Hello <b>world</b></p>"
result = client.translate_html(html, source="en", target="fr")
print(result["html"]) # "<p>Bonjour <b>monde</b></p>"Translate Email
result = client.translate_email(
subject="Welcome",
email_body="<p>Thank you for signing up!</p>",
source="en",
target="fr"
)
print(result["subject"]) # "Bienvenue"
print(result["html_body"]) # "<p>Merci de vous être inscrit!</p>"Translate Subtitles
subtitle_content = "1\n00:00:01,000 --> 00:00:02,000\nHello world\n"
result = client.translate_subtitles(
content=subtitle_content,
format="srt", # or "vtt"
source="en",
target="fr"
)
print(result["content"])Language Methods
Detect Language
result = client.detect_language("Bonjour le monde")
print(result["language_detection"]["language"]) # "fr"
print(result["language_detection"]["confidence"]) # 0.95Get Supported Languages
result = client.get_supported_languages()
languages = result["supported_languages"]
for name, code in languages.items():
print(f"{name}: {code}")Account Methods
Get Account Summary
summary = client.get_account_summary()
print(f"Credits remaining: {summary['credits_remaining']}")
print(f"Plan: {summary['plan_name']}")
print(f"Concurrency limit: {summary['concurrency_limit']}")i18n Translation Jobs
Create i18n Job
result = client.create_i18n_job(
file_path="/path/to/locales/en.json",
target_languages=["fr", "es", "de"],
source_language="en",
webhook_url="https://example.com/webhook" # Optional
)
print(f"Job ID: {result['job_id']}")Get Job Status
status = client.get_i18n_job_status("job-123")
print(f"Status: {status['status']}") # "pending", "processing", "completed", "failed"
print(f"Progress: {status['progress']}%") # PercentageList Jobs
jobs = client.list_i18n_jobs(page=1, page_size=20)
for job in jobs["results"]:
print(f"Job {job['id']}: {job['status']}")Error Handling
The client throws specific exceptions for different error types:
from translateplus import (
TranslatePlusError,
TranslatePlusAPIError,
TranslatePlusAuthenticationError,
TranslatePlusRateLimitError,
TranslatePlusInsufficientCreditsError,
TranslatePlusValidationError
)
try:
result = client.translate(text="Hello", target="fr")
except TranslatePlusAuthenticationError as e:
print(f"Authentication failed: {e}")
except TranslatePlusInsufficientCreditsError as e:
print(f"Insufficient credits: {e}")
print(f"Status code: {e.status_code}")
except TranslatePlusRateLimitError as e:
print(f"Rate limit exceeded: {e}")
except TranslatePlusAPIError as e:
print(f"API error: {e}")
print(f"Status code: {e.status_code}")
print(f"Response: {e.response}")
except TranslatePlusValidationError as e:
print(f"Validation error: {e}")Advanced Usage
Concurrent Translations
The client automatically handles concurrency limits. You can configure the maximum concurrent requests:
client = TranslatePlusClient(
api_key="your-api-key",
max_concurrent=10 # Allow up to 10 concurrent requests
)Custom Timeout and Retries
client = TranslatePlusClient(
api_key="your-api-key",
timeout=60, # 60 second timeout
max_retries=5 # Retry up to 5 times
)Requirements
- Python 3.8 or higher
- pip for package management
Resources
- GitHub Repository: https://github.com/translateplus/translateplus-python (opens in a new tab)
- PyPI Package: https://pypi.org/project/translateplus-python/ (opens in a new tab)
- API Documentation: https://docs.translateplus.io (opens in a new tab)
- Issues: PyPI Package Page (opens in a new tab)
- Support: [email protected]
License
MIT License - see LICENSE (opens in a new tab) file for details.