Skip to content

Commit e1dfc46

Browse files
Readme: reformat
1 parent 0bb48f1 commit e1dfc46

File tree

1 file changed

+83
-43
lines changed

1 file changed

+83
-43
lines changed

README.md

Lines changed: 83 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,37 +4,46 @@
44
[![Supported Python versions](https://img.shields.io/pypi/pyversions/deepl.svg)](https://pypi.org/project/deepl/)
55
[![License: MIT](https://img.shields.io/badge/license-MIT-blueviolet.svg)](https://github.com/DeepLcom/deepl-python/blob/main/LICENSE)
66

7-
The [DeepL API][api-docs] is a language
8-
translation API that allows other computer programs to send texts and documents to DeepL's servers and receive
9-
high-quality translations. This opens a whole universe of opportunities for developers: any translation product you can
10-
imagine can now be built on top of DeepL's best-in-class translation technology.
7+
The [DeepL API][api-docs] is a language translation API that allows other
8+
computer programs to send texts and documents to DeepL's servers and receive
9+
high-quality translations. This opens a whole universe of opportunities for
10+
developers: any translation product you can imagine can now be built on top of
11+
DeepL's best-in-class translation technology.
1112

12-
The DeepL Python library offers a convenient way for applications written in Python to interact with the DeepL API. We
13-
intend to support all API functions with the library, though support for new features may be added to the library after
14-
they’re added to the API.
13+
The DeepL Python library offers a convenient way for applications written in
14+
Python to interact with the DeepL API. We intend to support all API functions
15+
with the library, though support for new features may be added to the library
16+
after they’re added to the API.
1517

18+
## Getting an authentication key
1619

17-
## Getting an authentication key
20+
To use the DeepL Python Library, you'll need an API authentication key. To get a
21+
key, [please create an account here][create-account]. You can translate up to
22+
500,000 characters/month for free.
1823

19-
To use the DeepL Python Library, you'll need an API authentication key. To get a key, [please create an account here][create-account]. You can translate up to 500,000 characters/month for free.
20-
21-
After you have created an account, you can find your API authentication key on your [DeepL Pro Account][pro-account].
24+
After you have created an account, you can find your API authentication key on
25+
your [DeepL Pro Account][pro-account].
2226

2327
## Installation
28+
2429
The library can be installed from [PyPI][pypi-project] using pip:
30+
2531
```shell
2632
pip install --upgrade deepl
2733
```
2834

2935
If you need to modify this source code, install the dependencies using poetry:
36+
3037
```shell
3138
poetry install
3239
```
3340

3441
### Requirements
35-
The library is tested with Python versions 3.6 to 3.10.
3642

37-
The `requests` module is used to perform HTTP requests; the minimum is version 2.0.
43+
The library is tested with Python versions 3.6 to 3.10.
44+
45+
The `requests` module is used to perform HTTP requests; the minimum is version
46+
2.0.
3847

3948
## Usage
4049

@@ -55,7 +64,8 @@ print(result) # "Bonjour, le monde !"
5564
# Note: printing or converting the result to a string uses the output text
5665

5766
# Translate multiple texts into British English
58-
result = translator.translate_text(["お元気ですか?", "¿Cómo estás?"], target_lang="EN-GB")
67+
result = translator.translate_text(["お元気ですか?", "¿Cómo estás?"],
68+
target_lang="EN-GB")
5969
print(result[0].text) # "How are you?"
6070
print(result[0].detected_source_lang) # "JA"
6171
print(result[1].text) # "How are you?"
@@ -77,7 +87,8 @@ except deepl.DocumentTranslationException as error:
7787
# DeepL support.
7888
doc_id = error.document_handle.id
7989
doc_key = error.document_handle.key
80-
print(f"Error after uploading document ${error}, id: ${doc_id} key: ${doc_key}")
90+
print(
91+
f"Error after uploading document ${error}, id: ${doc_id} key: ${doc_key}")
8192
except deepl.DeepLException as error:
8293
# Errors during upload raise a DeepLException
8394
print(error)
@@ -100,13 +111,13 @@ without_glossary = translator.translate_text(
100111
)
101112
print(without_glossary) # "Der Künstler wurde mit einem Preis ausgezeichnet."
102113

103-
104114
# Check account usage
105115
usage = translator.get_usage()
106116
if usage.character.limit_exceeded:
107117
print("Character limit exceeded.")
108118
else:
109-
print(f"Character usage: {usage.character.count} of {usage.character.limit}")
119+
print(
120+
f"Character usage: {usage.character.count} of {usage.character.limit}")
110121

111122
# Source and target languages
112123
print("Source languages:")
@@ -122,43 +133,59 @@ for language in translator.get_target_languages():
122133
```
123134

124135
### Exceptions
136+
125137
All module functions may raise `deepl.DeepLException` or one of its subclasses.
126-
If invalid arguments are provided, they may raise the standard exceptions `ValueError` and `TypeError`.
138+
If invalid arguments are provided, they may raise the standard exceptions
139+
`ValueError` and `TypeError`.
127140

128141
### Configuration
129142

130143
#### Logging
131-
Logging can be enabled to see the HTTP-requests sent and responses received by the library. Enable and control logging
132-
using Python's logging module, for example:
144+
145+
Logging can be enabled to see the HTTP-requests sent and responses received by
146+
the library. Enable and control logging using Python's logging module, for
147+
example:
148+
133149
```python
134150
import logging
151+
135152
logging.basicConfig()
136153
logging.getLogger('deepl').setLevel(logging.DEBUG)
137154
```
138155

139156
#### Proxy configuration
140-
You can configure a proxy by specifying the `proxy` argument when creating a `deepl.Translator`:
157+
158+
You can configure a proxy by specifying the `proxy` argument when creating a
159+
`deepl.Translator`:
160+
141161
```python
142162
proxy = "http://user:[email protected]:3128"
143163
translator = deepl.Translator(..., proxy=proxy)
144164
```
145165

146166
The proxy argument is passed to the underlying `requests` session,
147-
[see the documentation here][requests-proxy-docs]; a dictionary of schemes
148-
to proxy URLs is also accepted.
167+
[see the documentation here][requests-proxy-docs]; a dictionary of schemes to
168+
proxy URLs is also accepted.
149169

150170
## Command Line Interface
151-
The library can be run on the command line supporting all API functions. Use the `--help` option for
152-
usage information:
171+
172+
The library can be run on the command line supporting all API functions. Use the
173+
`--help` option for usage information:
174+
153175
```shell
154176
python3 -m deepl --help
155177
```
156-
The CLI requires your DeepL authentication key specified either as the `DEEPL_AUTH_KEY` environment variable, or using
157-
the `--auth-key` option, for example:
178+
179+
The CLI requires your DeepL authentication key specified either as the
180+
`DEEPL_AUTH_KEY` environment variable, or using the `--auth-key` option, for
181+
example:
182+
158183
```shell
159184
python3 -m deepl --auth-key=YOUR_AUTH_KEY usage
160185
```
161-
Note that the `--auth-key` argument must appear *before* the command argument. The recognized commands are:
186+
187+
Note that the `--auth-key` argument must appear *before* the command argument.
188+
The recognized commands are:
162189

163190
| Command | Description |
164191
| :-------- | :----------------------------------------------------- |
@@ -169,38 +196,51 @@ Note that the `--auth-key` argument must appear *before* the command argument. T
169196
| glossary | create, list, and remove glossaries |
170197

171198
For example, to translate text:
199+
172200
```shell
173201
python3 -m deepl --auth-key=YOUR_AUTH_KEY text --to=DE "Text to be translated."
174202
```
175-
Wrap text arguments in quotes to prevent the shell from splitting sentences into words.
203+
204+
Wrap text arguments in quotes to prevent the shell from splitting sentences into
205+
words.
176206

177207
## Issues
178208

179-
If you experience problems using the library, or would like to request a new feature, please open an
180-
[issue][issues].
209+
If you experience problems using the library, or would like to request a new
210+
feature, please open an [issue][issues].
181211

182212
## Development
183213

184-
We are currently unable to accept Pull Requests. If you would like to suggest changes, please open an issue instead.
214+
We are currently unable to accept Pull Requests. If you would like to suggest
215+
changes, please open an issue instead.
185216

186-
### Tests
217+
### Tests
187218

188-
Execute the tests using `pytest`. The tests communicate with the DeepL API using the auth key defined by the
189-
`DEEPL_AUTH_KEY` environment variable.
219+
Execute the tests using `pytest`. The tests communicate with the DeepL API using
220+
the auth key defined by the `DEEPL_AUTH_KEY` environment variable.
190221

191-
Be aware that the tests make DeepL API requests that contribute toward your API usage.
222+
Be aware that the tests make DeepL API requests that contribute toward your API
223+
usage.
192224

193-
The test suite may instead be configured to communicate with the mock-server provided by
194-
[deepl-mock][deepl-mock]. Although most test cases work for either, some test cases work
195-
only with the DeepL API or the mock-server and will be otherwise skipped. The test cases that require the mock-server
196-
trigger server errors and test the client error-handling. To execute the tests using deepl-mock, run it in another
197-
terminal while executing the tests. Execute the tests using `pytest` with the `DEEPL_MOCK_SERVER_PORT` and
198-
`DEEPL_SERVER_URL` environment variables defined referring to the mock-server.
225+
The test suite may instead be configured to communicate with the mock-server
226+
provided by [deepl-mock][deepl-mock]. Although most test cases work for either,
227+
some test cases work only with the DeepL API or the mock-server and will be
228+
otherwise skipped. The test cases that require the mock-server trigger server
229+
errors and test the client error-handling. To execute the tests using
230+
deepl-mock, run it in another terminal while executing the tests. Execute the
231+
tests using `pytest` with the `DEEPL_MOCK_SERVER_PORT` and `DEEPL_SERVER_URL`
232+
environment variables defined referring to the mock-server.
199233

200234
[api-docs]: https://www.deepl.com/docs-api?utm_source=github&utm_medium=github-python-readme
235+
201236
[create-account]: https://www.deepl.com/pro?utm_source=github&utm_medium=github-python-readme#developer
237+
202238
[deepl-mock]: https://www.github.com/DeepLcom/deepl-mock
239+
203240
[issues]: https://www.github.com/DeepLcom/deepl-python/issues
241+
204242
[pypi-project]: https://pypi.org/project/deepl/
243+
205244
[pro-account]: https://www.deepl.com/pro-account/?utm_source=github&utm_medium=github-python-readme
206-
[requests-proxy-docs]: https://docs.python-requests.org/en/latest/user/advanced/#proxies
245+
246+
[requests-proxy-docs]: https://docs.python-requests.org/en/latest/user/advanced/#proxies

0 commit comments

Comments
 (0)