Skip to content

Commit 49a2f49

Browse files
xiangyan99mccoyp
andauthored
readme update to opt in code snippet tool (Azure#28889)
* app config * updates * update readmes * Update sdk/keyvault/azure-keyvault-certificates/README.md Co-authored-by: McCoy Patiño <39780829+mccoyp@users.noreply.github.com> * update * update * update * update * Update sdk/keyvault/azure-keyvault-keys/README.md Co-authored-by: McCoy Patiño <39780829+mccoyp@users.noreply.github.com> * update * update * update * Update sdk/keyvault/azure-keyvault-secrets/README.md Co-authored-by: McCoy Patiño <39780829+mccoyp@users.noreply.github.com> * Update sdk/keyvault/azure-keyvault-secrets/samples/hello_world.py Co-authored-by: McCoy Patiño <39780829+mccoyp@users.noreply.github.com> * Updates * update * update * update * update * update * updates * update * update * update * updates * update * update * update * update * update * update * update --------- Co-authored-by: McCoy Patiño <39780829+mccoyp@users.noreply.github.com>
1 parent a4e362d commit 49a2f49

File tree

49 files changed

+1156
-748
lines changed

Some content is hidden

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

49 files changed

+1156
-748
lines changed

sdk/appconfiguration/azure-appconfiguration/README.md

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,16 @@ Alternatively, get the connection string from the Azure Portal.
5858

5959
Once you have the value of the connection string, you can create the AzureAppConfigurationClient:
6060

61+
<!-- SNIPPET:hello_world_sample.create_app_config_client -->
6162
```python
63+
import os
6264
from azure.appconfiguration import AzureAppConfigurationClient
65+
CONNECTION_STRING = os.environ['APPCONFIGURATION_CONNECTION_STRING']
6366

64-
connection_str = "<connection_string>"
65-
client = AzureAppConfigurationClient.from_connection_string(connection_str)
67+
# Create app config client
68+
client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)
6669
```
70+
<!-- END SNIPPET -->
6771

6872
#### Use AAD token
6973

@@ -162,6 +166,7 @@ There are two ways to store a Configuration Setting:
162166

163167
- add_configuration_setting creates a setting only if the setting does not already exist in the store.
164168

169+
<!-- SNIPPET:hello_world_advanced_sample.create_config_setting -->
165170
```python
166171
config_setting = ConfigurationSetting(
167172
key="MyKey",
@@ -172,86 +177,91 @@ config_setting = ConfigurationSetting(
172177
)
173178
added_config_setting = client.add_configuration_setting(config_setting)
174179
```
180+
<!-- END SNIPPET -->
175181

176182
- set_configuration_setting creates a setting if it doesn't exist or overrides an existing setting.
177183

184+
<!-- SNIPPET:hello_world_advanced_sample.set_config_setting -->
178185
```python
179-
config_setting = ConfigurationSetting(
180-
key="MyKey",
181-
label="MyLabel",
182-
value="my set value",
183-
content_type="my set content type",
184-
tags={"my set tag": "my set tag value"}
185-
)
186-
returned_config_setting = client.set_configuration_setting(config_setting)
186+
added_config_setting.value = "new value"
187+
added_config_setting.content_type = "new content type"
188+
updated_config_setting = client.set_configuration_setting(config_setting)
187189
```
190+
<!-- END SNIPPET -->
188191

189192
### Get a Configuration Setting
190193

191194
Get a previously stored Configuration Setting.
192195

196+
<!-- SNIPPET:hello_world_sample.get_config_setting -->
193197
```python
194198
fetched_config_setting = client.get_configuration_setting(
195-
key="MyKey", label="MyLabel"
199+
key="MyKey"
196200
)
197201
```
202+
<!-- END SNIPPET -->
198203

199204
### Delete a Configuration Setting
200205

201206
Delete an existing Configuration Setting.
202207

208+
<!-- SNIPPET:hello_world_advanced_sample.delete_config_setting -->
203209
```python
204-
deleted_config_setting = client.delete_configuration_setting(
205-
key="MyKey", label="MyLabel"
210+
client.delete_configuration_setting(
211+
key="MyKey",
212+
label="MyLabel",
206213
)
207214
```
215+
<!-- END SNIPPET -->
208216

209217
### List Configuration Settings
210218

211219
List all configuration settings filtered with label_filter and/or key_filter.
212220

221+
<!-- SNIPPET:hello_world_advanced_sample.list_config_setting -->
213222
```python
214-
215-
filtered_listed = client.list_configuration_settings(
216-
label_filter="My*", key_filter="My*"
217-
)
218-
for item in filtered_listed:
219-
pass # do something
220-
223+
config_settings = client.list_configuration_settings(label_filter="MyLabel")
224+
for item in config_settings:
225+
print_configuration_setting(item)
221226
```
227+
<!-- END SNIPPET -->
222228

223229
### Async APIs
224230

225231
Async client is supported.
226232
To use the async client library, import the AzureAppConfigurationClient from package azure.appconfiguration.aio instead of azure.appconfiguration
227233

234+
<!-- SNIPPET:hello_world_sample_async.create_app_config_client -->
228235
```python
236+
import os
229237
from azure.appconfiguration.aio import AzureAppConfigurationClient
238+
CONNECTION_STRING = os.environ['APPCONFIGURATION_CONNECTION_STRING']
230239

231-
connection_str = "<connection_string>"
232-
async_client = AzureAppConfigurationClient.from_connection_string(connection_str)
240+
# Create app config client
241+
client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)
233242
```
243+
<!-- END SNIPPET -->
234244

235245
This async AzureAppConfigurationClient has the same method signatures as the sync ones except that they're async.
236246
For instance, to retrieve a Configuration Setting asynchronously, async_client can be used:
237247

248+
<!-- SNIPPET:hello_world_sample_async.get_config_setting -->
238249
```python
239-
fetched_config_setting = await async_client.get_configuration_setting(
240-
key="MyKey", label="MyLabel"
250+
fetched_config_setting = await client.get_configuration_setting(
251+
key="MyKey"
241252
)
242253
```
254+
<!-- END SNIPPET -->
243255

244256
To use list_configuration_settings, call it synchronously and iterate over the returned async iterator asynchronously
245257

258+
<!-- SNIPPET:hello_world_advanced_sample_async.list_config_setting -->
246259
```python
247-
248-
filtered_listed = async_client.list_configuration_settings(
249-
label_filter="My*", key_filter="My*"
250-
)
251-
async for item in filtered_listed:
252-
pass # do something
253-
260+
config_settings = client.list_configuration_settings(label_filter="MyLabel")
261+
async for item in config_settings:
262+
print_configuration_setting(item)
254263
```
264+
<!-- END SNIPPET -->
255265

256266
## Troubleshooting
257267

sdk/appconfiguration/azure-appconfiguration/samples/hello_world_advanced_sample.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def main():
2323
client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)
2424

2525
print("Add new configuration setting")
26+
# [START create_config_setting]
2627
config_setting = ConfigurationSetting(
2728
key="MyKey",
2829
label="MyLabel",
@@ -31,27 +32,34 @@ def main():
3132
tags={"my tag": "my tag value"}
3233
)
3334
added_config_setting = client.add_configuration_setting(config_setting)
35+
# [END create_config_setting]
3436
print("New configuration setting:")
3537
print_configuration_setting(added_config_setting)
3638
print("")
3739

3840
print("Set configuration setting")
41+
# [START set_config_setting]
3942
added_config_setting.value = "new value"
4043
added_config_setting.content_type = "new content type"
4144
updated_config_setting = client.set_configuration_setting(config_setting)
45+
# [END set_config_setting]
4246
print_configuration_setting(updated_config_setting)
4347
print("")
4448

4549
print("List configuration settings")
50+
# [START list_config_setting]
4651
config_settings = client.list_configuration_settings(label_filter="MyLabel")
4752
for item in config_settings:
4853
print_configuration_setting(item)
54+
# [END list_config_setting]
4955

5056
print("Delete configuration setting")
57+
# [START delete_config_setting]
5158
client.delete_configuration_setting(
5259
key="MyKey",
5360
label="MyLabel",
5461
)
62+
# [END delete_config_setting]
5563

5664
if __name__ == "__main__":
5765
main()

sdk/appconfiguration/azure-appconfiguration/samples/hello_world_advanced_sample_async.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,11 @@ async def main():
4545
print("")
4646

4747
print("List configuration settings")
48+
# [START list_config_setting]
4849
config_settings = client.list_configuration_settings(label_filter="MyLabel")
4950
async for item in config_settings:
5051
print_configuration_setting(item)
52+
# [END list_config_setting]
5153

5254
print("Delete configuration setting")
5355
await client.delete_configuration_setting(

sdk/appconfiguration/azure-appconfiguration/samples/hello_world_sample.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@
1313
USAGE: python hello_world_sample.py
1414
"""
1515

16-
from azure.appconfiguration import AzureAppConfigurationClient, ConfigurationSetting
17-
from util import print_configuration_setting, get_connection_string
16+
from azure.appconfiguration import ConfigurationSetting
17+
from util import print_configuration_setting
1818

1919
def main():
20-
CONNECTION_STRING = get_connection_string()
20+
# [START create_app_config_client]
21+
import os
22+
from azure.appconfiguration import AzureAppConfigurationClient
23+
CONNECTION_STRING = os.environ['APPCONFIGURATION_CONNECTION_STRING']
2124

2225
# Create app config client
2326
client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)
27+
# [END create_app_config_client]
2428

2529
print("Set new configuration setting")
2630
config_setting = ConfigurationSetting(
@@ -35,9 +39,11 @@ def main():
3539
print("")
3640

3741
print("Get configuration setting")
42+
# [START get_config_setting]
3843
fetched_config_setting = client.get_configuration_setting(
3944
key="MyKey"
4045
)
46+
# [END get_config_setting]
4147
print("Fetched configuration setting:")
4248
print_configuration_setting(fetched_config_setting)
4349
print("")

sdk/appconfiguration/azure-appconfiguration/samples/hello_world_sample_async.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@
1515

1616
import asyncio
1717
from azure.appconfiguration import ConfigurationSetting
18-
from azure.appconfiguration.aio import AzureAppConfigurationClient
19-
from util import print_configuration_setting, get_connection_string
18+
from util import print_configuration_setting
2019

2120
async def main():
22-
CONNECTION_STRING = get_connection_string()
21+
# [START create_app_config_client]
22+
import os
23+
from azure.appconfiguration.aio import AzureAppConfigurationClient
24+
CONNECTION_STRING = os.environ['APPCONFIGURATION_CONNECTION_STRING']
2325

2426
# Create app config client
2527
client = AzureAppConfigurationClient.from_connection_string(CONNECTION_STRING)
28+
# [END create_app_config_client]
2629

2730
print("Set new configuration setting")
2831
config_setting = ConfigurationSetting(
@@ -37,9 +40,11 @@ async def main():
3740
print("")
3841

3942
print("Get configuration setting")
43+
# [START get_config_setting]
4044
fetched_config_setting = await client.get_configuration_setting(
4145
key="MyKey"
4246
)
47+
# [END get_config_setting]
4348
print("Fetched configuration setting:")
4449
print_configuration_setting(fetched_config_setting)
4550
print("")

sdk/cognitiveservices/azure-cognitiveservices-vision-computervision/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export ACCOUNT_KEY=$(az cognitiveservices account keys list \
8787

8888
Once you've populated the `ACCOUNT_REGION` and `ACCOUNT_KEY` environment variables, you can create the [ComputerVisionClient][ref_computervisionclient] client object.
8989

90-
```Python
90+
```python
9191
from azure.cognitiveservices.vision.computervision import ComputerVisionClient
9292
from azure.cognitiveservices.vision.computervision.models import VisualFeatureTypes
9393
from msrest.authentication import CognitiveServicesCredentials
@@ -128,7 +128,7 @@ The following sections provide several code snippets covering some of the most c
128128

129129
You can analyze an image for certain features with [`analyze_image`][ref_computervisionclient_analyze_image]. Use the [`visual_features`][ref_computervision_model_visualfeatures] property to set the types of analysis to perform on the image. Common values are `VisualFeatureTypes.tags` and `VisualFeatureTypes.description`.
130130

131-
```Python
131+
```python
132132
url = "https://upload.wikimedia.org/wikipedia/commons/thumb/1/12/Broadway_and_Times_Square_by_night.jpg/450px-Broadway_and_Times_Square_by_night.jpg"
133133

134134
image_analysis = client.analyze_image(url,visual_features=[VisualFeatureTypes.tags])
@@ -141,7 +141,7 @@ for tag in image_analysis.tags:
141141

142142
Review the subject domains used to analyze your image with [`list_models`][ref_computervisionclient_list_models]. These domain names are used when [analyzing an image by domain](#analyze-an-image-by-domain). An example of a domain is `landmarks`.
143143

144-
```Python
144+
```python
145145
models = client.list_models()
146146

147147
for x in models.models_property:
@@ -152,7 +152,7 @@ for x in models.models_property:
152152

153153
You can analyze an image by subject domain with [`analyze_image_by_domain`][ref_computervisionclient_analyze_image_by_domain]. Get the [list of supported subject domains](#get-subject-domain-list) in order to use the correct domain name.
154154

155-
```Python
155+
```python
156156
domain = "landmarks"
157157
url = "https://images.pexels.com/photos/338515/pexels-photo-338515.jpeg"
158158
language = "en"
@@ -168,7 +168,7 @@ for landmark in analysis.result["landmarks"]:
168168

169169
You can get a language-based text description of an image with [`describe_image`][ref_computervisionclient_describe_image]. Request several descriptions with the `max_description` property if you are doing text analysis for keywords associated with the image. Examples of a text description for the following image include `a train crossing a bridge over a body of water`, `a large bridge over a body of water`, and `a train crossing a bridge over a large body of water`.
170170

171-
```Python
171+
```python
172172
domain = "landmarks"
173173
url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg"
174174
language = "en"
@@ -185,7 +185,7 @@ for caption in analysis.captions:
185185

186186
You can get any handwritten or printed text from an image. This requires two calls to the SDK: [`read`][ref_computervisionclient_read] and [`get_read_result`][ref_computervisionclient_get_read_result]. The call to read is asynchronous. In the results of the get_read_result call, you need to check if the first call completed with [`OperationStatusCodes`][ref_computervision_model_operationstatuscodes] before extracting the text data. The results include the text as well as the bounding box coordinates for the text.
187187

188-
```Python
188+
```python
189189
# import models
190190
from azure.cognitiveservices.vision.computervision.models import OperationStatusCodes
191191

@@ -218,7 +218,7 @@ You can generate a thumbnail (JPG) of an image with [`generate_thumbnail`][ref_c
218218

219219
This example uses the [Pillow][pypi_pillow] package to save the new thumbnail image locally.
220220

221-
```Python
221+
```python
222222
from PIL import Image
223223
import io
224224

@@ -242,7 +242,7 @@ When you interact with the [ComputerVisionClient][ref_computervisionclient] clie
242242

243243
For example, if you try to analyze an image with an invalid key, a `401` error is returned. In the following snippet, the [error][ref_httpfailure] is handled gracefully by catching the exception and displaying additional information about the error.
244244

245-
```Python
245+
```python
246246

247247
domain = "landmarks"
248248
url = "http://www.public-domain-photos.com/free-stock-photos-4/travel/san-francisco/golden-gate-bridge-in-san-francisco.jpg"

0 commit comments

Comments
 (0)