You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/utilities/parser.md
+20-14Lines changed: 20 additions & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Parser
2
+
title: Parser (Pydantic)
3
3
description: Utility
4
4
---
5
5
<!-- markdownlint-disable MD043 -->
@@ -25,7 +25,11 @@ This utility provides data parsing and deep validation using [Pydantic](https://
25
25
26
26
Install parser's extra dependencies using **`pip install aws-lambda-powertools[pydantic]`**.
27
27
28
-
## Defining models
28
+
## Getting started
29
+
30
+
### Install
31
+
32
+
### Defining models
29
33
30
34
You can define models to parse incoming events by inheriting from `BaseModel`.
31
35
@@ -47,11 +51,11 @@ class Order(BaseModel):
47
51
48
52
These are simply Python classes that inherit from BaseModel. **Parser** enforces type hints declared in your model at runtime.
49
53
50
-
## Parsing events
54
+
###Parsing events
51
55
52
56
You can parse inbound events using **event_parser** decorator, or the standalone `parse` function. Both are also able to parse either dictionary or JSON string as an input.
53
57
54
-
### event_parser decorator
58
+
####event_parser decorator
55
59
56
60
Use the decorator for fail fast scenarios where you want your Lambda function to raise an exception in the event of a malformed payload.
`root_validator` can help when you have a complex validation mechanism. For example finding whether data has been omitted, comparing field values, etc.
You can read more about validating list items, reusing validators, validating raw inputs, and a lot more in <ahref="https://pydantic-docs.helpmanual.io/usage/validators/">Pydantic's documentation</a>.
472
478
473
-
## Advanced use cases
479
+
###Advanced use cases
474
480
475
481
???+ tip "Tip: Looking to auto-generate models from JSON, YAML, JSON Schemas, OpenApi, etc?"
476
482
Use Koudai Aono's [data model code generation tool for Pydantic](https://github.com/koxudaxi/datamodel-code-generator)
0 commit comments