deepl-fastapi-pw


Namedeepl-fastapi-pw JSON
Version 0.1.0a6 PyPI version JSON
download
home_pagehttps://github.com/ffreemt/deepl-fastapi-playwright
Summarydeepl via fastapi using playwright
upload_time2023-08-13 11:35:53
maintainer
docs_urlNone
authorfreemt
requires_python>=3.8.3,<4.0.0
licenseMIT
keywords
VCS
bugtrack_url
requirements appdirs atomicwrites attrs click colorama cssselect
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # deepl-fastapi-pw
<!--- repo-name  pypi-name  mod_name func_name --->
[![tests](https://github.com/ffreemt/deepl-fastapi-playwright/actions/workflows/routine-tests.yml/badge.svg)](https://github.com/ffreemt/deepl-fastapi-playwright/actions)
[![python](https://img.shields.io/static/v1?label=python+&message=3.8%2B&color=blue)](https://img.shields.io/static/v1?label=python+&message=3.8%2B&color=blue)[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)[![PyPI version](https://badge.fury.io/py/deepl-fastapi-pw.svg)](https://badge.fury.io/py/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.,
    ```bash
    # Linux and friends
    python3.8 -m venv .venv
    source .venv/bin/activate

    # Windows
    # py -3.8 -m venv .venv
    # .venv\Scripts\activate
    ```

```bash
pip install deepl-fastapi-pw
```
or (if your use poetry)
```bash
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](https://github.com/ffreemt/deepl-fastapi-playwrigh.git)
    ```bash
    git clone https://github.com/ffreemt/deepl-fastapi-playwright.git
    ```
    and `cd deepl-fastapi-playwright`
*   `pip install -r requirements.txt
    * or ``poetry install``

## Usage

*   Start the server

```
python  -m deepl_fastapi_pw
```

Or use uvicorn directly (note the `deepl_server` module, not `run_uvicorn`)
```bash
uvicorn deepl_fastapi_pw.deepl_server_async:app
```

or
```bash
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](http://127.0.0.1:8001/text/?q=test&to_lang=zh)

Or in command line:
```bash
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)
```python
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](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 1500 characters will be trimmed to 1500. This is what the `deepl.com` webpage can handle (used to be 5000 characters).
* 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](http://127.0.0.1:8001/docs)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ffreemt/deepl-fastapi-playwright",
    "name": "deepl-fastapi-pw",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.3,<4.0.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "freemt",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/1a/d9/858e3ccc0d0d61e10d643e62bfea4bcc31565fd9ada9fc47d2708ce07ef5/deepl_fastapi_pw-0.1.0a6.tar.gz",
    "platform": null,
    "description": "# deepl-fastapi-pw\n<!--- repo-name  pypi-name  mod_name func_name --->\n[![tests](https://github.com/ffreemt/deepl-fastapi-playwright/actions/workflows/routine-tests.yml/badge.svg)](https://github.com/ffreemt/deepl-fastapi-playwright/actions)\n[![python](https://img.shields.io/static/v1?label=python+&message=3.8%2B&color=blue)](https://img.shields.io/static/v1?label=python+&message=3.8%2B&color=blue)[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)[![PyPI version](https://badge.fury.io/py/deepl-fastapi-pw.svg)](https://badge.fury.io/py/deepl-fastapi-pw)\n\nYour own deepl server via fastapi and playwright, cross-platform (Windows/Linux/MacOs) with API for OmegaT\n\n## Installation\n*   Create a virual environment: optional but recommended\n    e.g.,\n    ```bash\n    # Linux and friends\n    python3.8 -m venv .venv\n    source .venv/bin/activate\n\n    # Windows\n    # py -3.8 -m venv .venv\n    # .venv\\Scripts\\activate\n    ```\n\n```bash\npip install deepl-fastapi-pw\n```\nor (if your use poetry)\n```bash\npoetry add deepl-fastapi-pw\n```\nor\n```\n pip install git+https://github.com/ffreemt/deepl-fastapi-playwright.git\n```\nor\n*   Clone the repo [https://github.com/ffreemt/deepl-fastapi-playwright.git](https://github.com/ffreemt/deepl-fastapi-playwrigh.git)\n    ```bash\n    git clone https://github.com/ffreemt/deepl-fastapi-playwright.git\n    ```\n    and `cd deepl-fastapi-playwright`\n*   `pip install -r requirements.txt\n    * or ``poetry install``\n\n## Usage\n\n*   Start the server\n\n```\npython  -m deepl_fastapi_pw\n```\n\nOr use uvicorn directly (note the `deepl_server` module, not `run_uvicorn`)\n```bash\nuvicorn deepl_fastapi_pw.deepl_server_async:app\n```\n\nor\n```bash\npython -m deepl_fastapi_pw.deepl_server_async\n```\n\nor run the server on the external net, for example at port 9888\n```\nuvicorn deepl_fastapi_pw.deepl_server:app --reload --host 0.0.0.0 --port 9888\n```\n\n### Explore and consume\n\nPoint your browser to [http://127.0.0.1:8001/text/?q=test&to_lang=zh](http://127.0.0.1:8001/text/?q=test&to_lang=zh)\n\nOr in command line:\n```bash\npython -c \"import httpx; print(httpx.get('http://127.0.0.1:8001/text/?to_lang=zh&q=test 1\\ntest 2').json())\"\n# output: {'q': 'test 1\\ntest 2', 'from_lang': None, 'to_lang': 'zh', 'trtext': '\u6d4b\u8bd5 1\\n\u6d4b\u8bd5 2', 'translation': '\u6d4b\u8bd5 1\\n\u6d4b\u8bd5 2'}\n```\n\nOr in python code (`pip install requests` first)\n```python\nimport requests\n\n# get\nurl = \"http://127.0.0.1:8001/text/?q=test me&to_lang=zh\"\nprint(requests.get(url).json())\n# {'q': 'test me', 'from_lang': None, 'to_lang':\n# 'zh', 'trtext': '\u8003\u6211', 'translation': '\u8003\u6211'}\n```\n\n`'translation'` is there for `OmegaT` plugin. Refer to the `OmegaT Fake MT plugin setup` part\nin [https://github.com/ffreemt/deepl-fastapi](https://github.com/ffreemt/deepl-fastapi)\n```\n# post\ntext = \"test me \\n and him\"\ndata = {\"text\": text, \"to_lang\": \"zh\"}\nresp = requests.post(\"http://127.0.0.1:8001/text\", json=data)\nprint(resp.json())\n# {'q': {'text': 'test me \\n and him', 'from_lang': None,\n# 'to_lang': 'zh', 'description': None}, 'result': '\u8003\u9a8c\u6211 \\n  \u6211\u548c\u4ed6'}\n```\n\n### NB\n* Text longer than 1500 characters will be trimmed to 1500. This is what the `deepl.com` webpage can handle (used to be 5000 characters).\n* 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`.\n\n## Interactive Docs (Swagger UI)\n\n [http://127.0.0.1:8001/docs](http://127.0.0.1:8001/docs)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "deepl via fastapi using playwright",
    "version": "0.1.0a6",
    "project_urls": {
        "Homepage": "https://github.com/ffreemt/deepl-fastapi-playwright",
        "Repository": "https://github.com/ffreemt/deepl-fastapi-playwright"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c699089537cc41eb82033fa20c66d33fa07fe622145dff7cd2ca1620b9864401",
                "md5": "40c2b261c4679bd9b9432b45b79bea93",
                "sha256": "c24b0b83cd61631bc3241480208cec41553f690aeae6d1b90fbe7b70507a6332"
            },
            "downloads": -1,
            "filename": "deepl_fastapi_pw-0.1.0a6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "40c2b261c4679bd9b9432b45b79bea93",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.3,<4.0.0",
            "size": 18049,
            "upload_time": "2023-08-13T11:35:51",
            "upload_time_iso_8601": "2023-08-13T11:35:51.163846Z",
            "url": "https://files.pythonhosted.org/packages/c6/99/089537cc41eb82033fa20c66d33fa07fe622145dff7cd2ca1620b9864401/deepl_fastapi_pw-0.1.0a6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1ad9858e3ccc0d0d61e10d643e62bfea4bcc31565fd9ada9fc47d2708ce07ef5",
                "md5": "f3a3499856f67c5885f663714d1b3797",
                "sha256": "c59314708c3fe0ca520306510eb4859e063fb15a4b539d338ec4100a165e09d5"
            },
            "downloads": -1,
            "filename": "deepl_fastapi_pw-0.1.0a6.tar.gz",
            "has_sig": false,
            "md5_digest": "f3a3499856f67c5885f663714d1b3797",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.3,<4.0.0",
            "size": 11002,
            "upload_time": "2023-08-13T11:35:53",
            "upload_time_iso_8601": "2023-08-13T11:35:53.022460Z",
            "url": "https://files.pythonhosted.org/packages/1a/d9/858e3ccc0d0d61e10d643e62bfea4bcc31565fd9ada9fc47d2708ce07ef5/deepl_fastapi_pw-0.1.0a6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-13 11:35:53",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ffreemt",
    "github_project": "deepl-fastapi-playwright",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "appdirs",
            "specs": [
                [
                    "==",
                    "1.4.4"
                ]
            ]
        },
        {
            "name": "atomicwrites",
            "specs": [
                [
                    "==",
                    "1.4.0"
                ]
            ]
        },
        {
            "name": "attrs",
            "specs": [
                [
                    "==",
                    "19.3.0"
                ]
            ]
        },
        {
            "name": "click",
            "specs": [
                [
                    "==",
                    "7.1.2"
                ]
            ]
        },
        {
            "name": "colorama",
            "specs": [
                [
                    "==",
                    "0.4.4"
                ]
            ]
        },
        {
            "name": "cssselect",
            "specs": [
                [
                    "==",
                    "1.1.0"
                ]
            ]
        }
    ],
    "lcname": "deepl-fastapi-pw"
}
        
Elapsed time: 0.16296s