Lingo.dev Python SDK
Project description
Lingo.dev Python SDK
A powerful async-first localization engine that supports various content types including plain text, objects, chat sequences, and HTML documents.
✨ Key Features
- 🚀 Async-first design for high-performance concurrent translations
- 🔀 Concurrent processing for dramatically faster bulk translations
- 🎯 Multiple content types: text, objects, chat messages, and more
- 🌐 Auto-detection of source languages
- ⚡ Fast mode for quick translations
- 🔧 Flexible configuration with progress callbacks
- 📦 Context manager support for proper resource management
🚀 Performance Benefits
The async implementation provides significant performance improvements:
- Concurrent chunk processing for large payloads
- Batch operations for multiple translations
- Parallel API requests instead of sequential ones
- Better resource management with httpx
📦 Installation
pip install lingodotdev
🎯 Quick Start
Simple Translation
import asyncio
from lingodotdev import LingoDotDevEngine
async def main():
# Quick one-off translation (handles context management automatically)
result = await LingoDotDevEngine.quick_translate(
"Hello, world!",
api_key="your-api-key",
target_locale="es"
)
print(result) # "¡Hola, mundo!"
asyncio.run(main())
Context Manager (Recommended for Multiple Operations)
import asyncio
from lingodotdev import LingoDotDevEngine
async def main():
config = {
"api_key": "your-api-key",
"api_url": "https://engine.lingo.dev" # Optional, defaults to this
}
async with LingoDotDevEngine(config) as engine:
# Translate text
text_result = await engine.localize_text(
"Hello, world!",
{"target_locale": "es"}
)
# Translate object with concurrent processing
obj_result = await engine.localize_object(
{
"greeting": "Hello",
"farewell": "Goodbye",
"question": "How are you?"
},
{"target_locale": "es"},
concurrent=True # Process chunks concurrently for speed
)
asyncio.run(main())
🔥 Advanced Usage
Batch Processing (Multiple Target Languages)
async def batch_example():
# Translate to multiple languages at once
results = await LingoDotDevEngine.quick_batch_translate(
"Welcome to our application",
api_key="your-api-key",
target_locales=["es", "fr", "de", "it"]
)
# Results: ["Bienvenido...", "Bienvenue...", "Willkommen...", "Benvenuto..."]
Large Object Processing with Progress
async def progress_example():
def progress_callback(progress, source_chunk, processed_chunk):
print(f"Progress: {progress}% - Processed {len(processed_chunk)} items")
large_content = {f"item_{i}": f"Content {i}" for i in range(1000)}
async with LingoDotDevEngine({"api_key": "your-api-key"}) as engine:
result = await engine.localize_object(
large_content,
{"target_locale": "es"},
progress_callback=progress_callback,
concurrent=True # Much faster for large objects
)
Chat Translation
async def chat_example():
chat_messages = [
{"name": "Alice", "text": "Hello everyone!"},
{"name": "Bob", "text": "How is everyone doing?"},
{"name": "Charlie", "text": "Great to see you all!"}
]
async with LingoDotDevEngine({"api_key": "your-api-key"}) as engine:
translated_chat = await engine.localize_chat(
chat_messages,
{"source_locale": "en", "target_locale": "es"}
)
# Names preserved, text translated
Multiple Objects Concurrently
async def concurrent_objects_example():
objects = [
{"title": "Welcome", "description": "Please sign in"},
{"error": "Invalid input", "help": "Check your email"},
{"success": "Account created", "next": "Continue to dashboard"}
]
async with LingoDotDevEngine({"api_key": "your-api-key"}) as engine:
results = await engine.batch_localize_objects(
objects,
{"target_locale": "fr"}
)
# All objects translated concurrently
Language Detection
async def detection_example():
async with LingoDotDevEngine({"api_key": "your-api-key"}) as engine:
detected = await engine.recognize_locale("Bonjour le monde")
print(detected) # "fr"
⚙️ Configuration Options
config = {
"api_key": "your-api-key", # Required: Your API key
"api_url": "https://engine.lingo.dev", # Optional: API endpoint
"batch_size": 25, # Optional: Items per batch (1-250)
"ideal_batch_item_size": 250 # Optional: Target words per batch (1-2500)
}
🎛️ Method Parameters
Translation Parameters
- source_locale: Source language code (auto-detected if None)
- target_locale: Target language code (required)
- fast: Enable fast mode for quicker translations
- reference: Reference translations for context
- concurrent: Process chunks concurrently (faster, but no progress callbacks)
Performance Options
- concurrent=True: Enables parallel processing of chunks
- progress_callback: Function to track progress (disabled with concurrent=True)
🔧 Error Handling
async def error_handling_example():
try:
async with LingoDotDevEngine({"api_key": "invalid-key"}) as engine:
result = await engine.localize_text("Hello", {"target_locale": "es"})
except ValueError as e:
print(f"Invalid request: {e}")
except RuntimeError as e:
print(f"API error: {e}")
🚀 Performance Tips
- Use
concurrent=Truefor large objects or multiple chunks - Use
batch_localize_objects()for multiple objects - Use context managers for multiple operations
- Use
quick_translate()for one-off translations - Adjust
batch_sizebased on your content structure
🤝 Migration from Sync Version
The async version is a drop-in replacement with these changes:
- Add
async/awaitto all method calls - Use
async withfor context managers - All methods now return awaitable coroutines
📚 API Reference
Core Methods
localize_text(text, params)- Translate text stringslocalize_object(obj, params)- Translate dictionary objectslocalize_chat(chat, params)- Translate chat messagesbatch_localize_text(text, params)- Translate to multiple languagesbatch_localize_objects(objects, params)- Translate multiple objectsrecognize_locale(text)- Detect languagewhoami()- Get API account info
Convenience Methods
quick_translate(content, api_key, target_locale, ...)- One-off translationquick_batch_translate(content, api_key, target_locales, ...)- Batch translation
📄 License
Apache-2.0 License
🤖 Support
- 📚 Documentation
- 🐛 Issues
- 💬 Community
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 lingodotdev-1.2.0.tar.gz.
File metadata
- Download URL: lingodotdev-1.2.0.tar.gz
- Upload date:
- Size: 18.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f0477915178f687a827366bc78fbcb90b2ff155ed9d3a09267e6b82a9d562642
|
|
| MD5 |
baed45b18c5946a94985b75fcc4d7eb6
|
|
| BLAKE2b-256 |
ae6cc9fdd32e6cb2dc3fe76f4212432fa472a05d84a6f442f2d0b49c6cb4ce68
|
Provenance
The following attestation bundles were made for lingodotdev-1.2.0.tar.gz:
Publisher:
release.yml on lingodotdev/sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lingodotdev-1.2.0.tar.gz -
Subject digest:
f0477915178f687a827366bc78fbcb90b2ff155ed9d3a09267e6b82a9d562642 - Sigstore transparency entry: 301584317
- Sigstore integration time:
-
Permalink:
lingodotdev/sdk-python@5b32b3cb60630cd0f1643f86cb848a5344ea52fc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lingodotdev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5b32b3cb60630cd0f1643f86cb848a5344ea52fc -
Trigger Event:
push
-
Statement type:
File details
Details for the file lingodotdev-1.2.0-py3-none-any.whl.
File metadata
- Download URL: lingodotdev-1.2.0-py3-none-any.whl
- Upload date:
- Size: 12.8 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 |
274432e97da303e783575c1304e229b6ce900f4d05e6bc1365ab1993abc06601
|
|
| MD5 |
bed27315b5e96b828e3458ba18b91123
|
|
| BLAKE2b-256 |
21b010f9bdbfe6a01e9277ffa01ae76d5e0282d6d21f2b0b80aaf4dc9908364d
|
Provenance
The following attestation bundles were made for lingodotdev-1.2.0-py3-none-any.whl:
Publisher:
release.yml on lingodotdev/sdk-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
lingodotdev-1.2.0-py3-none-any.whl -
Subject digest:
274432e97da303e783575c1304e229b6ce900f4d05e6bc1365ab1993abc06601 - Sigstore transparency entry: 301584321
- Sigstore integration time:
-
Permalink:
lingodotdev/sdk-python@5b32b3cb60630cd0f1643f86cb848a5344ea52fc -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lingodotdev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@5b32b3cb60630cd0f1643f86cb848a5344ea52fc -
Trigger Event:
push
-
Statement type: