Python bindings for LibreTranslate

Overview

LibreTranslate-py

Python bindings for LibreTranslate

Install

pip install libretranslatepy

Example usage

from libretranslatepy import api
api.translate('Hello World', 'en', 'es', 'https://translate.astian.org/translate')

Source

import json
import sys
from urllib import request, parse


def translate(q, source="en", target="es", url="https://translate.astian.org/translate"):
    """Connect to LibreTranslate API

    Args:
        q (str): The text to translate
        source (str): The source language code (ISO 639)
        target (str): The target language code (ISO 639)
    
    Returns: The translated text
    """
    params = {"q": q, "source": source, "target": target}

    url_params = parse.urlencode(params)

    req = request.Request(url, data=url_params.encode())

    try:
        response = request.urlopen(req)
    except Exception as e:
        print(e, sys.stderr)
        return None

    try:
        response_str = response.read().decode()
    except Exception as e:
        print(e, sys.stderr)
        return None

    return json.loads(response_str)

License

Dual licensed under either the MIT License or CC0.

You might also like...
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

alpaca-trade-api-python is a python library for the Alpaca Commission Free Trading API.

alpaca-trade-api-python is a python library for the Alpaca Commission Free Trading API. It allows rapid trading algo development easily, with support for both REST and streaming data interfaces

🖥️ Python - P1 Monitor API Asynchronous Python Client

🖥️ Asynchronous Python client for the P1 Monitor

Volt is yet another discord api wrapper for Python. It supports python 3.8 +

Volt Volt is yet another discord api wrapper for Python. It supports python 3.8 + How to install [Currently Not Supported.] pip install volt.py Speed

Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive. Based on python-aria-mirror-bot
Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring files on the Internet to our beloved Google Drive. Based on python-aria-mirror-bot

- [ MAYBE UPDATE & ADD MORE MODULE ] Bagas Mirror&Leech Bot Bagas Mirror&Leech Bot is a multipurpose Telegram Bot written in Python for mirroring file

A python Discord wrapper made in well, python.

discord.why A python Discord wrapper made in well, python. Made to be used by devs who want something a bit more, general. Basic Examples Sending a me

A wrapper for aqquiring Choice Coin directly through a Python Terminal. Leverages the TinyMan Python-SDK.

CHOICE_TinyMan_Wrapper A wrapper that allows users to acquire Choice Coin directly through their Terminal using ALGO and various Algorand Standard Ass

Python On WhatsApp - Run your python codes on whatsapp along with talking to a chatbot
Python On WhatsApp - Run your python codes on whatsapp along with talking to a chatbot

Python On WhatsApp Run your python codes on whatsapp along with talking to a chatbot This is a small python project to run python on whatsapp. and i c

Get-Phone-Number-Details-using-Python - To get the details of any number, we can use an amazing Python module known as phonenumbers.

Get-Phone-Number-Details-using-Python To get the details of any number, we can use an amazing Python module known as phonenumbers. We can use the amaz

Comments
  • lt.languages() returns HTTPError: HTTP Error 405: METHOD NOT ALLOWED

    lt.languages() returns HTTPError: HTTP Error 405: METHOD NOT ALLOWED

    Tried to call lt.languages() and it returned HTTPError: HTTP Error 405: METHOD NOT ALLOWED Needed to add req.get_method = lambda: 'GET' into languages() to make it work.

    bug 
    opened by romran 11
  • Added type annotations

    Added type annotations

    I added type annotations to the code, which are compatible with 3.8 and newer. (unsure about older versions).

    I would suggest making a dataclass or similar structures for return values.

    Solves #6

    opened by ChinoCodeDemon 1
  • Improve setup.py

    Improve setup.py

    • fixed long_description variable defined but never used.
    • url should point to the project repository or to the official page.
    • Add the minimum supported version of Python, calculated with Vermin
    • Add more options
    opened by Jalkhov 1
Owner
Argos Open Tech
Argos Open Tech
Python bindings for ArrayFire: A general purpose GPU library.

ArrayFire Python Bindings ArrayFire is a high performance library for parallel computing with an easy-to-use API. It enables users to write scientific

ArrayFire 402 Dec 20, 2022
Python bindings for BigML.io

BigML Python Bindings BigML makes machine learning easy by taking care of the details required to add data-driven decisions and predictive power to yo

BigML Inc, Machine Learning made easy 271 Dec 27, 2022
Disqus API bindings for Python

disqus-python Let's start with installing the API: pip install disqus-python Use the API by instantiating it, and then calling the method through dott

DISQUS 163 Oct 14, 2022
Python bindings to the Syncthing REST interface.

python-syncthing Python bindings to the Syncthing REST interface. Python API Documentation Syncthing Syncthing REST Documentation Syncthing Forums $ p

Blake VandeMerwe 64 Aug 13, 2022
pylunasvg - Python bindings for lunasvg

pylunasvg - Python bindings for lunasvg Pylunasvg is a simple wrapper around lunasvg that uses pybind11 to create python bindings. All public API of t

Eren 6 Jan 5, 2023
Python bindings for swm-core client REST API

Python bindings for swm-core client REST API Description Sky Port is an universal bus between user software and compute resources. It can also be cons

Sky Workflows 1 Jan 1, 2022
Official Python client for the MonkeyLearn API. Build and consume machine learning models for language processing from your Python apps.

MonkeyLearn API for Python Official Python client for the MonkeyLearn API. Build and run machine learning models for language processing from your Pyt

MonkeyLearn 157 Nov 22, 2022
PRAW, an acronym for "Python Reddit API Wrapper", is a python package that allows for simple access to Reddit's API.

PRAW: The Python Reddit API Wrapper PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's AP

Python Reddit API Wrapper Development 3k Dec 29, 2022