DeepLcom / deepl-python

Official Python library for the DeepL language translation API.
https://www.deepl.com
MIT License
1.11k stars 80 forks source link

list_glossaries #26

Closed SamueLacombe closed 2 years ago

SamueLacombe commented 2 years ago

Hello,

I'm not able to use the "list_glossaries" function.

It's working when I do the call, but I just can't seem to do anything with the object returned?

print(dir(deeplClient)) ['_DEEPL_SERVER_URL', '_DEEPL_SERVER_URL_FREE', '_HTTP_STATUS_QUOTA_EXCEEDED', '__class__', '__del__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api_call', '_check_language_and_formality', '_check_valid_languages', '_client', '_raise_for_status', '_server_url', 'close', 'create_glossary', 'delete_glossary', 'get_glossary', 'get_glossary_entries', 'get_glossary_languages', 'get_source_languages', 'get_target_languages', 'get_usage', 'headers', 'list_glossaries', 'server_url', 'translate_document', 'translate_document_download', 'translate_document_from_filepath', 'translate_document_get_status', 'translate_document_upload', 'translate_text', 'translate_text_with_glossary']

glossaries = deeplClient.list_glossaries print(dir(glossaries)) ['__call__', '__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__func__', '__ge__', '__get__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__self__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

How am I suppose to access the list of glossaries? it's not an iterable object and I don't see any methods usefull to get info out of the object.

The glossary creation seem to work great, but I want to create them just once and then retrieve them through the list.

Best regards, Samuel

daniel-jones-deepl commented 2 years ago

Hello Samuel, thank you for raising this issue, you've brought to my attention that the Readme lacks an example for this function.

list_glossaries is a function, when called it returns a list of GlossaryInfo objects (the same as is returned by the create_glossary and get_glossary functions).

Here is an example:

glossaries = deeplClient.list_glossaries()  # using deeplClient as in your code
for glossary in glossaries:
    print(f"{glossary.name} ({glossary.glossary_id}), "
          f"{glossary.source_lang}->{glossary.target_lang}, {glossary.entry_count} entries")
SamueLacombe commented 2 years ago

Thanks you! It's working great!