Skip to main content

deepl via fastapi using playwright

Project description

deepl-fastapi-pw

tests pythonCode style: blackLicense: MITPyPI version

Your own deepl server via fastapi and playwright, cross-platform (Windows/Linux/MacOs) with API for OmegaT

Installation

  • Create a virual environment: optional but recommended e.g.,
    # Linux and friends
    python3.8 -m venv .venv
    source .venv/bin/activate
    
    # Windows
    # py -3.8 -m venv .venv
    # .venv\Scripts\activate
    
pip install deepl-fastapi-pw

or (if your use poetry)

poetry add deepl-fastapi-pw

or

 pip install git+https://github.com/ffreemt/deepl-fastapi-playwright.git

or

Usage

  • Start the server
python  -m deepl_fastapi_pw

Or use uvicorn directly (note the deepl_server module, not run_uvicorn)

uvicorn deepl_fastapi_pw.deepl_server_async:app

or

python -m deepl_fastapi_pw.deepl_server_async

or run the server on the external net, for example at port 9888

uvicorn deepl_fastapi_pw.deepl_server:app --reload --host 0.0.0.0 --port 9888

Explore and consume

Point your browser to http://127.0.0.1:8001/text/?q=test&to_lang=zh

Or in command line:

python -c "import httpx; print(httpx.get('http://127.0.0.1:8001/text/?to_lang=zh&q=test 1\ntest 2').json())"
# output: {'q': 'test 1\ntest 2', 'from_lang': None, 'to_lang': 'zh', 'trtext': '测试 1\n测试 2', 'translation': '测试 1\n测试 2'}

Or in python code (pip install requests first)

import requests

# get
url = "http://127.0.0.1:8001/text/?q=test me&to_lang=zh"
print(requests.get(url).json())
# {'q': 'test me', 'from_lang': None, 'to_lang':
# 'zh', 'trtext': '考我', 'translation': '考我'}

'translation' is there for OmegaT plugin. Refer to the OmegaT Fake MT plugin setup part in https://github.com/ffreemt/deepl-fastapi

# post
text = "test me \n and him"
data = {"text": text, "to_lang": "zh"}
resp = requests.post("http://127.0.0.1:8001/text", json=data)
print(resp.json())
# {'q': {'text': 'test me \n and him', 'from_lang': None,
# 'to_lang': 'zh', 'description': None}, 'result': '考验我 \n  我和他'}

NB

  • Text longer than 5000 characters will be trimmed to 5000. This is what the deepl.com webpage can handle.
  • The package deepl-fastapi-pw is in essence a browser from your local IP (although a proxy can be used, refer to get-pwbroser's doc for setting up). Hence if you send too many requests too frequently, your IP may be blocked by deepl.com temporarily, which of course will also disable deepl-fastapi-pw.

Interactive Docs (Swagger UI)

http://127.0.0.1:8001/docs

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_fastapi_pw-0.1.0a5.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deepl_fastapi_pw-0.1.0a5-py3-none-any.whl (17.9 kB view details)

Uploaded Python 3

File details

Details for the file deepl_fastapi_pw-0.1.0a5.tar.gz.

File metadata

  • Download URL: deepl_fastapi_pw-0.1.0a5.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.8.10 Windows/10

File hashes

Hashes for deepl_fastapi_pw-0.1.0a5.tar.gz
Algorithm Hash digest
SHA256 83fa2ef71190e2259801a0463dab239c28841e8e932a3ba90310516689ac71cf
MD5 e9d3679234341f239bcb09257b563929
BLAKE2b-256 8086078da98c2e34236f77f539a010982edb1eb50a12b541073626873afdc82b

See more details on using hashes here.

File details

Details for the file deepl_fastapi_pw-0.1.0a5-py3-none-any.whl.

File metadata

File hashes

Hashes for deepl_fastapi_pw-0.1.0a5-py3-none-any.whl
Algorithm Hash digest
SHA256 b8cbccec654170ff416334141e1f12a6e75c7938c262ff9558980c5805d0ad09
MD5 f3063efc63e6c561caec4f9e42bfeea0
BLAKE2b-256 decf214ce28fc26f54db8ae6dfa156a953109bba9cc7ebd9be24765f0be7215b

See more details on using hashes here.

Supported by

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