API-Reference¶
Version: 0.16.1
client.py¶
The core module provides access to the WDC-API. It provides a consistent interface for handling the data as JSON, DataFrame or Graph and transparently handles paging for large result-sets.
- class dsslab.wdc_client.client.WDCClient(host: str, token=None)¶
Client for the WDC-API.
- createDomainGraph(nodes, edges) DiGraph¶
Create a DiGraph from a list of nodes and a list of edges.
:param nodes a JSON-Object or a DataFrame :param edges a JSON-Object or a DataFrame
:return the created DiGraph.
- findDomainGraphId(snapshot: str, selection: str | None = None, variant: str = 'ONLY_SEEDS')¶
Finds the DomainGraphId of the specified Graph.
- Parameters:
snapshot – The machineName of the snapshot.
selection – A selection of the snapshot.
variant – A value of an enumeration of the variant of the DomainGraph.
- Returns:
the ID of the specified DomainGraph.
- static fromEnv()¶
Creates a WDCClient from the ‘Environment’.
Uses the environment variables ‘WDC_HOST’ and ‘WDC_TOKEN’ from the current environment. Thus, you can make use of modules such as python-dotenv or other variants more easily.
If the WDC_HOST has not been previously set, the method tries to load the configuration from “~/.wdc”. This allows a easy central setup for the configuration without the risk of exposing the config-file in a git-/cloud-repository.
Remember: Using passwords or tokens in source code is dangerous!
- Returns:
A new WDCClient configured from the environment values.
- loadAsDF(endpoint: str, **params) DataFrame¶
Short-Cut for loadAsDataFrame with keyword arguments to specify the parameters for the endpoint. Same as calling self.loadAsDataFrame(endpoint, params)
- loadAsDataFrame(endpoint: str, params: dict[str, Any] = {}) DataFrame¶
Loads the complete tabular data from the endpoint and returns a Pandas-DataFrame. The method transparently pages through the complete results.
- Parameters:
endpoint – the endpoint
params – a dictionary with possible parameters for the query-string of the request. Values will be properly encoded. A param named ‘body’ will be sent as BODY in a GET-Request.
- Returns:
the data as Pands-DataFrame
- loadAsJson(endpoint: str, params: dict[str, Any] = {}) []¶
Loads the tabular data from the endpoint and returns it as JSON-Array. The method transparently pages through the complete results.
- Parameters:
endpoint – the endpoint
params – a dictionary with possible parameters for the query-string of the request. Values will be properly encoded.
- Returns:
the data as JSON-Array
- loadDomainGraph(snapshot: str, selection: str | None = None, variant: str = 'ONLY_SEEDS') DiGraph¶
Loads a DomainGraph as a DiGraph.
Note: If you intend to “merge” other data to nodes or edges, it might be simpler to use the methods loadDomainGraphNodes() and lodDomainGraphEdges() to load the data, modify it and create the graph with createGraph().
- Parameters:
snapshot – The machineName of the snapshot.
selection – A selection of the snapshot.
variant – A value of an enumeration of the variant of the DomainGraph.
- Returns:
DiGraph of the DomainGraph
- loadDomainGraphData(snapshot: str, selection: str | None = None, variant: str = 'ONLY_SEEDS')¶
Convienence method load the nodes and edges of a DomainGraph.
- Returns:
a tuple of (nodes, edges) as JSON.
- loadForEach(endpoint: str, params: dict[str, Any] = {}, f: Callable[[Any, int, int], None] | None = None) None¶
Provides the means to work on larger resultsets by providing a Callback.
- Parameters:
endpoint – the endpoint
params – a dictionary with possible parameters for the query-string of the request. Values will be properly encoded.
f – a Callable-Object (function, …) with the signature (row, currentPos, maxPos) as a callback to work on each entry in the dataset.
- put(endpoint: str, body: str, params: dict[str, Any] = {}) None¶
Executes a PUT request to the specified endpoint with a body. Raises a WDCException if the response is not “OK”.
- Parameters:
endpoint – the endpoint
body – the body to send with the PUT-Request
- exception dsslab.wdc_client.client.WDCException(message, query=None, state=None)¶
An exception which is raised when an error within the WDCClient occurs.