Parsers¶
Warning
This step is optional and is required only if the related API does not return JSON format.
Some API does not follow any standard and it can be complex to deal with its content. Thus, you might need to build some parsers to make the response stick to the model you described for the API
Parser structure¶
Parsers are build on the model previously described for your API. An abstract class is available to give you the main lines to build your parser:
Base with abstract classes for all parsers.
-
class
dabeplech.parsers.base.
BaseListParser
(content_response)[source]¶ Bases:
abc.ABC
Base structure for parsers.
-
__init__
(content_response)[source]¶ Instantiate your parser on the response.
- Parameters
content_response – content response from the API
-
model
¶ alias of
pydantic.main.BaseModel
-
property
validated_model
¶ Retrieve entry validated with the model.
- Returns
Validated entry.
- Return type
BaseModel
-
-
class
dabeplech.parsers.base.
BaseParser
(content_response)[source]¶ Bases:
abc.ABC
Base structure for parsers.
-
__init__
(content_response)[source]¶ Instantiate your parser on the response.
- Parameters
content_response – content response from the API
-
model
¶ alias of
pydantic.main.BaseModel
-
property
validated_entry
¶ Retrieve entry validated with the model.
- Returns
Validated entry.
- Return type
BaseModel
-
Note
We are aware that some API needs more specific and complex parsing, but the idea
is to be perform parsing with the parse
method and obtain the validated
data with validated_entry
property.
Test your parser¶
You can add your unit tests for your parser within /tests/dabeplech/parsers
directory.
You can have a look at the tests for kegg to help you build your own tests.