11# digital-letters-events
22
3+ <!-- vale Vale.Avoid = NO -->
4+ <!-- vale Vale.Terms = NO -->
35This package contains the automatically-generated code that the
4- [ typescript-schema-generator] ( ../typescript-schema-generator/ ) tool produces.
6+ [ typescript-schema-generator] ( ../typescript-schema-generator/ ) and the
7+ [ python-schema-generator] ( ../python-schema-generator/ ) tools produce.
8+ <!-- vale Vale.Avoid = YES -->
9+ <!-- vale Vale.Terms = YES -->
510
611The source files in this package should not be edited directly. If changes are
712required, update the schemas in the
813[ src/cloudevents/domains] ( ../cloudevents/domains ) directory and use the
9- ` typescript-schema-generator ` tool to regenerate them.
14+ ` typescript-schema-generator ` and ` python-schema-generator ` tools to regenerate
15+ them.
1016
1117## Using this Package
1218
13- ### Using Event Types
19+ ### TypeScript
20+
21+ #### Using Event Types
1422
1523The event types can be used by simply installing the
1624` digital-letters-events ` package as a dependency and then importing
@@ -51,7 +59,7 @@ const pdmResourceSubmittedEvent: PDMResourceSubmitted = {
5159 };
5260```
5361
54- ### Using Event Validator Functions
62+ #### Using Event Validator Functions
5563
5664Validator functions for an event can be used by importing the default export
5765from the relevant JS file in
@@ -74,3 +82,54 @@ if (isEventValid) {
7482Note: You will need to make sure the
7583[ ` allowJs ` ] ( https://www.typescriptlang.org/tsconfig/#allowJs ) option is set in
7684your package's ` tsconfig.json ` in order to import the JS files.
85+
86+ ### Python
87+
88+ #### Using Event Models
89+
90+ The Pydantic models can be used by installing the ` digital-letters-events ` package and importing the desired model:
91+
92+ ``` python
93+ from digital_letters_events import PDMResourceSubmitted
94+
95+ try :
96+ # Validate and parse an event
97+ event_data = {
98+ " type" : " uk.nhs.notify.digital.letters.pdm.resource.submitted.v1" ,
99+ " source" : " /nhs/england/notify/staging/dev-647563337/data-plane/digitalletters/pdm" ,
100+ " dataschema" : " https://notify.nhs.uk/cloudevents/schemas/digital-letters/2025-10-draft/data/digital-letters-pdm-resource-submitted-data.schema.json" ,
101+ " specversion" : " 1.0" ,
102+ " id" : " 0249e529-f947-4012-819e-b634eb71be79" ,
103+ " subject" : " customer/7ff8ed41-cd5f-20e4-ef4e-34f96d8cc8ac/75027ace-9b8c-bcfe-866e-6c24242cffc3/q58dnxk5e/4cbek805wwx/yiaw7bl0d/her/1ccb7eb8-c6fe-0a42-279a-2a0e48ff1ca9/zk" ,
104+ " time" : " 2025-11-21T16:01:52.268Z" ,
105+ " datacontenttype" : " application/json" ,
106+ " traceparent" : " 00-ee4790eb6821064c645406abe918b3da-3a4e6957ce2a15de-01" ,
107+ " tracestate" : " nisi quis" ,
108+ " partitionkey" : " customer-7ff8ed41" ,
109+ " recordedtime" : " 2025-11-21T16:01:53.268Z" ,
110+ " sampledrate" : 1 ,
111+ " sequence" : " 00000000000350773861" ,
112+ " severitytext" : " INFO" ,
113+ " severitynumber" : 2 ,
114+ " dataclassification" : " restricted" ,
115+ " dataregulation" : " ISO-27001" ,
116+ " datacategory" : " non-sensitive" ,
117+ " data" : {
118+ " messageReference" : " incididunt Ut aute laborum" ,
119+ " senderId" : " officia voluptate culpa Ut dolor" ,
120+ " resourceId" : " a2bcbb42-ab7e-42b6-88d6-74f8d3ca4a09" ,
121+ " retryCount" : 97_903_257 ,
122+ },
123+ }
124+
125+ # Create and validate the event
126+ event = PDMResourceSubmitted(** event_data)
127+
128+ # Access validated fields
129+ print (event.id)
130+ print (event.type)
131+ print (event.data.messageReference)
132+ except Exception as e:
133+ print (e)
134+ raise ValueError (" Error processing event" ) from e
135+ ```
0 commit comments