Resource container
General and abstract implementation for a resource container.
A resource container is a collection of resources returned by the StreamPipes API. It is capable of parsing the response content directly into a list of queried resources. Furthermore, the resource container makes them accessible in a pythonic manner.
ResourceContainer(resources)
¶
Bases: ABC
General and abstract implementation for a resource container.
A resource container is a collection of resources returned by the StreamPipes API. It is capable of parsing the response content directly into a list of queried resources. Furthermore, the resource container makes them accessible in a pythonic manner.
PARAMETER | DESCRIPTION |
---|---|
resources |
A list of resources to be contained in the
TYPE:
|
from_json(json_string)
classmethod
¶
Creates a ResourceContainer
from the given JSON string.
PARAMETER | DESCRIPTION |
---|---|
json_string |
The JSON string returned from the StreamPipes API.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
container
|
instance of the container derived from the JSON definition
TYPE:
|
RAISES | DESCRIPTION |
---|---|
StreamPipesDataModelError
|
If a resource cannot be mapped to the corresponding Python data model. |
StreamPipesResourceContainerJSONError
|
If JSON response cannot be parsed to a |
to_dicts(use_source_names=False)
¶
Returns the contained resources as list of dictionaries.
PARAMETER | DESCRIPTION |
---|---|
use_source_names |
Determines whether the field names are named in Python style (=
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dictionary_list
|
List of resources in dictionary representation.
If
TYPE:
|
to_json()
¶
Returns the resource container in the StreamPipes JSON representation.
RETURNS | DESCRIPTION |
---|---|
json_string: str
|
JSON representation of the resource container where key names are equal to keys used in the StreamPipes backend |
to_pandas()
¶
Returns the resource container in representation of a Pandas Dataframe.
RETURNS | DESCRIPTION |
---|---|
resource_container_df
|
Representation of the resource container as pandas DataFrame
TYPE:
|
StreamPipesDataModelError(validation_error)
¶
Bases: Exception
A custom exception to be raised when a validation error occurs during the parsing of StreamPipes API responses.
PARAMETER | DESCRIPTION |
---|---|
validation_error |
The validation error thrown by Pydantic during parsing.
TYPE:
|
StreamPipesResourceContainerJSONError(container_name, json_string)
¶
Bases: Exception
A custom exception to be raised when the returned JSON string does not suit to the structure of resource container.
PARAMETER | DESCRIPTION |
---|---|
container_name |
The class name of the resource container where the invalid data structure was detected.
TYPE:
|
json_string |
The JSON string that has been tried to parse.
TYPE:
|