github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/python/common_README.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 {{#apiInfo}}{{#apis}}{{#-first}}{{#operations}}{{#operation}}{{#-first}} 8 {{> python_doc_auth_partial}} 9 # Defining host is optional and default to {{{basePath}}} 10 configuration.host = "{{{basePath}}}" 11 # Enter a context with an instance of the API client 12 with {{{packageName}}}.ApiClient(configuration) as api_client: 13 # Create an instance of the API class 14 api_instance = {{{packageName}}}.{{{classname}}}(api_client) 15 {{#allParams}} 16 {{paramName}} = {{{example}}} # {{{dataType}}} | {{{description}}}{{#required}} (required){{/required}}{{#defaultValue}} (default to {{{.}}}){{/defaultValue}} 17 {{/allParams}} 18 19 try: 20 {{#summary}} # {{{.}}} 21 {{/summary}} {{#returnType}}api_response = {{/returnType}}api_instance.{{{operationId}}}({{#allParams}}{{#required}}{{paramName}}{{/required}}{{^required}}{{paramName}}={{paramName}}{{/required}}{{^-last}}, {{/-last}}{{/allParams}}){{#returnType}} 22 pprint(api_response){{/returnType}} 23 except ApiException as e: 24 print("Exception when calling {{classname}}->{{operationId}}: %s\n" % e) 25 {{/-first}}{{/operation}}{{/operations}}{{/-first}}{{/apis}}{{/apiInfo}} 26 ``` 27 28 ## Datacenters 29 30 The API is only accessible via HTTPS and the current version is <code>v2</code>, which results in a base URL like: <code>{{{basePath}}}</code> depending on the datacenter. 31 32 ### EU Datacenter 33 ``` 34 {{{basePath}}} 35 ``` 36 37 This is the default datacenter. 38 39 ### US Datacenter 40 ``` 41 https://api.us.app.phrase.com/v2/ 42 ``` 43 44 ### Specifying US Datacenter 45 You can use the US datacenter by setting the following: 46 ``` 47 configuration.host = "https://api.us.app.phrase.com/v2/" 48 ``` 49 50 ## Documentation For Authorization 51 52 {{^authMethods}} 53 All endpoints do not require authorization. 54 {{/authMethods}} 55 {{#authMethods}} 56 {{#last}} Authentication schemes defined for the API:{{/last}} 57 ## {{{name}}} 58 59 {{#isApiKey}} 60 - **Type**: API key 61 - **API key parameter name**: {{{keyParamName}}} 62 - **Location**: {{#isKeyInQuery}}URL query string{{/isKeyInQuery}}{{#isKeyInHeader}}HTTP header{{/isKeyInHeader}} 63 64 ```python 65 import phrase-api 66 67 configuration = phrase-api.Configuration() 68 configuration.api_key['{{{keyParamName}}}'] = 'YOUR_API_KEY' 69 configuration.api_key_prefix['{{{keyParamName}}}'] = 'token' 70 ``` 71 {{/isApiKey}} 72 {{#isBasic}} 73 {{#isBasicBasic}} 74 - **Type**: HTTP basic authentication 75 76 ```python 77 import phrase-api 78 79 configuration = phrase-api.Configuration() 80 configuration.username = 'YOUR_USERNAME' 81 configuration.password = 'YOUR_PASSWORD' 82 ``` 83 {{/isBasicBasic}} 84 {{#isBasicBearer}} 85 - **Type**: Bearer authentication{{#bearerFormat}} ({{{.}}}){{/bearerFormat}} 86 87 ```pytjon 88 import phrase-api 89 90 configuration = phrase-api.Configuration() 91 configuration.access_token = 'YOUR_BEARER_TOKEN' 92 ``` 93 {{/isBasicBearer}} 94 {{/isBasic}} 95 {{#isOAuth}} 96 - **Type**: OAuth 97 - **Flow**: {{{flow}}} 98 - **Authorization URL**: {{{authorizationUrl}}} 99 - **Scopes**: {{^scopes}}N/A{{/scopes}} 100 {{#scopes}} - **{{{scope}}}**: {{{description}}} 101 {{/scopes}} 102 103 ```python 104 import phrase-api 105 106 configuration = phrase-api.Configuration() 107 configuration.access_token = 'YOUR_ACCESS_TOKEN' 108 ``` 109 {{/isOAuth}} 110 111 {{/authMethods}} 112 113 ## Documentation for API Endpoints 114 115 All URIs are relative to *{{basePath}}* 116 117 Class | Method | HTTP request | Description 118 ------------ | ------------- | ------------- | ------------- 119 {{#apiInfo}}{{#apis}}{{#operations}}{{#operation}}*{{classname}}* | [**{{operationId}}**]({{apiDocPath}}{{classname}}.md#{{operationIdLowerCase}}) | **{{httpMethod}}** {{path}} | {{#summary}}{{summary}}{{/summary}} 120 {{/operation}}{{/operations}}{{/apis}}{{/apiInfo}} 121 122 ## Documentation For Models 123 124 {{#models}}{{#model}} - [{{{classname}}}]({{modelDocPath}}{{{classname}}}.md) 125 {{/model}}{{/models}} 126 127 ## Author 128 129 {{#apiInfo}}{{#apis}}{{#-last}}{{infoEmail}} 130 {{/-last}}{{/apis}}{{/apiInfo}} 131 132 ## Get help / support 133 134 Please contact [support@phrase.com](mailto:support@phrase.com?subject=[GitHub]%20phrase-python) and we can take more direct action toward finding a solution.