deepl via fastapi using playwright
Project description
deepl-fastapi-pw
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
- Clone the repo https://github.com/ffreemt/deepl-fastapi-playwright.git
git clone https://github.com/ffreemt/deepl-fastapi-playwright.git
andcd deepl-fastapi-playwright
- `pip install -r requirements.txt
- or
poetry install
- 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 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 我和他'}
Interactive Docs (Swagger UI)
Project details
Release history Release notifications | RSS feed
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.0a2.tar.gz
(10.2 kB
view hashes)
Built Distribution
Close
Hashes for deepl_fastapi_pw-0.1.0a2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 83572a4c4a21b761777777993c7cf2b220fe2ec9d724833d562135439cedb6b6 |
|
MD5 | 724e2dd38e8508fca85b925697b635e8 |
|
BLAKE2b-256 | 0665e7a5576dd2acad1bceffe82c492198ccce1ddaf344240e55bc357a311d8e |