github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/python/api_doc_example.mustache (about)

     1  ```python
     2  from __future__ import print_function
     3  import time
     4  import {{{packageName}}}
     5  from {{{packageName}}}.rest import ApiException
     6  from pprint import pprint
     7  
     8  {{> python_doc_auth_partial}}
     9  # Enter a context with an instance of the API client
    10  {{#hasAuthMethods}}
    11  with {{{packageName}}}.ApiClient(configuration) as api_client:
    12  {{/hasAuthMethods}}
    13  {{^hasAuthMethods}}
    14  with {{{packageName}}}.ApiClient() as api_client:
    15  {{/hasAuthMethods}}
    16      # Create an instance of the API class
    17      api_instance = {{{packageName}}}.{{{classname}}}(api_client)
    18      {{#allParams}}
    19      {{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}}
    20      {{/allParams}}
    21  
    22      try:
    23      {{#summary}}    # {{{.}}}
    24      {{/summary}}    {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}}
    25          pprint(api_response){{/returnType}}
    26      except ApiException as e:
    27          print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e)
    28  ```