Skip to main content

deepl grpc server and client

Project description

deepl-grpc

[tests]pythonCode style: blackLicense: MITPyPI version

deepl grpc, server and client, cross platform (Windows/MacOS/Linux)

Installation

  • Install grpcio-reflection
    • grpc-reflection cannot be installed using poetry add. Use pip install grpcio-reflection instead.
  • Install the rest as usual
pip install deepl-grpc

or

poetry add deepl-grpc

or clone the repo (git clone https://github.com/ffreemt/deepl-grpc.git) and install from it. For example

git clone https://github.com/ffreemt/deepl-grpc.git
cd deepl-grpc
python3.8 -m venv .venv  # require python3.7+

# for Linux/MacOS, you'd need to install venv and dev if you haven't done so
# sudo apt install python3.8-venv
# sudo apt install python3.8-dev

source .venv/bin/activate  # or in Windows do: .venv\Scripts\activate

pip install grpcio-reflection

pip install -r requirements.txt
# or poetry install --no-dev

python -m deepl_grpc.deepl_client

Usage

python code

from deepl_grpc.deepl_client import DeeplClient
from linetimer import CodeTimer

client = DeeplClient()

text = "test this and that"
with CodeTimer(unit="s"):
    result = client.get_url(message=text)
# Code block took: 1.99860 s

print(result.message)
# 试探 左右逢源 检验 审时度势

to_lang = "de"
with CodeTimer(unit="s"):
  result = client.get_url(message=text, to_lang=to_lang,)
# Code block took: 2.02847 s

print(result.message)
# "Testen Sie dieses und jenes a Testen Sie dies und das a testen Sie dies und das Testen Sie dieses und jenes"

Interactive

  • Start the grpc server
python -m deepl_grpc.deepl_server

The first run in Linux may take a while since chromium (~1G) needs to be downloaded. In Windows, Chrome will be used if it's available.

  • Start the client
python -m deepl_grpc.deepl_client  # to chinese

# python -m deepl_grpc.deepl_client de  # to german

WebUI

Download grpcui and run, for example in Windows

grpcui.exe -plaintext 127.0.0.1:50051

to explore the server in the same manner as Postman for REST.

pyppeteer issues in Linux

You may encounter the following error in Linux:

chromium/linux-588429/chrome-linux/chrome: error while loading shared libraries: libX11-xcb.so.1: cannot open shared object file: No such file or directory

You may wish to try this fix in Ubuntu https://medium.com/@cloverinks/how-to-fix-puppetteer-error-ibx11-xcb-so-1-on-ubuntu-152c336368

sudo apt-get install gconf-service libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxss1 libxtst6 libappindicator1 libnss3 libasound2 libatk1.0-0 libc6 ca-certificates fonts-liberation lsb-release xdg-utils wget

More coming soon

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepl-grpc-0.1.1.tar.gz (7.9 kB view hashes)

Uploaded Source

Built Distribution

deepl_grpc-0.1.1-py3-none-any.whl (8.4 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page