Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
c8b92f5
[EG] dont hardcode api_version on request (#34965)
l0lawrence Mar 27, 2024
d5c7f31
add sync side patches
l0lawrence Mar 27, 2024
b33f24e
aio patches
l0lawrence Mar 29, 2024
10275c3
update readme samples
l0lawrence Mar 29, 2024
4b972fb
all samples use EGClient
l0lawrence Mar 29, 2024
6afe650
update readme samples
l0lawrence Mar 29, 2024
c2da0d2
fix imports
l0lawrence Mar 29, 2024
6e30992
import issue
l0lawrence Mar 29, 2024
3a3dfd5
missing pathc
l0lawrence Mar 29, 2024
1d2e3fb
allow sas cred
l0lawrence Mar 29, 2024
36156ee
typo
l0lawrence Mar 29, 2024
1ffe29c
updates
l0lawrence Mar 29, 2024
d31a9ad
sas
l0lawrence Mar 29, 2024
eddc282
client
l0lawrence Mar 29, 2024
9195ef8
self serialize cloudevent
l0lawrence Apr 1, 2024
5e4face
add bakc in
l0lawrence Apr 1, 2024
dc9dfb1
updates
l0lawrence Apr 1, 2024
18e30ab
update ptach
l0lawrence Apr 1, 2024
9e0ab3d
update
l0lawrence Apr 1, 2024
da460d5
update exception logic
l0lawrence Apr 1, 2024
f445558
async w client
l0lawrence Apr 1, 2024
b1568d3
aio [atch
l0lawrence Apr 1, 2024
e5666bc
typo
l0lawrence Apr 1, 2024
8ce9377
import
l0lawrence Apr 1, 2024
a55861b
update links
l0lawrence Apr 1, 2024
3e9231a
tests
l0lawrence Apr 1, 2024
cce33cc
raise error
l0lawrence Apr 1, 2024
8e68c4c
content type
l0lawrence Apr 1, 2024
009d24b
use more fake url
l0lawrence Apr 1, 2024
a0e055f
remove content type
l0lawrence Apr 1, 2024
9a5fb89
mypy
l0lawrence Apr 1, 2024
4f42263
update apiversion
l0lawrence Apr 1, 2024
2737e9e
content type
l0lawrence Apr 1, 2024
a3a78ac
unitttests
l0lawrence Apr 2, 2024
ef4b2eb
update auth
l0lawrence Apr 2, 2024
37e7839
updates
l0lawrence Apr 2, 2024
de8f2bd
add level
l0lawrence Apr 2, 2024
241cdc2
update readme
l0lawrence Apr 2, 2024
d744e99
update
l0lawrence Apr 2, 2024
4dfa335
binary mode
l0lawrence Apr 2, 2024
cb9354d
args, kwargs
l0lawrence Apr 2, 2024
240e959
remove auth
l0lawrence Apr 2, 2024
339a9d6
add sample comments
l0lawrence Apr 2, 2024
0938e4b
testing
l0lawrence Apr 2, 2024
7c4934b
move around readme
l0lawrence Apr 2, 2024
ccd5c85
content type
l0lawrence Apr 3, 2024
307668a
update tests
l0lawrence Apr 3, 2024
55ace2e
docstring
l0lawrence Apr 3, 2024
e078283
cncf event
l0lawrence Apr 3, 2024
38007d7
add more tests
l0lawrence Apr 3, 2024
fe2d551
update doc
l0lawrence Apr 3, 2024
0769169
update inits to prevent typing errors
l0lawrence Apr 3, 2024
3afea29
ran blakc
l0lawrence Apr 3, 2024
5a6f41a
fix pylint patch
l0lawrence Apr 3, 2024
03ff6b3
changes
l0lawrence Apr 3, 2024
51737b4
add all kwargs
l0lawrence Apr 3, 2024
0f4ab57
indent
l0lawrence Apr 3, 2024
fd8adfc
reviews
l0lawrence Apr 3, 2024
bf35f7b
nit
l0lawrence Apr 3, 2024
bd4ea4e
name changes
l0lawrence Apr 3, 2024
fe0623a
options
l0lawrence Apr 3, 2024
6d37422
options/result rename
l0lawrence Apr 3, 2024
291e88c
Revert "options"
l0lawrence Apr 4, 2024
93fb64b
Revert "options/result rename"
l0lawrence Apr 4, 2024
61e81c0
fix tests
l0lawrence Apr 4, 2024
475ed6a
remove or None
l0lawrence Apr 4, 2024
bf94364
remove EGPubClient
l0lawrence Apr 4, 2024
7d4e712
remove options naming
l0lawrence Apr 4, 2024
e5c92a6
Merge branch 'llawrence/eg/oneclient' of https://github.com/l0lawrenc…
l0lawrence Apr 4, 2024
788a3e3
Revert "remove EGPubClient"
l0lawrence Apr 4, 2024
92543d8
typeerror
l0lawrence Apr 4, 2024
6c293ac
update readme
l0lawrence Apr 4, 2024
bb514b7
readme nit
l0lawrence Apr 4, 2024
f4fc072
readme updates
l0lawrence Apr 4, 2024
31a200a
add send operation samples
l0lawrence Apr 4, 2024
1a5b355
add datacontenttpye
l0lawrence Apr 4, 2024
1abb59f
typo
l0lawrence Apr 5, 2024
c906efa
make Options bag models kwargs
l0lawrence Apr 5, 2024
484cea4
remove models
l0lawrence Apr 5, 2024
67b5ba3
import
l0lawrence Apr 5, 2024
bb45754
exception
l0lawrence Apr 5, 2024
19ca9e0
update changelog
l0lawrence Apr 5, 2024
cd37161
shorten operation names
l0lawrence Apr 5, 2024
e793e38
nit
l0lawrence Apr 5, 2024
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
Prev Previous commit
Next Next commit
update readme samples
  • Loading branch information
l0lawrence committed Mar 29, 2024
commit 6afe65096348fab66318d1ea45abc6ca518a67fc
118 changes: 84 additions & 34 deletions sdk/eventgrid/azure-eventgrid/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ Azure Event Grid is a fully-managed intelligent event routing service that allow

## _Disclaimer_

This is a beta release of Azure EventGrid's `EventGridClient`, which along with the GA `EventGridPublisherClient`. `EventGridClient` supports `publish_cloud_events`, `receive_cloud_events`, `acknowledge_cloud_events` , `release_cloud_events`, `reject_cloud_events`, and `renew_cloud_event_locks` operations. Please refer to the [samples](https://github.com/Azure/azure-sdk-for-python/tree/feature/eventgrid/sdk/eventgrid/azure-eventgrid/samples/sync_samples/eventgrid_client_samples) for further information.
This is a beta release of Azure EventGrid's `EventGridClient`. `EventGridClient` supports `send`, `receive_cloud_events`, `acknowledge_cloud_events` , `release_cloud_events`, `reject_cloud_events`, and `renew_cloud_event_locks` operations. Please refer to the [samples](https://github.com/Azure/azure-sdk-for-python/tree/feature/eventgrid/sdk/eventgrid/azure-eventgrid/samples/sync_samples/eventgrid_client_samples) for further information.

## Getting started

### Prerequisites
* Python 3.7 or later is required to use this package.
* You must have an [Azure subscription][azure_subscription] and an Event Grid Topic resource to use this package. Follow this [step-by-step tutorial](https://docs.microsoft.com/azure/event-grid/custom-event-quickstart-portal) to register the Event Grid resource provider and create Event Grid topics using the [Azure portal](https://portal.azure.com/). There is a [similar tutorial](https://docs.microsoft.com/azure/event-grid/custom-event-quickstart) using [Azure CLI](https://docs.microsoft.com/cli/azure).
* Python 3.8 or later is required to use this package.
* You must have an [Azure subscription][azure_subscription] and an Event Grid Namespace resource, or an Event Grid Topic resource to use this package. To create an Event Grid Namespace resource follow [this tutorial](https://learn.microsoft.com/en-us/azure/event-grid/create-view-manage-namespaces). Follow this [step-by-step tutorial](https://docs.microsoft.com/azure/event-grid/custom-event-quickstart-portal) to register the Event Grid resource provider and create Event Grid topics using the [Azure portal](https://portal.azure.com/). There is a [similar tutorial](https://docs.microsoft.com/azure/event-grid/custom-event-quickstart) using [Azure CLI](https://docs.microsoft.com/cli/azure).


### Install the package
Expand All @@ -28,17 +28,29 @@ Install the Azure Event Grid client library for Python with [pip][pip]:
pip install azure-eventgrid
```

* An existing Event Grid topic or domain is required. You can create the resource using [Azure Portal][azure_portal_create_EG_resource] or [Azure CLI][azure_cli_link]
* An existing Event Grid Basic topic or domain, or Event Grid Namespace topic is required. You can create the resource using [Azure Portal][azure_portal_create_EG_resource] or [Azure CLI][azure_cli_link]

If you use Azure CLI, replace `<resource-group-name>` and `<resource-name>` with your own unique names.

#### Create an Event Grid Topic
#### Create an Event Grid Namespace

```
az eventgrid namespace create --location <location> --resource-group <resource-group-name> --name <resource-name>
```

#### Create an Event Grid Namespace Topic

```
az eventgrid namespace create topic --location <location> --resource-group <resource-group-name> --name <resource-name>
```

#### Create an Event Grid Basic Topic

```
az eventgrid topic --create --location <location> --resource-group <resource-group-name> --name <resource-name>
```

#### Create an Event Grid Domain
#### Create an Event Grid Basic Domain

```
az eventgrid domain --create --location <location> --resource-group <resource-group-name> --name <resource-name>
Expand All @@ -62,16 +74,22 @@ For example, you can use `DefaultAzureCredential` to construct a client which wi

```python
from azure.identity import DefaultAzureCredential
from azure.eventgrid import EventGridPublisherClient, EventGridEvent
from azure.eventgrid import EventGridClient, EventGridEvent

default_az_credential = DefaultAzureCredential()
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
client = EventGridPublisherClient(endpoint, default_az_credential)
endpoint = os.environ["EVENTGRID_NAMESPACE_ENDPOINT"]
client = EventGridClient(endpoint, default_az_credential)
```

<!-- END SNIPPET -->

#### Looking up the endpoint

##### Event Grid Namespace
You can find the Namespace endpoint within the Event Grid Namespace resource on the Azure portal. This will look like:
`"<event-grid-namespace-name>.<namespace-location>.eventgrid.azure.net"`

##### Event Grid Basic
You can find the topic endpoint within the Event Grid Topic resource on the Azure portal. This will look like:
`"https://<event-grid-topic-name>.<topic-location>.eventgrid.azure.net/api/events"`

Expand All @@ -86,14 +104,14 @@ pass the key as a string into an instance of [AzureKeyCredential][azure-key-cred

```python
import os
from azure.eventgrid import EventGridPublisherClient
from azure.eventgrid import EventGridClient
from azure.core.credentials import AzureKeyCredential

topic_key = os.environ["EVENTGRID_TOPIC_KEY"]
endpoint = os.environ["EVENTGRID_TOPIC_ENDPOINT"]
key = os.environ["EVENTGRID_NAMESPACE_KEY"]
endpoint = os.environ["EVENTGRID_NAMESPACE_ENDPOINT"]

credential_key = AzureKeyCredential(topic_key)
client = EventGridPublisherClient(endpoint, credential_key)
credential_key = AzureKeyCredential(key)
client = EventGridClient(endpoint, credential_key)
```

<!-- END SNIPPET -->
Expand All @@ -104,29 +122,43 @@ client = EventGridPublisherClient(endpoint, credential_key)

## Key concepts

### Topic
### Namespace

A **[namespace](https://learn.microsoft.com/en-us/azure/event-grid/concepts-event-grid-namespaces#namespaces)** is a management container for other resources. It allows for grouping of related resources in order to manage them under one subscription.

#### Namespace Topic

A **[namespace topic](https://learn.microsoft.com/en-us/azure/event-grid/concepts-event-grid-namespaces#namespace-topics)** are topics that are created within an Event Grid namespace. The client publishes events to an HTTP namespace endpoint specifying a namespace topic where published events are logically contained. A namespace topic only supports the CloudEvent v1.0 schema.

#### Event Subscription

An **[event subscription](https://learn.microsoft.com/en-us/azure/event-grid/concepts-event-grid-namespaces#event-subscriptions)** is a configuration resource associated with a single topic.

### Basic

#### Topic
A **[topic](https://docs.microsoft.com/azure/event-grid/concepts#topics)** is a channel within the EventGrid service to send events. The event schema that a topic accepts is decided at topic creation time. If events of a schema type are sent to a topic that requires a different schema type, errors will be raised.

### Domain
#### Domain
An event **[domain](https://docs.microsoft.com/azure/event-grid/event-domains)** is a management tool for large numbers of Event Grid topics related to the same application. They allow you to publish events to thousands of topics. Domains also give you authorization and authentication control over each topic. For more information, visit [Event domain overview](https://docs.microsoft.com/azure/event-grid/event-domains).

When you create an event domain, a publishing endpoint for this domain is made available to you. This process is similar to creating an Event Grid Topic. The only difference is that, when publishing to a domain, you must specify the topic within the domain that you'd like the event to be delivered to.

### Event schemas
#### Event schemas
An **[event](https://docs.microsoft.com/azure/event-grid/concepts#events)** is the smallest amount of information that fully describes something that happened in the system. When a custom topic or domain is created, you must specify the schema that will be used when publishing events.

Event Grid supports multiple schemas for encoding events.

#### Event Grid schema
##### Event Grid schema
While you may configure your topic to use a [custom schema](https://docs.microsoft.com/azure/event-grid/input-mappings), it is more common to use the already-defined Event Grid schema. See the specifications and requirements [here](https://docs.microsoft.com/azure/event-grid/event-schema).

#### CloudEvents v1.0 schema
##### CloudEvents v1.0 schema
Another option is to use the CloudEvents v1.0 schema. [CloudEvents](https://cloudevents.io/) is a Cloud Native Computing Foundation project which produces a specification for describing event data in a common way. The service summary of CloudEvents can be found [here](https://docs.microsoft.com/azure/event-grid/cloud-event-schema).

### EventGridPublisherClient
`EventGridPublisherClient` provides operations to send event data to a topic hostname specified during client initialization.
### EventGridClient
`EventGridClient` provides operations to send, receive, acknowledge, reject, release event data to a resource specified during client initialization.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor nit for clarity:

Suggested change
`EventGridClient` provides operations to send, receive, acknowledge, reject, release event data to a resource specified during client initialization.
`EventGridClient` provides operations to send to, receive from, acknowledge, reject, release event data for a resource specified during client initialization.


Regardless of the schema that your topic or domain is configured to use, `EventGridPublisherClient` will be used to publish events to it. Use the `send` method publishing events.
If you are using Event Grid Basic, regardless of the schema that your topic or domain is configured to use, `EventGridClient` will be used to publish events to it. Use the `send` method publishing events.

The following formats of events are allowed to be sent:
- A list or a single instance of strongly typed EventGridEvents.
Expand Down Expand Up @@ -184,7 +216,7 @@ This example publishes an Event Grid event.
```python
import os
from azure.core.credentials import AzureKeyCredential
from azure.eventgrid import EventGridPublisherClient, EventGridEvent
from azure.eventgrid import EventGridClient, EventGridEvent, ClientLevel

key = os.environ["EG_ACCESS_KEY"]
endpoint = os.environ["EG_TOPIC_HOSTNAME"]
Expand All @@ -197,7 +229,7 @@ event = EventGridEvent(
)

credential = AzureKeyCredential(key)
client = EventGridPublisherClient(endpoint, credential)
client = EventGridClient(endpoint, credential, level=ClientLevel.BASIC)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any examples using STANDARD in the readme (other than linking to them). Is that intentional since the usage would be the same and more people would be using basic?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all these examples are only supported by EventGrid Basic


client.send(event)
```
Expand All @@ -210,7 +242,7 @@ This example publishes a Cloud event.
import os
from azure.core.credentials import AzureKeyCredential
from azure.core.messaging import CloudEvent
from azure.eventgrid import EventGridPublisherClient
from azure.eventgrid import EventGridClient, ClientLevel

key = os.environ["CLOUD_ACCESS_KEY"]
endpoint = os.environ["CLOUD_TOPIC_HOSTNAME"]
Expand All @@ -222,7 +254,7 @@ event = CloudEvent(
)

credential = AzureKeyCredential(key)
client = EventGridPublisherClient(endpoint, credential)
client = EventGridClient(endpoint, credential, level=ClientLevel.BASIC)

client.send(event)
```
Expand All @@ -237,7 +269,7 @@ It is possible to send events as a batch when sending multiple events to a topic
import os
from azure.core.credentials import AzureKeyCredential
from azure.core.messaging import CloudEvent
from azure.eventgrid import EventGridPublisherClient
from azure.eventgrid import EventGridClient, ClientLevel

key = os.environ["CLOUD_ACCESS_KEY"]
endpoint = os.environ["CLOUD_TOPIC_HOSTNAME"]
Expand All @@ -256,7 +288,7 @@ event1 = CloudEvent(
events = [event0, event1]

credential = AzureKeyCredential(key)
client = EventGridPublisherClient(endpoint, credential)
client = EventGridClient(endpoint, credential, level=ClientLevel.BASIC)

client.send(events)
```
Expand All @@ -273,7 +305,7 @@ import uuid
import datetime as dt
from msrest.serialization import UTC
from azure.core.credentials import AzureKeyCredential
from azure.eventgrid import EventGridPublisherClient
from azure.eventgrid import EventGridClient, ClientLevel

key = os.environ["CUSTOM_SCHEMA_ACCESS_KEY"]
endpoint = os.environ["CUSTOM_SCHEMA_TOPIC_HOSTNAME"]
Expand All @@ -288,7 +320,7 @@ event = custom_schema_event = {
}

credential = AzureKeyCredential(key)
client = EventGridPublisherClient(endpoint, credential)
client = EventGridClient(endpoint, credential, level=ClientLevel.BASIC)

client.send(event)
```
Expand Down Expand Up @@ -372,11 +404,11 @@ trace.get_tracer_provider().add_span_processor(
)
```

Once the `tracer` and `exporter` are set, please follow the example below to start collecting traces while using the `send` method from the `EventGridPublisherClient` to send a CloudEvent object.
Once the `tracer` and `exporter` are set, please follow the example below to start collecting traces while using the `send` method from the `EventGridClient` to send a CloudEvent object.

```python
import os
from azure.eventgrid import EventGridPublisherClient
from azure.eventgrid import EventGridClient, ClientLevel
from azure.core.messaging import CloudEvent
from azure.core.credentials import AzureKeyCredential

Expand All @@ -388,7 +420,7 @@ cloud_event = CloudEvent(
data = {'test': 'hello'},
)
with tracer.start_as_current_span(name="MyApplication"):
client = EventGridPublisherClient(hostname, key)
client = EventGridClient(hostname, key, level=ClientLevel.BASIC)
client.send(cloud_event)
```

Expand Down Expand Up @@ -419,6 +451,14 @@ The following section provides several code snippets illustrating common pattern

These code samples show common champion scenario operations with the Azure Event Grid client library.

#### Namespaces EventGrid Scenarios

* Authenticate the client: [sample_eg_client_authentication.py][python-eg-client-auth-samples]
* Sample of all operations: [sample_all_operations.py][python-eg-client-all-ops-sample]
* Publish cloud event in binary mode: [sample_binary_mode_operation.py][python-eg-client-binary-mode-sample]

#### Basic EventGrid Scenarios

* Generate Shared Access Signature: [sample_generate_sas.py][python-eg-generate-sas]

* Authenticate the client: [sample_authentication.py][python-eg-auth] ([async_version][python-eg-auth-async])
Expand Down Expand Up @@ -494,7 +534,17 @@ This project has adopted the [Microsoft Open Source Code of Conduct][code_of_con
[python-eg-consume-samples]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/consume_samples
[python-eg-sample-consume-custom-payload]: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/eventgrid/azure-eventgrid/samples/sync_samples/sample_consume_custom_payload.py


[python-eg-client-aad-auth-samples]:https://github.com/Azure/azure-sdk-for-python/blob/feature/eventgrid/sdk/eventgrid/azure-eventgrid/samples/sync_samples/eventgrid_client_samples/sample_aad_auth_operation.py

[python-eg-client-auth-samples]:https://github.com/Azure/azure-sdk-for-python/blob/feature/eventgrid/sdk/eventgrid/azure-eventgrid/samples/sync_samples/eventgrid_client_samples/sample_eg_client_authentication.py

[python-eg-client-all-ops-sample]:https://github.com/Azure/azure-sdk-for-python/blob/feature/eventgrid/sdk/eventgrid/azure-eventgrid/samples/sync_samples/eventgrid_client_samples/sample_all_operations.py

[python-eg-client-binary-mode-sample]:https://github.com/Azure/azure-sdk-for-python/blob/feature/eventgrid/sdk/eventgrid/azure-eventgrid/samples/sync_samples/eventgrid_client_samples/sample_binary_mode.py


[cla]: https://cla.microsoft.com
[code_of_conduct]: https://opensource.microsoft.com/codeofconduct/
[coc_faq]: https://opensource.microsoft.com/codeofconduct/faq/
[coc_contact]: mailto:[email protected]
[coc_contact]: mailto:[email protected]