Skip to content
Merged
Show file tree
Hide file tree
Changes from 93 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
61ba8d1
initial commit
simorenoh Aug 13, 2021
15dcceb
Client Constructor (#20310)
annatisch Aug 20, 2021
bda95c3
read database
simorenoh Aug 27, 2021
c9648ab
Update simon_testfile.py
simorenoh Aug 27, 2021
80540dc
with coroutine
simorenoh Aug 30, 2021
1285438
Update simon_testfile.py
simorenoh Aug 30, 2021
992b0cd
small changes
simorenoh Aug 31, 2021
47cb688
async with returns no exceptions
simorenoh Aug 31, 2021
f3fa79f
Merge pull request #1 from Azure/simonmoreno/async
simorenoh Aug 31, 2021
0c49739
async read container
simorenoh Sep 1, 2021
47f4af5
async item read
simorenoh Sep 2, 2021
c97c946
cleaning up
simorenoh Sep 3, 2021
fcd95db
create item/ database methods
simorenoh Sep 13, 2021
36c5b90
item delete working
simorenoh Sep 13, 2021
44db2a2
docs replace functionality
simorenoh Sep 16, 2021
ec5b6ed
upsert functionality
simorenoh Sep 17, 2021
d63d052
Merge pull request #2 from simorenoh/item-read
simorenoh Oct 8, 2021
5d74c8f
missing query methods
simorenoh Oct 11, 2021
89fc2f7
CRUD for udf, sproc, triggers
simorenoh Oct 12, 2021
fdaa880
Merge branch 'Azure:main' into async-client
simorenoh Oct 12, 2021
3f9baf2
Merge branch 'Azure:main' into async-client
simorenoh Oct 12, 2021
d6650bc
Merge branch 'Azure:main' into query-functionality
simorenoh Oct 12, 2021
043dfe0
initial query logic + container methods
simorenoh Oct 13, 2021
befdb41
Merge branch 'async-client' into query-functionality
simorenoh Oct 13, 2021
8cffbe2
Merge pull request #3 from simorenoh/query-functionality
simorenoh Oct 13, 2021
72de7c8
missing some execution logic and tests
simorenoh Oct 21, 2021
5b805b8
oops
simorenoh Oct 21, 2021
8d8d0c4
fully working queries
simorenoh Oct 22, 2021
b597ca8
small fix to query_items()
simorenoh Oct 22, 2021
18319df
Update _cosmos_client_connection_async.py
simorenoh Oct 22, 2021
162c44d
Update _cosmos_client_connection.py
simorenoh Oct 22, 2021
ebbac51
documentation update
simorenoh Oct 22, 2021
43f78e6
Merge branch 'Azure:main' into main
simorenoh Oct 22, 2021
470aa5b
updated MIT dates and get_user_client() description
simorenoh Oct 22, 2021
74da690
Update CHANGELOG.md
simorenoh Oct 22, 2021
7104d63
Merge branch 'Azure:main' into main
simorenoh Oct 25, 2021
20718c7
Delete simon_testfile.py
simorenoh Oct 25, 2021
d825eaa
Merge pull request #4 from simorenoh/async-client
simorenoh Oct 25, 2021
e3c27a5
leftover retry utility
simorenoh Oct 25, 2021
3b778ad
Update README.md
simorenoh Oct 25, 2021
c6e352e
docs and removed six package
simorenoh Oct 28, 2021
8971a25
Merge remote-tracking branch 'upstream/main'
simorenoh Oct 28, 2021
52736ac
changes based on comments
simorenoh Nov 4, 2021
ad98039
small change in type hints
simorenoh Nov 4, 2021
f76c595
updated readme
simorenoh Nov 9, 2021
3f02a65
fixes based on conversations
simorenoh Nov 10, 2021
e719869
added missing type comments
simorenoh Nov 11, 2021
d03ee05
Merge branch 'Azure:main' into main
simorenoh Nov 11, 2021
02c52ee
update changelog for ci pipeline
simorenoh Nov 23, 2021
2cb4551
added typehints, moved params into keywords, added decorators, made _…
simorenoh Nov 29, 2021
cf20d35
changes based on sync with central sdk
simorenoh Dec 2, 2021
f456817
remove is_system_key from scripts (only used in execute_sproc)
simorenoh Dec 3, 2021
ea9bd16
Revert "remove is_system_key from scripts (only used in execute_sproc)"
simorenoh Dec 3, 2021
709d2eb
async script proxy using composition
simorenoh Dec 3, 2021
3277dd8
pylint
simorenoh Dec 3, 2021
a57cb4d
capitalized constants
simorenoh Dec 6, 2021
014578b
Apply suggestions from code review
simorenoh Dec 6, 2021
0d79695
closing python code snippet
simorenoh Dec 6, 2021
fdabea1
last doc updates
simorenoh Dec 7, 2021
016d0dd
Update sdk/cosmos/azure-cosmos/CHANGELOG.md
tjprescott Dec 7, 2021
8228aa9
version update
simorenoh Dec 7, 2021
7ae1cd0
Merge branch 'Azure:main' into main
simorenoh Dec 13, 2021
7e8e953
cosmos updates for release
simorenoh Dec 13, 2021
caad36c
public surface area python3 typehints
simorenoh Dec 30, 2021
99997e9
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python …
simorenoh Jan 12, 2022
f446308
Merge branch 'Azure-main'
simorenoh Jan 12, 2022
bc466d8
Merge branch 'Azure-main'
simorenoh Jan 12, 2022
bca2da7
Merge branch 'Azure:main' into main
simorenoh Jan 13, 2022
437895f
fix connection string comma
simorenoh Jan 18, 2022
dd4b4a4
Update CHANGELOG.md
simorenoh Jan 18, 2022
73838be
Merge branch 'main' into python3-typehints
simorenoh Jan 20, 2022
24c5a73
Merge branch 'main' into python3-typehints
simorenoh Jan 20, 2022
79e0b28
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python
simorenoh Jan 25, 2022
399f8bc
Merge branch 'Azure:main' into main
simorenoh Jan 25, 2022
a3bd2e8
fixing extra await keyword in sample
simorenoh Feb 25, 2022
dbf1532
Update CHANGELOG.md
simorenoh Feb 25, 2022
c275953
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python
simorenoh Mar 10, 2022
140b042
Update CHANGELOG.md
simorenoh Mar 10, 2022
426a616
Merge branch 'main' of https://github.com/Azure/azure-sdk-for-python
simorenoh Apr 5, 2022
7c551dc
Merge branch 'Azure:main' into main
simorenoh Apr 6, 2022
0678376
Merge branch 'Azure:main' into main
simorenoh Apr 6, 2022
e49a6ce
Merge branch 'python3-typehints' of https://github.com/simorenoh/azur…
simorenoh Apr 11, 2022
2b23648
simplified short types into one line and moved many options to kwargs
simorenoh Apr 13, 2022
b702457
missed additional Callable definitions
simorenoh Apr 13, 2022
cf54382
pylint
simorenoh Apr 13, 2022
90a6b12
addressed several comments, thank you Travis
simorenoh Apr 14, 2022
87bac28
Update CHANGELOG.md
simorenoh Apr 14, 2022
39a2681
Callable typehints
simorenoh Apr 19, 2022
311847d
Merge branch 'main' into simorenoh-python3-typehints
simorenoh Apr 19, 2022
eeceef2
Update CHANGELOG.md
simorenoh Apr 19, 2022
d44502f
bets practices recommends using string partition keys
simorenoh Apr 20, 2022
d8093b7
Revert "bets practices recommends using string partition keys"
simorenoh Apr 20, 2022
4968d8b
Merge branch 'main' into simorenoh-python3-typehints
simorenoh Apr 25, 2022
7f5a5f1
Update sdk/cosmos/azure-cosmos/azure/cosmos/container.py
simorenoh May 2, 2022
b509da5
Merge branch 'main' into simorenoh-python3-typehints
simorenoh May 2, 2022
992f79d
changes from meeting
simorenoh May 2, 2022
56f1914
Update CHANGELOG.md
simorenoh May 2, 2022
2951f86
update query types
simorenoh May 3, 2022
c1c2d1d
Update dev_requirements.txt
simorenoh May 3, 2022
b42f162
Update setup.py
simorenoh May 3, 2022
4eadc97
type checking for tokencredential
simorenoh May 3, 2022
052fd33
Revert "type checking for tokencredential"
simorenoh May 3, 2022
1f8dd14
update shared_requirements
simorenoh May 3, 2022
8c5d364
anna comments
simorenoh May 4, 2022
e386375
pylint?
simorenoh May 4, 2022
7c1e348
Update _scripts.py
simorenoh May 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions sdk/cosmos/azure-cosmos/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@

### 4.3.0b5 (Unreleased)

#### Features Added

#### Breaking Changes

#### Bugs Fixed
- Method signatures have been updated to use keyword arguments instead of positional arguments for most method options in the async client.

#### Other Changes
- Added samples showing how to configure retry options for both the sync and async clients.
- Deprecated the `connection_retry_policy` and `retry_options` options in the sync client.

### 4.3.0b4 (2022-04-07)

#### Features Added
Expand Down
338 changes: 187 additions & 151 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/container.py

Large diffs are not rendered by default.

187 changes: 100 additions & 87 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/cosmos_client.py

Large diffs are not rendered by default.

387 changes: 208 additions & 179 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/database.py

Large diffs are not rendered by default.

240 changes: 137 additions & 103 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/scripts.py

Large diffs are not rendered by default.

135 changes: 77 additions & 58 deletions sdk/cosmos/azure-cosmos/azure/cosmos/aio/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from ._cosmos_client_connection_async import CosmosClientConnection
from .._base import build_options
from ..permission import Permission as _permission
from ..permission import Permission


class UserProxy(object):
Expand All @@ -42,19 +42,22 @@ class UserProxy(object):
:func:`DatabaseProxy.get_user_client` method.
"""

def __init__(self, client_connection, id, database_link, properties=None): # pylint: disable=redefined-builtin
# type: (CosmosClientConnection, str, str, Dict[str, Any]) -> None
def __init__(
self,
client_connection: CosmosClientConnection,
id: str, # pylint: disable=redefined-builtin
database_link: str,
properties: Dict[str, Any] = None
) -> None:
self.client_connection = client_connection
self.id = id
self.user_link = u"{}/users/{}".format(database_link, id)
self._properties = properties

def __repr__(self):
# type () -> str
def __repr__(self) -> str:
return "<UserProxy [{}]>".format(self.user_link)[:1024]

def _get_permission_link(self, permission_or_id):
# type: (Union[Permission, str, Dict[str, Any]]) -> str
def _get_permission_link(self, permission_or_id: Union[Permission, str, Dict[str, Any]]) -> str:
if isinstance(permission_or_id, str):
return u"{}/permissions/{}".format(self.user_link, permission_or_id)
try:
Expand All @@ -63,21 +66,20 @@ def _get_permission_link(self, permission_or_id):
pass
return u"{}/permissions/{}".format(self.user_link, cast("Dict[str, str]", permission_or_id)["id"])

async def _get_properties(self):
# type: () -> Dict[str, Any]
async def _get_properties(self) -> Dict[str, Any]:
if self._properties is None:
self._properties = await self.read()
return self._properties

@distributed_trace_async
async def read(self, **kwargs):
# type: (Any) -> Dict[str, Any]
"""Read user propertes.
async def read(self, **kwargs: Any) -> Dict[str, Any]:
"""Read user properties.

:keyword Callable response_hook: A callable invoked with the response metadata.
:returns: A dictionary of the retrieved user properties.
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], Any]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given user couldn't be retrieved.
:rtype: dict[str, Any]
:returns: A dictionary of the retrieved user properties.
:rtype: Dict[str, Any]
"""
request_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
Expand All @@ -91,17 +93,18 @@ async def read(self, **kwargs):
return cast('Dict[str, Any]', self._properties)

@distributed_trace
def list_permissions(self, max_item_count=None, **kwargs):
# type: (Optional[int], Any) -> AsyncItemPaged[Dict[str, Any]]
def list_permissions(self, **kwargs: Any) -> AsyncItemPaged[Dict[str, Any]]:
"""List all permission for the user.

:param max_item_count: Max number of permissions to be returned in the enumeration operation.
:keyword Callable response_hook: A callable invoked with the response metadata.
:keyword int max_item_count: Max number of permissions to be returned in the enumeration operation.
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], AsyncItemPaged[Dict[str, Any]], Any]
:returns: An AsyncItemPaged of permissions (dicts).
:rtype: AsyncItemPaged[dict[str, Any]]
:rtype: AsyncItemPaged[Dict[str, Any]]
"""
feed_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
max_item_count = kwargs.pop('max_item_count', None)
if max_item_count is not None:
feed_options["maxItemCount"] = max_item_count

Expand All @@ -115,23 +118,24 @@ def list_permissions(self, max_item_count=None, **kwargs):
@distributed_trace
def query_permissions(
self,
query,
parameters=None,
max_item_count=None,
**kwargs
):
# type: (str, Optional[List[str]], Optional[int], Any) -> AsyncItemPaged[Dict[str, Any]]
query: str,
parameters: Optional[List[Dict[str, Any]]] = None,
**kwargs: Any
) -> AsyncItemPaged[Dict[str, Any]]:
"""Return all permissions matching the given `query`.

:param query: The Azure Cosmos DB SQL query to execute.
:param str query: The Azure Cosmos DB SQL query to execute.
:param parameters: Optional array of parameters to the query. Ignored if no query is provided.
:param max_item_count: Max number of permissions to be returned in the enumeration operation.
:keyword Callable response_hook: A callable invoked with the response metadata.
:type parameters: Optional[List[Dict[str, Any]]]
:keyword int max_item_count: Max number of permissions to be returned in the enumeration operation.
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], AsyncItemPaged[Dict[str, Any]]], Any]
:returns: An AsyncItemPaged of permissions (dicts).
:rtype: AsyncItemPaged[dict[str, Any]]
:rtype: AsyncItemPaged[Dict[str, Any]]
"""
feed_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
max_item_count = kwargs.pop('max_item_count', None)
if max_item_count is not None:
feed_options["maxItemCount"] = max_item_count

Expand All @@ -148,16 +152,21 @@ def query_permissions(
return result

@distributed_trace_async
async def get_permission(self, permission, **kwargs):
# type: (Union[str, Dict[str, Any], Permission], Any) -> Permission
async def get_permission(
self,
permission: Union[str, Dict[str, Any], Permission],
**kwargs: Any
) -> Permission:
"""Get the permission identified by `id`.

:param permission: The ID (name), dict representing the properties or :class:`Permission`
instance of the permission to be retrieved.
:keyword Callable response_hook: A callable invoked with the response metadata.
:returns: A dict representing the retrieved permission.
:type permission: Union[str, Dict[str, Any], ~azure.cosmos.Permission]
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], Any]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given permission couldn't be retrieved.
:rtype: dict[str, Any]
:returns: The retrieved permission object.
:rtype: ~azure.cosmos.Permission
"""
request_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
Expand All @@ -169,7 +178,7 @@ async def get_permission(self, permission, **kwargs):
if response_hook:
response_hook(self.client_connection.last_response_headers, permission_resp)

return _permission(
return Permission(
id=permission_resp["id"],
user_link=self.user_link,
permission_mode=permission_resp["permissionMode"],
Expand All @@ -178,17 +187,18 @@ async def get_permission(self, permission, **kwargs):
)

@distributed_trace_async
async def create_permission(self, body, **kwargs):
# type: (Dict[str, Any], Any) -> Permission
async def create_permission(self, body: Dict[str, Any], **kwargs: Any) -> Permission:
"""Create a permission for the user.

To update or replace an existing permision, use the :func:`UserProxy.upsert_permission` method.
To update or replace an existing permission, use the :func:`UserProxy.upsert_permission` method.

:param body: A dict-like object representing the permission to create.
:keyword Callable response_hook: A callable invoked with the response metadata.
:returns: A dict representing the new permission.
:type body: Dict[str, Any]
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], Any]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given permission couldn't be created.
:rtype: dict[str, Any]
:returns: A permission object representing the new permission.
:rtype: ~azure.cosmos.Permission
"""
request_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
Expand All @@ -200,7 +210,7 @@ async def create_permission(self, body, **kwargs):
if response_hook:
response_hook(self.client_connection.last_response_headers, permission)

return _permission(
return Permission(
id=permission["id"],
user_link=self.user_link,
permission_mode=permission["permissionMode"],
Expand All @@ -209,18 +219,19 @@ async def create_permission(self, body, **kwargs):
)

@distributed_trace_async
async def upsert_permission(self, body, **kwargs):
# type: (Dict[str, Any], Any) -> Permission
async def upsert_permission(self, body: Dict[str, Any], **kwargs: Any) -> Permission:
"""Insert or update the specified permission.

If the permission already exists in the container, it is replaced. If
the permission does not exist, it is inserted.

:param body: A dict-like object representing the permission to update or insert.
:param Callable response_hook: A callable invoked with the response metadata.
:returns: A dict representing the upserted permission.
:type body: Dict[str, Any]
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], Any]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the given permission could not be upserted.
:rtype: dict[str, Any]
:returns: A dict representing the upserted permission.
:rtype: ~azure.cosmos.Permission
"""
request_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
Expand All @@ -232,7 +243,7 @@ async def upsert_permission(self, body, **kwargs):
if response_hook:
response_hook(self.client_connection.last_response_headers, permission)

return _permission(
return Permission(
id=permission["id"],
user_link=self.user_link,
permission_mode=permission["permissionMode"],
Expand All @@ -241,20 +252,27 @@ async def upsert_permission(self, body, **kwargs):
)

@distributed_trace_async
async def replace_permission(self, permission, body, **kwargs):
# type: (str, Union[str, Dict[str, Any], Permission], Any) -> Permission
async def replace_permission(
self,
permission: Union[str, Dict[str, Any], Permission],
body: Dict[str, Any],
**kwargs: Any
) -> Permission:
"""Replaces the specified permission if it exists for the user.

If the permission does not already exist, an exception is raised.

:param permission: The ID (name), dict representing the properties or :class:`Permission`
instance of the permission to be replaced.
:type permission: Union[str, Dict[str, Any], ~azure.cosmos.Permission]
:param body: A dict-like object representing the permission to replace.
:keyword Callable response_hook: A callable invoked with the response metadata.
:returns: A dict representing the permission after replace went through.
:type body: Dict[str, Any]
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], Dict[str, Any]], Any]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: If the replace failed or the permission
with given id does not exist.
:rtype: dict[str, Any]
:returns: A permission object representing the permission after the replace went through.
:rtype: ~azure.cosmos.Permission
"""
request_options = build_options(kwargs)
response_hook = kwargs.pop('response_hook', None)
Expand All @@ -266,7 +284,7 @@ async def replace_permission(self, permission, body, **kwargs):
if response_hook:
response_hook(self.client_connection.last_response_headers, permission_resp)

return _permission(
return Permission(
id=permission_resp["id"],
user_link=self.user_link,
permission_mode=permission_resp["permissionMode"],
Expand All @@ -275,15 +293,16 @@ async def replace_permission(self, permission, body, **kwargs):
)

@distributed_trace_async
async def delete_permission(self, permission, **kwargs):
# type: (Union[str, Dict[str, Any], Permission], Any) -> None
async def delete_permission(self, permission: Union[str, Dict[str, Any], Permission], **kwargs: Any) -> None:
"""Delete the specified permission from the user.

If the permission does not already exist, an exception is raised.

:param permission: The ID (name), dict representing the properties or :class:`Permission`
instance of the permission to be deleted.
:keyword Callable response_hook: A callable invoked with the response metadata.
:type permission: Union[str, Dict[str, Any], ~azure.cosmos.Permission]
:keyword response_hook: A callable invoked with the response metadata.
:paramtype response_hook: Callable[[Dict[str, str], None], Any]
:raises ~azure.cosmos.exceptions.CosmosHttpResponseError: The permission wasn't deleted successfully.
:raises ~azure.cosmos.exceptions.CosmosResourceNotFoundError: The permission does not exist for the user.
:rtype: None
Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/azure/cosmos/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def query_items(
For accounts configured to use the integrated cache, using Session or Eventual consistency,
responses are guaranteed to be no staler than this value.
:returns: An Iterable of items (dicts).
:rtype: Iterable[dict[str, Any]]
:rtype: ItemPaged[dict[str, Any]]

.. admonition:: Example:

Expand Down
2 changes: 1 addition & 1 deletion sdk/cosmos/azure-cosmos/azure/cosmos/cosmos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class CosmosClient(object):

:param str url: The URL of the Cosmos DB account.
:param credential: Can be the account key, or a dictionary of resource tokens.
:type credential: str or dict[str, str]
:type credential: Union[str, Dict[str, str], ~azure.core.credentials.TokenCredential]
:param str consistency_level: Consistency level to use for the session. The default value is None (Account level).
:keyword int timeout: An absolute timeout in seconds, for the combined HTTP request and response processing.
:keyword int request_timeout: The HTTP request timeout in milliseconds.
Expand Down