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
feat(parser): Allow primitive data types to be parsed using TypeAdapter (aws-powertools#4502)
* feat(parser): allow union types
* change validation method in the parser
* test test
* fix tests
* fixes exception handling in parse
* annotations fix
* add some docs for unions
* move to generics for parser
* split docs example out
* split docs example out
* docs
* typo
* update docstrings
* Update docs/utilities/parser.md
Co-authored-by: Leandro Damascena <lcdama@amazon.pt>
Signed-off-by: Simon Thulbourn <sthulb@users.noreply.github.com>
* update doc string
* add cache to parser to improve perf
* fix types in the test
* Final adjusts
* Making mypy happy
* Making pytest happy
* Addressing Heitor's feedback
---------
Signed-off-by: Simon Thulbourn <sthulb@users.noreply.github.com>
Co-authored-by: Leandro Damascena <lcdama@amazon.pt>
Copy file name to clipboardExpand all lines: docs/utilities/parser.md
+10-16
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.
35
21
36
22
#### Using Pydantic v2
37
23
@@ -169,6 +155,14 @@ def my_function():
169
155
}
170
156
```
171
157
158
+
#### Primitive data model parsing
159
+
160
+
The parser allows you parse events into primitive data types, such as `dict` or classes that don't inherit from `BaseModel`. The following example shows you how to parse a [`Union`](https://docs.pydantic.dev/latest/api/standard_library_types/#union):
0 commit comments