Lambda Powertools的Parser是否比纯Pydantic有优势?

huangapple go评论91阅读模式
英文:

Is there an advantage to Lambda Powertools’s Parser over straight Pydantic?

问题

我有继承Pydantic的BaseModel的模型,并使用它来定义我的模型属性并进行一些验证。

但我看到Lambda Powertools带有一个Parser模块,它使用了Pydantic。

现在,我想在AWS Lambda执行中使用这些模型,是否有以下好处:

from aws_lambda_powertools.utilities.parser import BaseModel

而不是继续使用我的现有:

from pydantic import BaseModel

我可以看到Powertools Parser带有一个有用的BaseEnvelope - 但Powertools中的BaseModel是否有任何不同?

作为后续问题,如果有好处,我是否可以在Lambda运行时进行monkey patch,以便我可以:

  1. 使我的模型独立于任何与Lambda相关的内容。
  2. 节省自己更改所有导入的工作。
英文:

I’ve got models which inherit Pydantic’s BaseModel and I use this to define my model attributes and do some validation.

But I see that Lambda Powertools comes with a Parser module which uses Pydantic.

Now that I want to use these models within an AWS lambda execution, is there a benefit to using:

from aws_lambda_powertools.utilities.parser import BaseModel

Instead of sticking with my existing

from pydantic import BaseModel

I can see that the Powertools Parser comes with a useful BaseEnvelope - but is BaseModel in Powertools any different?

And as a followup, if there is a benefit, could I monkey patch within the lambda runtime so I can:

  1. Keep my models independent of anything Lambda like.
  2. Spare myself from changing all the imports.

答案1

得分: 1

你不需要更新你的导入。AWS Lambda Powertools的BaseModel只是对Pydantic的BaseModel的重新导出。

英文:

You don't have to update your imports. AWS Lambda Powertools's BaseModel is just a re-export of Pydantic's BaseModel.

huangapple
  • 本文由 发表于 2023年1月9日 07:08:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/75051936.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定