azure.eventgrid package

class azure.eventgrid.EventGridPublisherClient(topic_hostname: str, credential: Union[AzureKeyCredential, EventGridSharedAccessSignatureCredential], **kwargs: Any)[source]

EventGrid Python Publisher Client.

Parameters
send(events: SendType, **kwargs: Any)None[source]

Sends event data to topic hostname specified during client initialization.

Parameters

events (SendType) – A list or an instance of CloudEvent/EventGridEvent/CustomEvent to be sent.

Keyword Arguments

content_type (str) – The type of content to be used to send the events. Has default value “application/json; charset=utf-8” for EventGridEvents, with “cloudevents-batch+json” for CloudEvents

Return type

None

Raises

ValueError, when events do not follow specified SendType.

class azure.eventgrid.EventGridConsumer[source]

A consumer responsible for deserializing event handler messages, to allow for access to strongly typed Event objects.

decode_cloud_event(cloud_event: Union[str, dict, bytes], **kwargs: Any) → CloudEvent[source]

Single event following CloudEvent schema will be parsed and returned as Deserialized Event. :param cloud_event: The event to be deserialized. :type cloud_event: Union[str, dict, bytes] :rtype: CloudEvent

Raise

ValueError, when events do not follow CloudEvent schema.

decode_eventgrid_event(eventgrid_event: Union[str, dict, bytes], **kwargs: Any) → EventGridEvent[source]

Single event following EventGridEvent schema will be parsed and returned as Deserialized Event. :param eventgrid_event: The event to be deserialized. :type eventgrid_event: Union[str, dict, bytes] :rtype: EventGridEvent

Raise

ValueError, when events do not follow EventGridEvent schema.

class azure.eventgrid.CloudEvent(source: str, type: str, **kwargs: Any)[source]

Properties of an event published to an Event Grid topic using the CloudEvent 1.0 Schema.

All required parameters must be populated in order to send to Azure.

Parameters
  • source (str) – Required. Identifies the context in which an event happened. The combination of id and source must be unique for each distinct event. If publishing to a domain topic, source must be the domain name.

  • data (object) – Event data specific to the event type.

  • type (str) – Required. Type of event related to the originating occurrence.

  • time (datetime) – The time (in UTC) the event was generated, in RFC3339 format.

  • dataschema (str) – Identifies the schema that data adheres to.

  • datacontenttype (str) – Content type of data value.

  • subject (str) – This describes the subject of the event in the context of the event producer (identified by source).

  • id (Optional[str]) – Optional. An identifier for the event. The combination of id and source must be unique for each distinct event.

class azure.eventgrid.CustomEvent(*args: Any, **kwargs: Any)[source]

The wrapper class for a CustomEvent, to be used when publishing events. :param dict args: dict

get(key, default=None)
has_key(k)
items()
keys()
update(*args, **kwargs)
values()
class azure.eventgrid.EventGridEvent(subject: str, event_type: str, **kwargs: Any)[source]

Properties of an event published to an Event Grid topic using the EventGrid Schema.

Variables are only populated by the server, and will be ignored when sending a request.

All required parameters must be populated in order to send to Azure.

Parameters
  • topic (str) – The resource path of the event source. If not provided, Event Grid will stamp onto the event.

  • subject (str) – Required. A resource path relative to the topic path.

  • data (object) – Event data specific to the event type.

  • event_type (str) – Required. The type of the event that occurred.

  • data_version (str) – The schema version of the data object. If not provided, will be stamped with an empty value.

  • id (Optional[str]) – Optional. An identifier for the event. The combination of id and source must be unique for each distinct event.

  • event_time (Optional[datetime]) – Optional.The time (in UTC) of the event. If not provided, it will be the time (in UTC) the event was generated.

Variables

metadata_version (str) – The schema version of the event metadata. If provided, must match Event Grid Schema exactly. If not provided, EventGrid will stamp onto event.

as_dict(keep_readonly=True, key_transformer=<function attribute_transformer>, **kwargs)

Return a dict that can be JSONify using json.dump.

Advanced usage might optionaly use a callback as parameter:

Key is the attribute name used in Python. Attr_desc is a dict of metadata. Currently contains ‘type’ with the msrest type and ‘key’ with the RestAPI encoded key. Value is the current value in this object.

The string returned will be used to serialize the key. If the return type is a list, this is considered hierarchical result dict.

See the three examples in this file:

  • attribute_transformer

  • full_restapi_key_transformer

  • last_restapi_key_transformer

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

key_transformer (function) – A key transformer function.

Returns

A dict JSON compatible object

Return type

dict

classmethod deserialize(data, content_type=None)

Parse a str using the RestAPI syntax and return a model.

Parameters
  • data (str) – A str using RestAPI structure. JSON by default.

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod enable_additional_properties_sending()
classmethod from_dict(data, key_extractors=None, content_type=None)

Parse a dict using given key extractor return a model.

By default consider key extractors (rest_key_case_insensitive_extractor, attribute_key_case_insensitive_extractor and last_rest_key_case_insensitive_extractor)

Parameters
  • data (dict) – A dict using RestAPI structure

  • content_type (str) – JSON by default, set application/xml if XML.

Returns

An instance of this model

Raises

DeserializationError if something went wrong

classmethod is_xml_model()
serialize(keep_readonly=False, **kwargs)

Return the JSON that would be sent to azure from this model.

This is an alias to as_dict(full_restapi_key_transformer, keep_readonly=False).

If you want XML serialization, you can pass the kwargs is_xml=True.

Parameters

keep_readonly (bool) – If you want to serialize the readonly attributes

Returns

A dict JSON compatible object

Return type

dict

validate()

Validate this model recursively and return a list of ValidationError.

Returns

A list of validation error

Return type

list

class azure.eventgrid.EventGridSharedAccessSignatureCredential(signature: str)[source]

Creates an instance of an EventGridSharedAccessSignatureCredential for use with a service client. :param str signature: Signature to use in authentication.

update(signature: str)None[source]

Updates the key property value of the signature to be used in authentication.

Parameters

signature (str) – Signature to use in authentication.

property signature

The value of the signature to be used in authentication.

Return type

str

azure.eventgrid.generate_shared_access_signature(topic_hostname: str, shared_access_key: str, expiration_date_utc: datetime.Datetime, **kwargs: Any)str[source]

Helper method to generate shared access signature given hostname, key, and expiration date. :param str topic_hostname: The topic endpoint to send the events to.

Similar to <YOUR-TOPIC-NAME>.<YOUR-REGION-NAME>-1.eventgrid.azure.net

Parameters
  • shared_access_key (str) – The shared access key to be used for generating the token

  • expiration_date_utc (datetime.datetime) – The expiration datetime in UTC for the signature.

  • api_version (str) – The API Version to include in the signature. If not provided, the default API version will be used.

Return type

str