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
+35-16Lines changed: 35 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -11,27 +11,13 @@ This utility provides data parsing and deep validation using [Pydantic](https://
11
11
* Defines data in pure Python classes, then parse, validate and extract only what you want
12
12
* Built-in envelopes to unwrap, extend, and validate popular event sources payloads
13
13
* Enforces type hints at runtime with user-friendly errors
14
-
* Support for Pydantic v1 and v2
14
+
* Support for Pydantic v2
15
15
16
16
## Getting started
17
17
18
18
### Install
19
19
20
-
Powertools for AWS Lambda (Python) supports Pydantic v1 and v2. Each Pydantic version requires different dependencies before you can use Parser.
21
-
22
-
#### Using Pydantic v1
23
-
24
-
!!! info "This is not necessary if you're installing Powertools for AWS Lambda (Python) via [Lambda Layer/SAR](../index.md#lambda-layer){target="_blank"}"
25
-
26
-
Add `aws-lambda-powertools[parser]` as a dependency in your preferred tool: _e.g._, _requirements.txt_, _pyproject.toml_.
27
-
28
-
???+ warning
29
-
This will increase the compressed package size by >10MB due to the Pydantic dependency.
30
-
31
-
To reduce the impact on the package size at the expense of 30%-50% of its performance [Pydantic can also be
32
-
installed without binary files](https://pydantic-docs.helpmanual.io/install/#performance-vs-package-size-trade-off){target="_blank" rel="nofollow"}:
Powertools for AWS Lambda (Python) supports Pydantic v2. Each Pydantic version requires different dependencies before you can use Parser.
35
21
36
22
#### Using Pydantic v2
37
23
@@ -169,6 +155,39 @@ def my_function():
169
155
}
170
156
```
171
157
158
+
#### Union parsing
159
+
160
+
You can parse multiple types using [`Union`](https://docs.pydantic.dev/latest/api/standard_library_types/#union), this gives you control over parsing different event types with the same handler based on an attribute, for example:
161
+
162
+
```python
163
+
from aws_lambda_powertools.utilities.parser import event_parser
0 commit comments