Skip to content

pd_cds_api.wrapper

pd_cds_api.wrapper

Query execution: invoke the native Frontier client as a subprocess.

:class:ApiClientWrapper turns a :class:~pd_cds_api.conditions.RunConditions plus an :class:~pd_cds_api.state.ApiClientState into one fn-fileget invocation (or one batched invocation for several conditions).

pd_cds_api.wrapper.ApiClientWrapper

Executes conditions queries through the bundled native client.

Each public method spawns a single fn-fileget process with an argv list (no shell involved). The wrapper itself is cheap: construct one per query (or per batch) and share an :class:~pd_cds_api.state.ApiClientState freely across instances.

_query_string cached property

conditions = conditions instance-attribute

state = state or ApiClientState() instance-attribute

__init__(conditions, state=None)

Bind query parameters and configuration (see the class docstring).

_build_query(conditions, state) staticmethod

_invoke(state, queries) staticmethod

_move_data(query_string)

get_data()

Fetch and store this wrapper's conditions under pd-cds-data/.

Performs :meth:run_query, then moves the payload file the native client wrote into the current working directory to pd-cds-data/<folder>-t_<t0>.<format> (or ...-t0_<t0>-t1_<t1>.<format> for range queries).

Returns:

Name Type Description
The CompletedProcess[str]

class:subprocess.CompletedProcess of the move step, with

CompletedProcess[str]

stdout set to "Conditions data written to: <file>".

Raises:

Type Description
FileNotFoundError

The native runtime is not installed/staged.

CalledProcessError

The fetch or the move failed.

run_queries(conditions, state=None) classmethod

Fetch several conditions in one native-client process.

All queries share one process, one connection, and the TTL configured on state; the native client stops at the first failed query, so a non-zero exit can mean partial success (earlier payloads are already on disk).

Parameters:

Name Type Description Default
conditions Sequence[RunConditions]

Queries to execute, in order.

required
state ApiClientState | None

Shared configuration; defaults to ApiClientState().

None

Returns:

Type Description
CompletedProcess[str]

The combined :class:subprocess.CompletedProcess; its stdout has

CompletedProcess[str]

one "N bytes written to ..." line per completed query.

Raises:

Type Description
FileNotFoundError

The native runtime is not installed/staged.

CalledProcessError

Any query failed (see :attr:CompletedProcess.stdout for those that succeeded).

run_query()

Fetch this wrapper's conditions with one native-client call.

Returns:

Type Description
CompletedProcess[str]

The raw :class:subprocess.CompletedProcess of fn-fileget.

CompletedProcess[str]

Its stdout reports the payload byte count; the CSV/JSON payload

CompletedProcess[str]

itself is written by the native client into the current working

CompletedProcess[str]

directory under a file named after the query string

CompletedProcess[str]

(get?folder=...). Use :meth:get_data to fetch and relocate

CompletedProcess[str]

that file in one step.

Raises:

Type Description
FileNotFoundError

The native runtime is not installed/staged (see :attr:~pd_cds_api.state.ApiClientState.frontier_client_path).

CalledProcessError

The client exited non-zero (server/proxy unreachable, malformed query, etc.).

Example

from pd_cds_api import ApiClientWrapper, RunConditions

wrapper = ApiClientWrapper( conditions=RunConditions(folder="pdunesp.run_conditionstest", t0=25034) ) print(wrapper.run_query().stdout)