Skip to content

Commit cb52715

Browse files
authored
[cosmos] readme review feedback (#11527)
* readme review feedback * Removed extra section
1 parent 016e7c6 commit cb52715

File tree

2 files changed

+47
-52
lines changed

2 files changed

+47
-52
lines changed

sdk/cosmos/azure-cosmos/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Release History
22

3-
## 4.0.0 (2020-05-18)
3+
## 4.0.0 (2020-05-20)
44

55
- Stable release.
66
- Added HttpLoggingPolicy to pipeline to enable passing in a custom logger for request and response headers.

sdk/cosmos/azure-cosmos/README.md

Lines changed: 46 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Use the Azure Cosmos DB SQL API SDK for Python to manage databases and the JSON
1313

1414

1515
## Getting started
16-
16+
### Prerequisites
1717
* Azure subscription - [Create a free account][azure_sub]
1818
* Azure [Cosmos DB account][cosmos_account] - SQL API
1919
* [Python 2.7 or 3.5.3+][python]
@@ -25,27 +25,24 @@ If you need a Cosmos DB SQL API account, you can create one with this [Azure CLI
2525
az cosmosdb create --resource-group <resource-group-name> --name <cosmos-account-name>
2626
```
2727

28-
## Installation
28+
### Install the package
2929

3030
```bash
3131
pip install azure-cosmos
3232
```
3333

34-
### Configure a virtual environment (optional)
34+
#### Configure a virtual environment (optional)
3535

3636
Although not required, you can keep your your base system and Azure SDK environments isolated from one another if you use a virtual environment. Execute the following commands to configure and then enter a virtual environment with [venv][venv]:
3737

3838
```Bash
3939
python3 -m venv azure-cosmosdb-sdk-environment
4040
source azure-cosmosdb-sdk-environment/bin/activate
4141
```
42-
43-
## Key concepts
42+
### Authenticate the client
4443

4544
Interaction with Cosmos DB starts with an instance of the [CosmosClient][ref_cosmosclient] class. You need an **account**, its **URI**, and one of its **account keys** to instantiate the client object.
4645

47-
### Get credentials
48-
4946
Use the Azure CLI snippet below to populate two environment variables with the database account URI and its primary master key (you can also find these values in the Azure portal). The snippet is formatted for the Bash shell.
5047

5148
```Bash
@@ -55,8 +52,7 @@ ACCT_NAME=<cosmos-db-account-name>
5552
export ACCOUNT_URI=$(az cosmosdb show --resource-group $RES_GROUP --name $ACCT_NAME --query documentEndpoint --output tsv)
5653
export ACCOUNT_KEY=$(az cosmosdb list-keys --resource-group $RES_GROUP --name $ACCT_NAME --query primaryMasterKey --output tsv)
5754
```
58-
59-
### Create client
55+
### Create the client
6056

6157
Once you've populated the `ACCOUNT_URI` and `ACCOUNT_KEY` environment variables, you can create the [CosmosClient][ref_cosmosclient].
6258

@@ -69,7 +65,7 @@ key = os.environ['ACCOUNT_KEY']
6965
client = CosmosClient(url, credential=key)
7066
```
7167

72-
## Usage
68+
## Key concepts
7369

7470
Once you've initialized a [CosmosClient][ref_cosmosclient], you can interact with the primary resource types in Cosmos DB:
7571

@@ -155,8 +151,9 @@ for i in range(1, 10):
155151
To delete items from a container, use [ContainerProxy.delete_item][ref_container_delete_item]. The SQL API in Cosmos DB does not support the SQL `DELETE` statement.
156152

157153
```Python
158-
for item in container.query_items(query='SELECT * FROM products p WHERE p.productModel = "DISCONTINUED"',
159-
enable_cross_partition_query=True):
154+
for item in container.query_items(
155+
query='SELECT * FROM products p WHERE p.productModel = "DISCONTINUED"',
156+
enable_cross_partition_query=True):
160157
container.delete_item(item, partition_key='Pager')
161158
```
162159

@@ -175,8 +172,8 @@ container = database.get_container_client(container_name)
175172
# Enumerate the returned items
176173
import json
177174
for item in container.query_items(
178-
query='SELECT * FROM mycontainer r WHERE r.id="item3"',
179-
enable_cross_partition_query=True):
175+
query='SELECT * FROM mycontainer r WHERE r.id="item3"',
176+
enable_cross_partition_query=True):
180177
print(json.dumps(item, indent=True))
181178
```
182179

@@ -215,50 +212,18 @@ Certain properties of an existing container can be modified. This example sets t
215212
```Python
216213
database = client.get_database_client(database_name)
217214
container = database.get_container_client(container_name)
218-
database.replace_container(container,
219-
partition_key=PartitionKey(path="/productName"),
220-
default_ttl=10,
221-
)
215+
database.replace_container(
216+
container,
217+
partition_key=PartitionKey(path="/productName"),
218+
default_ttl=10,
219+
)
222220
# Display the new TTL setting for the container
223221
container_props = container.read()
224222
print(json.dumps(container_props['defaultTtl']))
225223
```
226224

227225
For more information on TTL, see [Time to Live for Azure Cosmos DB data][cosmos_ttl].
228226

229-
## Optional Configuration
230-
231-
Optional keyword arguments that can be passed in at the client and per-operation level.
232-
233-
### Retry Policy configuration
234-
235-
Use the following keyword arguments when instantiating a client to configure the retry policy:
236-
237-
* __retry_total__ (int): Total number of retries to allow. Takes precedence over other counts.
238-
Pass in `retry_total=0` if you do not want to retry on requests. Defaults to 10.
239-
* __retry_connect__ (int): How many connection-related errors to retry on. Defaults to 3.
240-
* __retry_read__ (int): How many times to retry on read errors. Defaults to 3.
241-
* __retry_status__ (int): How many times to retry on bad status codes. Defaults to 3.
242-
243-
### Other client / per-operation configuration
244-
245-
Other optional configuration keyword arguments that can be specified on the client or per-operation.
246-
247-
**Client keyword arguments:**
248-
249-
* __enable_endpoint_discovery__ (bool): Enable endpoint discovery for geo-replicated database accounts. Default is `True`.
250-
* __preferred_locations__ (list[str]): The preferred locations for geo-replicated database accounts.
251-
* __connection_timeout__ (int): Optionally sets the connect and read timeout value, in seconds.
252-
* __transport__ (Any): User-provided transport to send the HTTP request.
253-
254-
**Per-operation keyword arguments:**
255-
256-
* __raw_response_hook__ (callable): The given callback uses the response returned from the service.
257-
* __user_agent__ (str): Appends the custom value to the user-agent header to be sent with the request.
258-
* __logging_enable__ (bool): Enables logging at the DEBUG level. Defaults to False. Can also be passed in at
259-
the client level to enable it for all requests.
260-
* __headers__ (dict): Pass in custom headers as key, value pairs. E.g. `headers={'CustomValue': value}`
261-
* __timeout__ (int): An absolute timeout in seconds, for the combined HTTP request and response processing.
262227

263228
## Troubleshooting
264229

@@ -278,6 +243,36 @@ except exceptions.CosmosResourceExistsError:
278243
HTTP status code 409: The ID (name) provided for the container is already in use.
279244
The container name must be unique within the database.""")
280245

246+
```
247+
### Logging
248+
This library uses the standard
249+
[logging](https://docs.python.org/3.5/library/logging.html) library for logging.
250+
Basic information about HTTP sessions (URLs, headers, etc.) is logged at INFO
251+
level.
252+
253+
Detailed DEBUG level logging, including request/response bodies and unredacted
254+
headers, can be enabled on a client with the `logging_enable` argument:
255+
```python
256+
import sys
257+
import logging
258+
from azure.cosmos import CosmosClient
259+
260+
# Create a logger for the 'azure' SDK
261+
logger = logging.getLogger('azure')
262+
logger.setLevel(logging.DEBUG)
263+
264+
# Configure a console output
265+
handler = logging.StreamHandler(stream=sys.stdout)
266+
logger.addHandler(handler)
267+
268+
# This client will log detailed information about its HTTP sessions, at DEBUG level
269+
client = CosmosClient(url, credential=key, logging_enable=True)
270+
```
271+
272+
Similarly, `logging_enable` can enable detailed logging for a single operation,
273+
even when it isn't enabled for the client:
274+
```py
275+
database = client.create_database(database_name, logging_enable=True)
281276
```
282277

283278
## Next steps

0 commit comments

Comments
 (0)