11# langbly-python
22
3- Official Python SDK for the [ Langbly] ( https://langbly.com ) translation API — a drop-in replacement for Google Translate v2.
3+ [ ![ PyPI] ( https://img.shields.io/pypi/v/langbly )] ( https://pypi.org/project/langbly/ )
4+ [ ![ Python] ( https://img.shields.io/pypi/pyversions/langbly )] ( https://pypi.org/project/langbly/ )
5+ [ ![ License: MIT] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( LICENSE )
6+
7+ Official Python SDK for the [ Langbly] ( https://langbly.com ) translation API — a drop-in replacement for Google Translate v2, powered by LLMs.
8+
9+ ** 5-10x cheaper than Google Translate** · ** Better quality** · ** Switch in one PR**
410
511## Installation
612
@@ -27,54 +33,87 @@ for r in results:
2733# Detect language
2834detection = client.detect(" Bonjour le monde" )
2935print (detection.language) # "fr"
36+
37+ # List supported languages
38+ languages = client.languages(target = " en" )
3039```
3140
32- ## Google Translate Migration
41+ ## Migrate from Google Translate
3342
34- If you're using ` google-cloud-translate ` , switching is simple :
43+ Already using ` google-cloud-translate ` ? Switching takes 2 minutes :
3544
3645``` python
37- # Before (Google)
46+ # Before (Google Translate )
3847from google.cloud import translate_v2 as translate
3948client = translate.Client()
4049result = client.translate(" Hello" , target_language = " nl" )
4150
42- # After (Langbly)
51+ # After (Langbly) — same concepts, better translations, 5x cheaper
4352from langbly import Langbly
4453client = Langbly(api_key = " your-key" )
4554result = client.translate(" Hello" , target = " nl" )
4655```
4756
57+ → Full migration guide: [ langbly.com/docs/migrate-google] ( https://langbly.com/docs/migrate-google )
58+
59+ ## Features
60+
61+ - ** Google Translate v2 API compatible** — same endpoint format
62+ - ** Auto-retry** — exponential backoff on 429/5xx with Retry-After support
63+ - ** Typed errors** — ` RateLimitError ` , ` AuthenticationError ` , ` LangblyError `
64+ - ** Batch translation** — translate multiple texts in one request
65+ - ** Language detection** — automatic source language identification
66+ - ** HTML support** — translate HTML while preserving tags
67+ - ** Context manager** — use ` with ` for automatic cleanup
68+
69+ ## Error Handling
70+
71+ ``` python
72+ from langbly import Langbly, RateLimitError, AuthenticationError
73+
74+ client = Langbly(api_key = " your-key" )
75+
76+ try :
77+ result = client.translate(" Hello" , target = " nl" )
78+ except AuthenticationError:
79+ print (" Invalid API key" )
80+ except RateLimitError as e:
81+ print (f " Rate limited — retry after { e.retry_after} s " )
82+ ```
83+
4884## API Reference
4985
50- ### ` Langbly(api_key, base_url=None) `
86+ ### ` Langbly(api_key, base_url=None, timeout=30.0, max_retries=2 ) `
5187
5288Create a client instance.
5389
54- - ` api_key ` (str): Your Langbly API key
90+ - ` api_key ` (str): Your Langbly API key — [ get one free ] ( https://langbly.com/signup )
5591- ` base_url ` (str, optional): Override the API URL (default: ` https://api.langbly.com ` )
92+ - ` timeout ` (float, optional): Request timeout in seconds (default: 30)
93+ - ` max_retries ` (int, optional): Retries for transient errors (default: 2)
5694
5795### ` client.translate(text, target, source=None, format=None) `
5896
59- Translate text.
60-
6197- ` text ` (str | list[ str] ): Text(s) to translate
6298- ` target ` (str): Target language code (e.g., "nl", "de", "fr")
6399- ` source ` (str, optional): Source language code (auto-detected if omitted)
64100- ` format ` (str, optional): "text" or "html"
65101
66102### ` client.detect(text) `
67103
68- Detect the language of text.
69-
70104- ` text ` (str): Text to analyze
71105
72106### ` client.languages(target=None) `
73107
74- List supported languages.
75-
76108- ` target ` (str, optional): Language code to return names in
77109
110+ ## Links
111+
112+ - [ Website] ( https://langbly.com )
113+ - [ Documentation] ( https://langbly.com/docs )
114+ - [ Compare: Langbly vs Google vs DeepL] ( https://langbly.com/compare )
115+ - [ JavaScript/TypeScript SDK] ( https://github.com/Langbly/langbly-js )
116+
78117## License
79118
80119MIT
0 commit comments