MCPcopy Index your code
hub / github.com/DeepL/deepl-python / main

Function main

examples/basic_usage/__main__.py:13–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12
13def main() -> None:
14 auth_key = os.getenv(env_auth_key)
15 server_url = os.getenv(env_server_url)
16 if auth_key is None:
17 raise Exception(
18 f"Please provide authentication key via the {env_auth_key} "
19 "environment variable or --auth_key argument"
20 )
21
22 # Create a Translator object, and call get_usage() to validate connection
23 translator: deepl.Translator = deepl.Translator(
24 auth_key, server_url=server_url
25 )
26 u: deepl.Usage = translator.get_usage()
27 u.any_limit_exceeded
28
29 # Use most translation features of the library
30 _ = translator.translate_text(
31 ["I am an example sentence", "I am another sentence"],
32 source_lang="EN",
33 target_lang="FR",
34 formality=deepl.Formality.DEFAULT,
35 tag_handling=None,
36 )
37 ginfo: deepl.GlossaryInfo = translator.create_glossary(
38 "Test Glossary", "DE", "FR", {"Hallo": "Bonjour"}
39 )
40 with io.BytesIO() as output_file:
41 doc_status: deepl.DocumentStatus = translator.translate_document(
42 "My example document",
43 output_file,
44 source_lang="DE",
45 target_lang="FR",
46 filename="example.txt",
47 glossary=ginfo,
48 )
49 doc_status.done
50 _ = translator.translate_text_with_glossary(
51 ["Ich bin ein Beispielsatz.", "Ich bin noch ein Satz."], glossary=ginfo
52 )
53
54 print("Success")
55
56 # cleanup
57 translator.delete_glossary(ginfo.glossary_id)
58
59
60if __name__ == "__main__":

Callers 1

__main__.pyFile · 0.70

Calls 6

get_usageMethod · 0.95
translate_textMethod · 0.95
create_glossaryMethod · 0.95
translate_documentMethod · 0.95
delete_glossaryMethod · 0.95

Tested by

no test coverage detected