Skip to content

Commit b096528

Browse files
authored
Merge pull request #686 from watson-developer-cloud/release-candidate
Release candidate 4.0.0rc1
2 parents 58d9776 + 8c77011 commit b096528

File tree

62 files changed

+12982
-9924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+12982
-9924
lines changed

.env.enc

-16 Bytes
Binary file not shown.

.travis.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
language: python
22
matrix:
33
include:
4-
- python: 2.7
5-
- python: 3.5
6-
- python: 3.6
7-
- python: 3.7
8-
dist: xenial
4+
- python: 3.5
5+
- python: 3.6
6+
- python: 3.7
7+
dist: xenial
98
cache: pip
109
before_install:
1110
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_cebf25e6c525_key
@@ -40,7 +39,7 @@ deploy:
4039
branch: master
4140
- provider: pypi
4241
user: watson-devex
43-
password: $PYPI_PASSWORD
42+
password: "$PYPI_PASSWORD"
4443
repository: https://upload.pypi.org/legacy
4544
skip_cleanup: true
4645
on:

README.md

Lines changed: 108 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ Python client library to quickly get started with the various [Watson APIs][wdc]
1818
* [Getting credentials](#getting-credentials)
1919
* [IAM](#iam)
2020
* [Username and password](#username-and-password)
21+
* [No Authentication](#no-authentication)
2122
* [Python version](#python-version)
2223
* [Changes for v1.0](#changes-for-v10)
2324
* [Changes for v2.0](#changes-for-v20)
2425
* [Changes for v3.0](#changes-for-v30)
26+
* [Changes for v4.0](#changes-for-v40)
2527
* [Migration](#migration)
2628
* [Configuring the http client](#configuring-the-http-client-supported-from-v110)
2729
* [Disable SSL certificate verification](#disable-ssl-certificate-verification)
@@ -103,9 +105,9 @@ On this page, you should be able to see your credentials for accessing your serv
103105

104106
### Supplying credentials
105107

106-
There are two ways to supply the credentials you found above to the SDK for authentication.
108+
There are three ways to supply the credentials you found above to the SDK for authentication.
107109

108-
#### Credential file (easier!)
110+
#### Credential file
109111

110112
With a credential file, you just need to put the file in the right place and the SDK will do the work of parsing and authenticating. You can get this file by clicking the **Download** button for the credentials in the **Manage** tab of your service instance.
111113

@@ -132,72 +134,89 @@ export IBM_CREDENTIALS_FILE="<path>"
132134

133135
where `<path>` is something like `/home/user/Downloads/<file_name>.env`.
134136

137+
#### Environment Variables
138+
Simply set the environment variables using <service name>_<variable name> syntax. For example, using your favourite terminal, you can set environment variables for Assistant service instance:
139+
140+
```bash
141+
export assistant_apikey="<your apikey>"
142+
export assistant_auth_type="iam"
143+
```
144+
145+
The credentials will be loaded from the environment automatically
146+
147+
```python
148+
assistant = AssistantV1(version='2018-08-01')
149+
```
150+
151+
135152
#### Manually
136153
If you'd prefer to set authentication values manually in your code, the SDK supports that as well. The way you'll do this depends on what type of credentials your service instance gives you.
137154

138155
### IAM
139156

140157
IBM Cloud has migrated 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.
141158

142-
You supply either an IAM service **API key** or an **access token**:
159+
You supply either an IAM service **API key** or a **bearer token**:
143160

144161
- 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.
145162
- Use the access token if you want to manage the lifecycle yourself. For details, see [Authenticating with IAM tokens](https://cloud.ibm.com/docs/services/watson?topic=watson-iam).
146163
- Use a server-side to generate access tokens using your IAM API key for untrusted environments like client-side scripts. The generated access tokens will be valid for one hour and can be refreshed.
147164

148-
### Generating access tokens using IAM API key
165+
#### Supplying the API key
149166
```python
150-
# In your API endpoint use this to generate new access tokens
151-
iam_token_manager = IAMTokenManager(iam_apikey='<apikey>')
152-
token = iam_token_manager.get_token()
153-
```
154-
155-
#### Supplying the IAM API key
167+
from ibm_watson import DiscoveryV1
168+
import from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
156169

157-
```python
158-
# In the constructor, letting the SDK manage the IAM token
170+
# In the constructor, letting the SDK manage the token
171+
authenticator = IAMAuthenticator('apikey',
172+
url='<iam_url>') # optional - the default value is https://iam.cloud.ibm.com/identity/token
159173
discovery = DiscoveryV1(version='2018-08-01',
160174
url='<url_as_per_region>',
161-
apikey='<apikey>',
162-
iam_url='<iam_url>') # optional - the default value is https://iam.cloud.ibm.com/identity/token
175+
authenticator=authenticator)
163176
```
164177

178+
#### Generating access tokens using API key
165179
```python
166-
# after instantiation, letting the SDK manage the IAM token
167-
discovery = DiscoveryV1(version='2018-08-01', url='<url_as_per_region>')
168-
discovery.set_apikey('<apikey>')
180+
from ibm_watson import IAMTokenManager
181+
182+
# In your API endpoint use this to generate new access tokens
183+
iam_token_manager = IAMTokenManager(apikey='<apikey>')
184+
token = iam_token_manager.get_token()
169185
```
170186

171-
#### Supplying the access token
187+
##### Supplying the bearer token
172188
```python
173-
# in the constructor, assuming control of managing IAM token
189+
from ibm_watson import DiscoveryV1
190+
from ibm_cloud_sdk_core.authenticators import BearerAuthenticator
191+
192+
# in the constructor, assuming control of managing the token
193+
authenticator = BearerAuthenticator('your bearer token')
174194
discovery = DiscoveryV1(version='2018-08-01',
175195
url='<url_as_per_region>',
176-
iam_access_token='<iam_access_token>')
177-
```
178-
179-
```python
180-
# after instantiation, assuming control of managing IAM token
181-
discovery = DiscoveryV1(version='2018-08-01', url='<url_as_per_region>')
182-
discovery.set_iam_access_token('<access_token>')
196+
authenticator=authenticator)
183197
```
184198

185199
### Username and password
186200
```python
187201
from ibm_watson import DiscoveryV1
188-
# In the constructor
189-
discovery = DiscoveryV1(version='2018-08-01', url='<url_as_per_region>', username='<username>', password='<password>')
202+
from ibm_cloud_sdk_core.authenticators import BasicAuthenticator
203+
204+
authenticator = BasicAuthenticator('username', 'password')
205+
discovery = DiscoveryV1(version='2018-08-01', url='<url_as_per_region>', authenticator=authenticator)
190206
```
191207

208+
### No Authentication
192209
```python
193-
# After instantiation
194-
discovery = DiscoveryV1(version='2018-08-01', url='<url_as_per_region>')
195-
discovery.set_username_and_password('<username>', '<password>')
210+
from ibm_watson import DiscoveryV1
211+
from ibm_cloud_sdk_core.authenticators import NoAuthAuthenticator
212+
213+
authenticator = NoAuthAuthenticator()
214+
discovery = DiscoveryV1(version='2018-08-01', url='<url_as_per_region>', authenticator=authenticator)
196215
```
197216

198217
## Python version
199218

200-
Tested on Python 2.7, 3.5, 3.6, and 3.7.
219+
Tested on Python 3.5, 3.6, and 3.7.
201220

202221
## Changes for v1.0
203222
Version 1.0 focuses on the move to programmatically-generated code for many of the services. See the [changelog](https://github.com/watson-developer-cloud/python-sdk/wiki/Changelog) for the details.
@@ -225,6 +244,21 @@ The SDK is generated using OpenAPI Specification(OAS3). Changes are basic reorde
225244

226245
The package is renamed to ibm_watson. See the [changelog](https://github.com/watson-developer-cloud/python-sdk/wiki/Changelog) for the details.
227246

247+
## Changes for v4.0
248+
Authenticator variable indicates the type of authentication to be used.
249+
250+
```python
251+
from ibm_watson import AssistantV1
252+
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
253+
254+
authenticator = IAMAuthenticator('your apikey')
255+
assistant = AssistantV1(
256+
version='2018-07-10',
257+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
258+
url='https://gateway.watsonplatform.net/assistant/api',
259+
authenticator=authenticator)
260+
```
261+
228262
## Migration
229263
This version includes many breaking changes as a result of standardizing behavior across the new generated services. Full details on migration from previous versions can be found [here](https://github.com/watson-developer-cloud/python-sdk/wiki/Migration).
230264

@@ -233,12 +267,14 @@ To set client configs like timeout use the `with_http_config()` function and pas
233267

234268
```python
235269
from ibm_watson import AssistantV1
270+
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
236271

272+
authenticator = IAMAuthenticator('your apikey')
237273
assistant = AssistantV1(
238-
username='xxx',
239-
password='yyy',
240-
url='<url_as_per_region>',
241-
version='2018-07-10')
274+
version='2018-07-10',
275+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
276+
url='https://gateway.watsonplatform.net/assistant/api',
277+
authenticator=authenticator)
242278

243279
assistant.set_http_config({'timeout': 100})
244280
response = assistant.message(workspace_id=workspace_id, input={
@@ -250,7 +286,7 @@ print(json.dumps(response, indent=2))
250286
For ICP(IBM Cloud Private), you can disable the SSL certificate verification by:
251287

252288
```python
253-
service.disable_SSL_verification()
289+
service.set_disable_ssl_verification()
254290
```
255291

256292
## Sending request headers
@@ -264,12 +300,14 @@ For example, to send a header called `Custom-Header` to a call in Watson Assista
264300
the headers parameter as:
265301
```python
266302
from ibm_watson import AssistantV1
303+
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
267304

305+
authenticator = IAMAuthenticator('your apikey')
268306
assistant = AssistantV1(
269-
username='xxx',
270-
password='yyy',
271-
url='<url_as_per_region>',
272-
version='2018-07-10')
307+
version='2018-07-10',
308+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
309+
url='https://gateway.watsonplatform.net/assistant/api',
310+
authenticator=authenticator)
273311

274312
response = assistant.list_workspaces(headers={'Custom-Header': 'custom_value'}).get_result()
275313
```
@@ -278,12 +316,14 @@ response = assistant.list_workspaces(headers={'Custom-Header': 'custom_value'}).
278316
If you would like access to some HTTP response information along with the response model, you can set the `set_detailed_response()` to `True`. Since Python SDK `v2.0`, it is set to `True`
279317
```python
280318
from ibm_watson import AssistantV1
319+
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
281320

321+
authenticator = IAMAuthenticator('your apikey')
282322
assistant = AssistantV1(
283-
username='xxx',
284-
password='yyy',
285-
url='<url_as_per_region>',
286-
version='2018-07-10')
323+
version='2018-07-10',
324+
## url is optional, and defaults to the URL below. Use the correct URL for your region.
325+
url='https://gateway.watsonplatform.net/assistant/api',
326+
authenticator=authenticator)
287327

288328
assistant.set_detailed_response(True)
289329
response = assistant.list_workspaces(headers={'Custom-Header': 'custom_value'}).get_result()
@@ -324,31 +364,38 @@ service.synthesize_using_websocket('I like to pet dogs',
324364
)
325365
```
326366

327-
## IBM Cloud Pak for Data(ICP4D)
328-
If your service instance is of ICP4D, below are two ways of initializing the assistant service.
367+
## Cloud Pak for Data(CP4D)
368+
If your service instance is of CP4D, below are two ways of initializing the assistant service.
329369

330-
### 1) Supplying the username, password, icp4d_url and authentication_type
370+
### 1) Supplying the username, password and authentication url
331371
The SDK will manage the token for the user
332372
```python
373+
from ibm_watson import AssistantV1
374+
from ibm_cloud_sdk_core.authenticators import CloudPakForDataAuthenticator
375+
376+
authenticator = CloudPakForDataAuthenticator(
377+
'<your username>',
378+
'<your password>',
379+
'<authentication url>') # should be of the form https://{icp_cluster_host}{instance-id}/api
380+
333381
assistant = AssistantV1(
334-
version='<version',
335-
username='<your username>',
336-
password='<your password>',
382+
version='<version>',
337383
url='<service url>', # should be of the form https://{icp_cluster_host}/{deployment}/assistant/{instance-id}/api
338-
icp4d_url='<authentication url>', # should be of the form https://{icp_cluster_host}
339-
authentication_type='icp4d')
340-
341-
assistant.disable_SSL_verification() # MAKE SURE SSL VERIFICATION IS DISABLED
384+
authenticator=authenticator,
385+
disable_ssl_verification=True # MAKE SURE SSL VERIFICATION IS DISABLED
386+
)
342387
```
343388

344389
### 2) Supplying the access token
345390
```python
346-
assistant = AssistantV1(
347-
version='<version>',
348-
url='service url', # should be of the form https://{icp_cluster_host}/{deployment}/assistant/{instance-id}/api
349-
icp4d_access_token='<your managed access token>')
391+
from ibm_watson import AssistantV1
392+
from ibm_cloud_sdk_core.authenticators import BearerAuthenticator
350393

351-
assistant.disable_SSL_verification() # MAKE SURE SSL VERIFICATION IS DISABLED
394+
authenticator = BearerAuthenticator('your managed access token')
395+
assistant = AssistantV1(version='<version>',
396+
url='service url', # should be of the form https://{icp_cluster_host}/{deployment}/assistant/{instance-id}/api
397+
authenticator=authenticator,
398+
disable_ssl_verification=True) # MAKE SURE SSL VERIFICATION IS DISABLED
352399
```
353400

354401
## Dependencies
@@ -358,7 +405,7 @@ assistant.disable_SSL_verification() # MAKE SURE SSL VERIFICATION IS DISABLED
358405
* [responses] for testing
359406
* Following for web sockets support in speech to text
360407
* `websocket-client` 0.48.0
361-
* `ibm_cloud_sdk_core` >=0.5.1
408+
* `ibm_cloud_sdk_core` >= 1.0.0rc4
362409

363410
## Contributing
364411

appveyor.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ environment:
33
matrix:
44

55
- PYTHON: "C:\\Python35"
6-
- PYTHON: "C:\\Python27-x64"
76
- PYTHON: "C:\\Python36-x64"
87

98
install:

examples/assistant_tone_analyzer_integration/tone_assistant_integration.v1.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
from __future__ import print_function
21
import json
32
import os
43
from dotenv import load_dotenv, find_dotenv
54

65
from ibm_watson import AssistantV1
76
from ibm_watson import ToneAnalyzerV3
7+
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
88

99
# import tone detection
1010
import tone_detection
@@ -14,14 +14,16 @@
1414
load_dotenv(find_dotenv())
1515

1616
# replace with your own assistant credentials or put them in a .env file
17+
assistant_authenticator = IAMAuthenticator(os.environ.get('ASSISTANT_APIKEY') or 'YOUR ASSISTANT APIKEY')
1718
assistant = AssistantV1(
18-
iam_apikey=os.environ.get('ASSISTANT_APIKEY') or 'YOUR ASSISTANT APIKEY',
19-
version='2018-07-10')
19+
version='2018-07-10',
20+
authenticator=assistant_authenticator)
2021

2122
# replace with your own tone analyzer credentials
23+
tone_analyzer_authenticator = IAMAuthenticator(os.environ.get('TONE_ANALYZER_APIKEY') or 'YOUR TONE ANALYZER APIKEY')
2224
tone_analyzer = ToneAnalyzerV3(
23-
iam_apikey=os.environ.get('TONE_ANALYZER_APIKEY') or 'YOUR TONE ANALYZER APIKEY',
24-
version='2016-05-19')
25+
version='2016-05-19',
26+
authenticator=tone_analyzer_authenticator)
2527

2628
# replace with your own workspace_id
2729
workspace_id = os.environ.get('WORKSPACE_ID') or 'YOUR WORKSPACE ID'

0 commit comments

Comments
 (0)