Skip to content

Commit 755518a

Browse files
authored
Merge branch 'develop' into master
2 parents 1b3dda1 + 50c05db commit 755518a

File tree

2 files changed

+85
-59
lines changed

2 files changed

+85
-59
lines changed

README.md

Lines changed: 81 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,33 @@
77

88
Python client library to quickly get started with the various [Watson APIs][wdc] services.
99

10+
<details>
11+
<summary>Table of Contents</summary>
12+
13+
* [Before you begin](#before-you-begin)
14+
* [Installation](#installation)
15+
* [Examples](#examples)
16+
* [Running in IBM Cloud](#running-in-ibm-cloud)
17+
* [Authentication](#authentication)
18+
* [Getting credentials](#getting-credentials)
19+
* [IAM](#iam)
20+
* [Username and password](#username-and-password)
21+
* [API key](#api-key)
22+
* [Python version](#python-version)
23+
* [Changes for v1.0](#changes-for-v10)
24+
* [Migration](#migration)
25+
* [Configuring the http client](#configuring-the-http-client-supported-from-v110)
26+
* [Sending request headers](#sending-request-headers)
27+
* [Parsing HTTP response info](#parsing-http-response-info)
28+
* [Dependencies](#dependencies)
29+
* [License](#license)
30+
* [Contributing](#contributing)
31+
32+
</details>
33+
34+
## Before you begin
35+
* You need an [IBM Cloud][ibm-cloud-onboarding] account.
36+
1037
## Installation
1138

1239
To install, use `pip` or `easy_install`:
@@ -41,70 +68,38 @@ For more details see [#405](https://github.com/watson-developer-cloud/python-sdk
4168

4269
## Examples
4370

44-
The [examples][examples] folder has basic and advanced examples.
45-
46-
## Getting the Service Credentials
47-
48-
Service credentials are required to access the APIs.
49-
50-
If you run your app in IBM Cloud, you don't need to specify the username and password or IAM API key (`apikey`). In that case, the SDK uses the `VCAP_SERVICES` environment variable to load the credentials.
51-
To run locally or outside of IBM Cloud you need the `username` and `password` credentials or IAM API key (`apikey`) for each service. (Service credentials are different from your IBM Cloud account email and password.)
71+
The [examples][examples] folder has basic and advanced examples. The examples within each service assume that you already have [service credentials](#getting-credentials).
5272

53-
To create an instance of the service:
73+
## Running in IBM Cloud
5474

55-
1. Log in to [IBM Cloud][ibm_cloud].
56-
1. Create an instance of the service:
57-
1. Click on **Create Resource**.
58-
1. In the IBM Cloud **Catalog**, select the Watson service you want to use. For example, select the Conversation service.
59-
1. Type a unique name for the service instance in the **Service name** field. For example, type `my-service-name`. Leave the default values for the other options.
60-
1. Click **Create**.
75+
If you run your app in IBM Cloud, the SDK gets credentials from the [`VCAP_SERVICES`][vcap_services] environment variable.
6176

6277
## Authentication
63-
To get your service credentials:
6478

65-
Copy your credentials from the **Manage** page. To find the Service details page for an existing service, navigate to your [IBM Cloud][ibm_cloud] dashboard and click the service name.
79+
Watson services are migrating to token-based Identity and Access Management (IAM) authentication.
6680

67-
1. On the **Manage** page, you will see a **Credentials** pane
68-
1. Depending on the service you will see use either:
69-
* 2.a: `username`, `password`, and `url`(optional) or `apikey`(for Visual Recognition).
70-
* 2.b: `apikey` which is the value for parameter `iam_api_key` when initializing the constructor.
71-
72-
### Username and Password
73-
```python
74-
from watson_developer_cloud import DiscoveryV1
75-
# In the constructor
76-
discovery = DiscoveryV1(version='2017-10-16', username='<username>', password='<password>')
77-
```
78-
79-
```python
80-
# After instantiation
81-
discovery = DiscoveryV1(version='2017-10-16')
82-
discovery.set_username_and_password('<username>', '<password>')
83-
```
81+
- With some service instances, you authenticate to the API by using **[IAM](#iam)**.
82+
- In other instances, you authenticate by providing the **[username and password](#username-and-password)** for the service instance.
83+
- Visual Recognition uses a form of [API key](#api-key) only with instances created before May 23, 2018. Newer instances of Visual Recognition use IAM.
8484

85-
### API Key
86-
*Important: Instantiation with API key works only with Visual Recognition service instances created before May 23, 2018. Visual Recognition instances created after May 22 use IAM.*
85+
### Getting credentials
86+
To find out which authentication to use, view the service credentials. You find the service credentials for authentication the same way for all Watson services:
8787

88-
```python
89-
from watson_developer_cloud import VisualRecognitionV3
90-
# In the constructor
91-
visual_recognition = VisualRecognitionV3(version='2018-05-22', api_key='<api_key>')
92-
```
88+
1. Go to the IBM Cloud **[Dashboard][watson-dashboard]** page.
89+
1. Either click an existing Watson service instance or click **Create**.
90+
1. Click **Show** to view your service credentials.
91+
1. Copy the `url` and either `apikey` or `username` and `password`.
9392

94-
```python
95-
# After instantiation
96-
visual_recognition = VisualRecognitionV3(version='2018-05-22')
97-
visual_recognition.set_api_key('<api_key>')
98-
```
93+
### IAM
9994

100-
### Using IAM
95+
IBM Cloud is migrating to token-based Identity and Access Management (IAM) authentication. IAM authentication uses a service API key to get an access token that is passed with the call. Access tokens are valid for approximately one hour and must be regenerated.
10196

102-
When authenticating with IAM, you have the option of passing in:
97+
You supply either an IAM service **API key** or an **access token**:
10398

104-
* the IAM API key and, optionally, the IAM service URL
105-
* an IAM access token
99+
- Use the API key to have the SDK manage the lifecycle of the access token. The SDK requests an access token, ensures that the access token is valid, and refreshes it if necessary.
100+
- Use the access token if you want to manage the lifecycle yourself. For details, see [Authenticating with IAM tokens](https://console.bluemix.net/docs/services/watson/getting-started-iam.html).
106101

107-
**Be aware that passing in an access token means that you're assuming responsibility for maintaining that token's lifecycle.** If you instead pass in an IAM API key, the SDK will manage it for you.
102+
#### Supplying the IAM API key
108103

109104
```python
110105
# In the constructor, letting the SDK manage the IAM token
@@ -119,6 +114,7 @@ discovery = DiscoveryV1(version='2017-10-16')
119114
discovery.set_iam_api_key('<iam_api_key>')
120115
```
121116

117+
#### Supplying the access token
122118
```python
123119
# in the constructor, assuming control of managing IAM token
124120
discovery = DiscoveryV1(version='2017-10-16',
@@ -131,9 +127,36 @@ discovery = DiscoveryV1(version='2017-10-16')
131127
discovery.set_iam_access_token('<access_token>')
132128
```
133129

134-
If at any time you would like to let the SDK take over managing your IAM token, simply override your stored IAM credentials with an IAM API key by calling the `set_token_manager()` method again.
130+
### Username and password
131+
```python
132+
from watson_developer_cloud import DiscoveryV1
133+
# In the constructor
134+
discovery = DiscoveryV1(version='2017-10-16', username='<username>', password='<password>')
135+
```
136+
137+
```python
138+
# After instantiation
139+
discovery = DiscoveryV1(version='2017-10-16')
140+
discovery.set_username_and_password('<username>', '<password>')
141+
```
142+
143+
### API key
144+
145+
**Important**: This type of authentication works only with Visual Recognition instances created before May 23, 2018. Newer instances of Visual Recognition use [IAM](#iam).
146+
147+
```python
148+
from watson_developer_cloud import VisualRecognitionV3
149+
# In the constructor
150+
visual_recognition = VisualRecognitionV3(version='2018-05-22', api_key='<api_key>')
151+
```
152+
153+
```python
154+
# After instantiation
155+
visual_recognition = VisualRecognitionV3(version='2018-05-22')
156+
visual_recognition.set_api_key('<api_key>')
157+
```
135158

136-
## Python Version
159+
## Python version
137160

138161
Tested on Python 2.7, 3.4, 3.5, and 3.6.
139162

@@ -160,7 +183,7 @@ response = assistant.message(workspace_id=workspace_id, input={
160183
print(json.dumps(response, indent=2))
161184
```
162185

163-
## Sending Request Headers
186+
## Sending request headers
164187
Custom headers can be passed in any request in the form of a `dict` as:
165188
```python
166189
headers = {
@@ -180,7 +203,7 @@ assistant = AssistantV1(
180203
response = assistant.list_workspaces(headers={'Custom-Header': 'custom_value'})
181204
```
182205

183-
## Parsing HTTP Response Info
206+
## Parsing HTTP response info
184207
If you would like access to some HTTP response information along with the response model, you can set the `set_detailed_response()` to `True`
185208
```python
186209
from watson_developer_cloud import AssistantV1
@@ -225,8 +248,11 @@ This library is licensed under the [Apache 2.0 license][license].
225248

226249
[wdc]: http://www.ibm.com/watson/developercloud/
227250
[ibm_cloud]: https://console.bluemix.net
251+
[watson-dashboard]: https://console.bluemix.net/dashboard/apps?category=watson
228252
[responses]: https://github.com/getsentry/responses
229253
[requests]: http://docs.python-requests.org/en/latest/
230254
[examples]: https://github.com/watson-developer-cloud/python-sdk/tree/master/examples
231255
[CONTRIBUTING]: https://github.com/watson-developer-cloud/python-sdk/blob/master/CONTRIBUTING.md
232256
[license]: http://www.apache.org/licenses/LICENSE-2.0
257+
[vcap_services]: https://console.bluemix.net/docs/services/watson/getting-started-variables.html
258+
[ibm-cloud-onboarding]: http://console.bluemix.net/registration?target=/developer/watson&cm_sp=WatsonPlatform-WatsonServices-_-OnPageNavLink-IBMWatson_SDKs-_-Python

watson_developer_cloud/visual_recognition_v3.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ def create_classifier(self,
235235
"""
236236
Create a classifier.
237237
:param str name: The name of the new classifier. Encode special characters in UTF-8.
238-
:param file <NAME>_positive_examples: A compressed (.zip) file of images that depict the visual subject for a class within the new classifier. Must contain a minimum of 10 images. The swagger limits you to training only one class. To train more classes, use the API functionality.
239-
:param file negative_examples: A compressed (.zip) file of images that do not depict the visual subject of any of the classes of the new classifier. Must contain a minimum of 10 images.
238+
:param file <NAME>_positive_examples: A compressed (.zip) file of images that depict the visual subject for a class within the new classifier. Include at least 10 images in .jpg or .png format. The minimum recommended image resolution is 32X32 pixels. The maximum number of images is 10,000 images or 100 MB per .zip file. Encode special characters in the file name in UTF-8.
239+
:param file negative_examples: A compressed (.zip) file of images that do not depict the visual subject of any of the classes of the new classifier. Must contain a minimum of 10 images. Encode special characters in the file name in UTF-8.
240240
:param dict headers: A `dict` containing the request headers
241241
:return: A `dict` containing the `Classifier` response.
242242
:rtype: dict
@@ -339,8 +339,8 @@ def update_classifier(self,
339339
"""
340340
Update a classifier.
341341
:param str classifier_id: The ID of the classifier.
342-
:param file <NAME>_positive_examples: A compressed (.zip) file of images that depict the visual subject for a class within the classifier. Must contain a minimum of 10 images.
343-
:param file negative_examples: A compressed (.zip) file of images that do not depict the visual subject of any of the classes of the new classifier. Must contain a minimum of 10 images.
342+
:param file <NAME>_positive_examples: A .zip file of images that depict the visual subject of a class in the classifier. The positive examples create or update classes in the classifier. You can include more than one positive example file in a call. Include at least 10 images in .jpg or .png format. The minimum recommended image resolution is 32X32 pixels. The maximum number of images is 10,000 images or 100 MB per .zip file. Encode special characters in the file name in UTF-8.
343+
:param file negative_examples: A .zip file of images that do not depict the visual subject of any of the classes of the new classifier. Must contain a minimum of 10 images. Encode special characters in the file name in UTF-8.
344344
:param dict headers: A `dict` containing the request headers
345345
:return: A `dict` containing the `Classifier` response.
346346
:rtype: dict

0 commit comments

Comments
 (0)