https://github.com/argosopentech/libretranslate-py
Python bindings to connect to a LibreTranslate API
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (4.5%) to scientific vocabulary
Repository
Python bindings to connect to a LibreTranslate API
Basic Info
- Host: GitHub
- Owner: argosopentech
- License: mit
- Language: Python
- Default Branch: main
- Homepage: https://pypi.org/project/libretranslatepy/
- Size: 52.7 KB
Statistics
- Stars: 119
- Watchers: 5
- Forks: 13
- Open Issues: 5
- Releases: 0
Metadata Files
README.md
LibreTranslate-py
Python bindings to connect to a LibreTranslate API
https://pypi.org/project/libretranslatepy/
Install
pip install libretranslatepy
Example usage
```python from libretranslatepy import LibreTranslateAPI
lt = LibreTranslateAPI("https://libretranslate.com/")
print(lt.translate("LibreTranslate is awesome!", "en", "es"))
LibreTranslate es impresionante!
print(lt.detect("Hello World"))
[{"confidence": 0.6, "language": "en"}]
print(lt.languages())
[{"code":"en", "name":"English"}, {"code":"es", "name":"Spanish"}]
```
LibreTranslate Mirrors
Source
```python import json import sys from urllib import request, parse
class LibreTranslateAPI: """Connect to the LibreTranslate API"""
"""Example usage:
from libretranslatepy import LibreTranslateAPI
lt = LibreTranslateAPI("https://translate.terraprint.co/")
print(lt.translate("LibreTranslate is awesome!", "en", "es"))
# LibreTranslate es impresionante!
print(lt.detect("Hello World"))
# [{"confidence": 0.6, "language": "en"}]
print(lt.languages())
# [{"code":"en", "name":"English"}]
"""
DEFAULT_URL = "https://translate.terraprint.co/"
def __init__(self, url=None, api_key=None):
"""Create a LibreTranslate API connection.
Args:
url (str): The url of the LibreTranslate endpoint.
api_key (str): The API key.
"""
self.url = LibreTranslateAPI.DEFAULT_URL if url is None else url
self.api_key = api_key
# Add trailing slash
assert len(self.url) > 0
if self.url[-1] != "/":
self.url += "/"
def translate(self, q, source="en", target="es"):
"""Translate string
Args:
q (str): The text to translate
source (str): The source language code (ISO 639)
target (str): The target language code (ISO 639)
Returns:
str: The translated text
"""
url = self.url + "translate"
params = {"q": q, "source": source, "target": target}
if self.api_key is not None:
params["api_key"] = self.api_key
url_params = parse.urlencode(params)
req = request.Request(url, data=url_params.encode())
response = request.urlopen(req)
response_str = response.read().decode()
return json.loads(response_str)["translatedText"]
def detect(self, q):
"""Detect the language of a single text.
Args:
q (str): Text to detect
Returns:
The detected languages ex: [{"confidence": 0.6, "language": "en"}]
"""
url = self.url + "detect"
params = {"q": q}
if self.api_key is not None:
params["api_key"] = self.api_key
url_params = parse.urlencode(params)
req = request.Request(url, data=url_params.encode())
response = request.urlopen(req)
response_str = response.read().decode()
return json.loads(response_str)
def languages(self):
"""Retrieve list of supported languages.
Returns:
A list of available languages ex: [{"code":"en", "name":"English"}]
"""
url = self.url + "languages"
params = dict()
if self.api_key is not None:
params["api_key"] = self.api_key
url_params = parse.urlencode(params)
req = request.Request(url, data=url_params.encode(), method="GET")
response = request.urlopen(req)
response_str = response.read().decode()
return json.loads(response_str)
```
License
Licensed under either the MIT License or Public Domain
Developed by P.J. Finlay
Owner
- Name: Argos Open Tech
- Login: argosopentech
- Kind: user
- Location: Ithaca, NY
- Website: www.argosopentech.com
- Twitter: argosopentech
- Repositories: 86
- Profile: https://github.com/argosopentech
GitHub Events
Total
- Issues event: 2
- Watch event: 25
- Issue comment event: 3
- Push event: 5
- Pull request event: 1
- Fork event: 4
Last Year
- Issues event: 2
- Watch event: 25
- Issue comment event: 3
- Push event: 5
- Pull request event: 1
- Fork event: 4
Committers
Last synced: 10 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| P.J. Finlay | p****t@g****m | 32 |
| Argos Open Tech | 4****h | 12 |
| Pedro Torcatt | p****o@g****m | 2 |
| Mats Bjerin | m****j@c****e | 2 |
| Ente | d****e@d****h | 1 |
| ChinoCodeDemon | l****a@a****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 6 months ago
All Time
- Total issues: 8
- Total pull requests: 6
- Average time to close issues: 3 months
- Average time to close pull requests: 2 days
- Total issue authors: 7
- Total pull request authors: 5
- Average comments per issue: 2.13
- Average comments per pull request: 1.17
- Merged pull requests: 5
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 2
- Pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 2
- Pull request authors: 1
- Average comments per issue: 0.0
- Average comments per pull request: 0.0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- PJ-Finlay (2)
- Cesilina (1)
- romran (1)
- jasperan (1)
- Terrtia (1)
- ahyear (1)
- riyaj8888 (1)
Pull Request Authors
- Jalkhov (2)
- dticed (2)
- LunaCodeDemon (1)
- MatsBjerin (1)
- Enteee (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 473,655 last-month
- Total docker downloads: 346
- Total dependent packages: 4
- Total dependent repositories: 161
- Total versions: 7
- Total maintainers: 1
pypi.org: libretranslatepy
Python bindings for LibreTranslate API
- Homepage: https://github.com/argosopentech/LibreTranslate-py
- Documentation: https://libretranslatepy.readthedocs.io/
- License: MIT License
-
Latest release: 2.1.4
published almost 2 years ago