azure.messaging.webpubsubservice package

class azure.messaging.webpubsubservice.WebPubSubServiceClient(endpoint: str, credential: corecredentials.AzureKeyCredential, **kwargs: Any)[source]

Create a new WebPubSubServiceClient instance

Parameters
  • endpoint (~str) – Endpoint to connect to.

  • credential (AzureKeyCredential) – Credentials to use to connect to endpoint.

Keyword Arguments
  • api_version – Api version to use when communicating with the service.

  • user – User to connect as. Optional.

classmethod from_connection_string(connection_string: Type[ClientType], **kwargs: str) → ClientType[source]

Create a new WebPubSubServiceClient from a connection string.

Parameters

connection_string (~str) – Connection string

Return type

WebPubSubServiceClient

send_request(http_request: corerest.HttpRequest, **kwargs: Any) → corerest.HttpResponse[source]

Runs the network request through the client’s chained policies.

We have helper methods to create requests specific to this service in azure.messaging.webpubsub.rest. Use these helper methods to create the request you pass to this method. See our example below:

>>> from azure.messaging.webpubsub.rest import build_healthapi_get_health_status_request
>>> request = build_healthapi_get_health_status_request(api_version)
<HttpRequest [HEAD], url: '/api/health'>
>>> response = client.send_request(request)
<HttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/python/llcwiki

For advanced cases, you can also create your own HttpRequest and pass it in.

Parameters

http_request (HttpRequest) – The network request you want to make. Required.

Keyword Arguments

stream_response (bool) – Whether the response payload will be streamed. Defaults to False.

Returns

The response of your network call. Does not do error handling on your response.

Return type

HttpResponse

azure.messaging.webpubsubservice.build_authentication_token(endpoint, hub, **kwargs)[source]

Build an authentication token for the given endpoint, hub using the provided key.

Keyword Arguments
  • endpoint – connetion string or HTTP or HTTPS endpoint for the WebPubSub service instance.

  • hub – The hub to give access to.

  • accesskey – Key to sign the token with. Required if endpoint is not a connection string

  • ttl – Optional ttl timedelta for the token. Default is 1 hour.

  • user – Optional user name (subject) for the token. Default is no user.

  • roles – Roles for the token.

Returns

~dict containing the web socket endpoint, the token and a url with the generated access token.

Return type

~dict

Example: >>> build_authentication_token(endpoint=’https://contoso.com/api/webpubsub’, hub=’theHub’, key=’123’) {

‘baseUrl’: ‘wss://contoso.com/api/webpubsub/client/hubs/theHub’, ‘token’: ‘eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ…’, ‘url’: ‘wss://contoso.com/api/webpubsub/client/hubs/theHub?access_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ…’

}

Subpackages

Submodules

azure.messaging.webpubsubservice.aio module

class azure.messaging.webpubsubservice.aio.WebPubSubServiceClient(endpoint: str, credential: corecredentials.AzureKeyCredential, **kwargs: Any)[source]

Create a new WebPubSubServiceClient instance

Parameters
  • endpoint (~str) – Endpoint to connect to.

  • credential (AzureKeyCredential) – Credentials to use to connect to endpoint.

Keyword Arguments
  • api_version – Api version to use when communicating with the service.

  • user – User to connect as. Optional.

async send_request(http_request: azure.messaging.webpubsubservice.core.rest._rest_py3.HttpRequest, **kwargs: Any) → azure.messaging.webpubsubservice.core.rest._rest_py3.AsyncHttpResponse[source]

Runs the network request through the client’s chained policies.

We have helper methods to create requests specific to this service in azure.messaging.webpubsub.rest. Use these helper methods to create the request you pass to this method. See our example below:

>>> from azure.messaging.webpubsub.rest import build_healthapi_get_health_status_request
>>> request = build_healthapi_get_health_status_request(api_version)
<HttpRequest [HEAD], url: '/api/health'>
>>> response = await client.send_request(request)
<AsyncHttpResponse: 200 OK>

For more information on this code flow, see https://aka.ms/azsdk/python/llcwiki

For advanced cases, you can also create your own HttpRequest and pass it in.

Parameters

http_request (HttpRequest) – The network request you want to make. Required.

Keyword Arguments

stream_response (bool) – Whether the response payload will be streamed. Defaults to False.

Returns

The response of your network call. Does not do error handling on your response.

Return type

AsyncHttpResponse

azure.messaging.webpubsubservice.rest module

azure.messaging.webpubsubservice.rest.build_add_connection_to_group_request(hub: str, group: str, connection_id: str, **kwargs: Any) → HttpRequest[source]

Add a connection to the target group.

Add a connection to the target group.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • group (str) – Target group name, which length should be greater than 0 and less than 1025.

  • connection_id (str) – Target connection Id.

Keyword Arguments

api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_add_user_to_group_request(hub: str, group: str, user_id: str, **kwargs: Any) → HttpRequest[source]

Add a user to the target group.

Add a user to the target group.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • group (str) – Target group name, which length should be greater than 0 and less than 1025.

  • user_id (str) – Target user Id.

Keyword Arguments

api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_connection_exists_request(hub: str, connection_id: str, **kwargs: Any) → HttpRequest[source]

Check if the connection with the given connectionId exists.

Check if the connection with the given connectionId exists.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • connection_id (str) – The connection Id.

Keyword Arguments

api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_group_exists_request(hub: str, group: str, **kwargs: Any) → HttpRequest[source]

Check if there are any client connections inside the given group.

Check if there are any client connections inside the given group.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • group (str) – Target group name, which length should be greater than 0 and less than 1025.

Keyword Arguments

api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_check_permission_request(hub: str, permission: Permissions, connection_id: str, **kwargs: Any) → HttpRequest[source]

Check if a connection has permission to the specified action.

Check if a connection has permission to the specified action.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • permission (~Permissions) – The permission: current supported actions are joinLeaveGroup and sendToGroup.

  • connection_id (str) – Target connection Id.

Keyword Arguments
  • target_name (str) – Optional. If not set, get the permission for all targets. If set, get the permission for the specific target. The meaning of the target depends on the specific permission.

  • api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_user_exists_request(hub: str, user_id: str, **kwargs: Any) → HttpRequest[source]

Check if there are any client connections connected for the given user.

Check if there are any client connections connected for the given user.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • user_id (str) – Target user Id.

Keyword Arguments

api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_close_client_connection_request(hub: str, connection_id: str, **kwargs: Any) → HttpRequest[source]

Close the client connection.

Close the client connection.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • connection_id (str) – Target connection Id.

Keyword Arguments
  • reason (str) – The reason closing the client connection.

  • api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_grant_permission_request(hub: str, permission: Permissions, connection_id: str, **kwargs: Any) → HttpRequest[source]

Grant permission to the connection.

Grant permission to the connection.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • permission (str or ~Permissions) – The permission: current supported actions are joinLeaveGroup and sendToGroup.

  • connection_id (str) – Target connection Id.

Keyword Arguments
  • target_name (str) – Optional. If not set, grant the permission to all the targets. If set, grant the permission to the specific target. The meaning of the target depends on the specific permission.

  • api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_healthapi_get_health_status_request(**kwargs: Any) → HttpRequest[source]

Get service health status.

Get service health status.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Keyword Arguments

api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_remove_connection_from_group_request(hub: str, group: str, connection_id: str, **kwargs: Any) → HttpRequest[source]

Remove a connection from the target group.

Remove a connection from the target group.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • group (str) – Target group name, which length should be greater than 0 and less than 1025.

  • connection_id (str) – Target connection Id.

Keyword Arguments

api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_remove_user_from_all_groups_request(hub: str, user_id: str, **kwargs: Any) → HttpRequest[source]

Remove a user from all groups.

Remove a user from all groups.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • user_id (str) – Target user Id.

Keyword Arguments

api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_remove_user_from_group_request(hub: str, group: str, user_id: str, **kwargs: Any) → HttpRequest[source]

Remove a user from the target group.

Remove a user from the target group.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • group (str) – Target group name, which length should be greater than 0 and less than 1025.

  • user_id (str) – Target user Id.

Keyword Arguments

api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_revoke_permission_request(hub: str, permission: Permissions, connection_id: str, **kwargs: Any) → HttpRequest[source]

Revoke permission for the connection.

Revoke permission for the connection.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • permission (str or ~Permissions) – The permission: current supported actions are joinLeaveGroup and sendToGroup.

  • connection_id (str) – Target connection Id.

Keyword Arguments
  • target_name (str) – Optional. If not set, revoke the permission for all targets. If set, revoke the permission for the specific target. The meaning of the target depends on the specific permission.

  • api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

azure.messaging.webpubsubservice.rest.build_send_to_all_request(hub: str, **kwargs: Any) → HttpRequest[source]

Broadcast content inside request body to all the connected client connections.

Broadcast content inside request body to all the connected client connections.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters

hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

Keyword Arguments
  • json (Any) – The payload body.

  • content (IO) – The payload body.

  • excluded (list[str]) – Excluded connection Ids.

  • api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

Example

# JSON input template you can fill out and use as your `json` input.
json = "Any (optional)"
azure.messaging.webpubsubservice.rest.build_send_to_connection_request(hub: str, connection_id: str, **kwargs: Any) → HttpRequest[source]

Send content inside request body to the specific connection.

Send content inside request body to the specific connection.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • connection_id (str) – The connection Id.

Keyword Arguments
  • json (Any) – The payload body.

  • content (IO) – The payload body.

  • api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

Example

# JSON input template you can fill out and use as your `json` input.
json = "Any (optional)"
azure.messaging.webpubsubservice.rest.build_send_to_group_request(hub: str, group: str, **kwargs: Any) → HttpRequest[source]

Send content inside request body to a group of connections.

Send content inside request body to a group of connections.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • group (str) – Target group name, which length should be greater than 0 and less than 1025.

Keyword Arguments
  • json (Any) – The payload body.

  • content (IO) – The payload body.

  • excluded (list[str]) – Excluded connection Ids.

  • api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

Example

# JSON input template you can fill out and use as your `json` input.
json = "Any (optional)"
azure.messaging.webpubsubservice.rest.build_send_to_user_request(hub: str, user_id: str, **kwargs: Any) → HttpRequest[source]

Send content inside request body to the specific user.

Send content inside request body to the specific user.

See https://aka.ms/azsdk/python/llcwiki for how to incorporate this request builder into your code flow.

Parameters
  • hub (str) – Target hub name, which should start with alphabetic characters and only contain alpha-numeric characters or underscore.

  • user_id (str) – The user Id.

Keyword Arguments
  • json (Any) – The payload body.

  • content (IO) – The payload body.

  • api_version (str) – Api Version.

Returns

Returns an HttpRequest that you will pass to the client’s send_request method. See https://aka.ms/azsdk/python/llcwiki for how to incorporate this response into your code flow.

Return type

HttpRequest

Example

# JSON input template you can fill out and use as your `json` input.
json = "Any (optional)"