Package: drb-impl-odata
OData implementationThis drb-impl-odata module implements the OData protocol access
following the Copernicus Space Component schema with DRB
data model. It is able to navigate among Product entities of a OData
service.NodesODataServiceNodeRepresents the OData service. This node has no attribute and
has as children Product entities of the service defined byProductNode.
A specificProductNodecan be retrieved during the bracket and
slash navigation by hisName(str) or by hisId(UUID).OData services required can be access using the second (optional)
parameterauthofODataServiceNode, this parameter must be anrequests.auth.AuthBaseobject, seerequests documentationfor more details.ODataProductNodeRepresents aProductentity of the OData service. This
node has as attribute properties of the associated entity and has
for unique child aProductAttributeNodeODataProductAttributeNodeThis node allowing to represent the navigation link between theProductentity and its attributes. It has no attribute and has as
childrenAttributeentities associated to theProductentity,
defined byAttributeNodeODataAttributeNodeRepresents anAttributeentity. This node has no child and has as
attribute properties associated to theAttributeentity.PredicateODataCustomQueryThis predicate allows to retrieve a specific subset of children of anODataServiceNode.Cache set upSome cache has been implemented to limit the number of requests to the server.
These cache evicts cache entries based on both time and space.
the time and the cache size can be changed by adding these two variables to the runtime environment.DRB_ODATA_NODE_REQUEST_CACHE_EXPIRE_TIME_SEC=120DRB_ODATA_NODE_REQUEST_CACHE_MAX_ELEMENTS=32Here are all the queries that use a cachedef req_svc(odata: OdataNode) -> dict:
def req_svc_products(odata: OdataNode, **kwargs) -> list:
def req_product_by_uuid(odata: OdataNode, prd_uuid: str) -> dict:
def req_product_attributes(odata: OdataNode, prd_uuid: str) -> List[dict]:The time of the cache eviction can be change by callingreset_cache_expiration_time(sec=1):req_svc_products.reset_expiration_time(sec=1)Installationpip install drb-impl-odataExamplesfromuuidimportUUIDfromrequests.authimportHTTPBasicAuthfromdrb_impl_odataimportODataServiceNode,\ODataProductNode,ODataAttributeNode,ODataQueryPredicate# generate ODataServiceNode without authenticationodata=ODataServiceNode('https://my.csc.odata.com')# generate ODataServiceNode with authentication mechanismodata=ODataServiceNode('https://my.csc.odata.com',auth=HTTPBasicAuth('usr','pwd'))# total number of childrenproduct_count=len(odata)# retrieve first ODataProductNodenode_idx=odata[0]# retrieve last ODataProductNodenode_idx=odata[-1]# retrieve 10 first productsproducts=odata.children[:10]# retrieve Product by namename='S2B_OPER_MSI_L0__GR_EPAE_..._D05_N02.06.tar'node_name_list=odata[name]# returns a listnode_name=odata[name]# returns first occurrence of the list# retrieve Product by UUIDuuid=UUID('0723d9bf-02a2-3e99-b1b3-f6d81de84b62')node_uuid=odata[uuid]# get product attributesprd_node=odata[uuid]attr_node=prd_node['Attributes']['Footprint']attr_type=attr_node.get_attribute('ValueType')attr_value=attr_node.value# filter and order productsfiltered_children=odata/ODataQueryPredicate(filter="startswith(Name,'S1')",order="ContentLength desc")The same example with DHus catalog (https://scihub.copernicus.eu/dhus/odata/v2)The only change is# get product attributes# For DhuS ValueType not exist in Attributes...attr_type=attr_node.get_attribute('ContentType')A similar example with ONDA-DIAS catalog (https://catalogue.onda-dias.eu/dias-catalogue)importuuidfromdrb_impl_odataimportODataServiceNode,ODataQueryPredicatesvc_url='https://catalogue.onda-dias.eu/dias-catalogue'# generate ODataServiceNode without authenticationodata=ODataServiceNode(svc_url)# retrieve Product by UUIDuuid_node=uuid.UUID('34a0a4ed-0246-4a57-827d-70350b96d03d')node_uuid=odata[uuid_node]attr_node=node_uuid['Attributes']children=attr_node.childrenfoot_print=node_uuid.get_attribute('footprint')print(foot_print)print(attr_node['Online quality check'].value)# search by product type limited two the 2 first resultfiltered_children=odata/ODataQueryPredicate(search='"(platformName:Sentinel-2) AND (productType:S2MSI2A)"',top="2")