The issue is I need to parse a string line delimited by spaces (but not exactly) into a Pydantic model. The field names are known and types for this task are not important, so keeping str
is fine.
I’m unfamiliar with Pydantic, but I assume there is a way to leverage the BaseModel.model_validate
method or similar to make the parsing more natively.
For the sake of example I trimmed the log and model!
Example log file:
<code>79a59df900b949e55d DOC-EXAMPLE-BUCKET1 [06/Feb/2019:00:00:38 +0000]
</code>
<code>79a59df900b949e55d DOC-EXAMPLE-BUCKET1 [06/Feb/2019:00:00:38 +0000]
</code>
79a59df900b949e55d DOC-EXAMPLE-BUCKET1 [06/Feb/2019:00:00:38 +0000]
The model:
<code>class S3AccessLogEntry(BaseModel):
owner: str
bucket: str
timestamp: str
</code>
<code>class S3AccessLogEntry(BaseModel):
owner: str
bucket: str
timestamp: str
</code>
class S3AccessLogEntry(BaseModel):
owner: str
bucket: str
timestamp: str