pipolars.PIClient¶
- class pipolars.PIClient[source]¶
Bases:
objectMain client for extracting PI System data as Polars DataFrames.
This is the primary interface for the PIPolars library. It provides a high-level API for querying PI Points, AF Attributes, and Event Frames, returning data as Polars DataFrames.
Example
>>> # Connect to PI Server >>> with PIClient("my-pi-server") as client: ... # Get recorded values as DataFrame ... df = client.recorded_values("SINUSOID", start="*-1d", end="*") ... print(df) ... ... # Get multiple tags at once ... df = client.recorded_values( ... ["TAG1", "TAG2", "TAG3"], ... start="*-1h", ... end="*" ... ) ... ... # Get summary statistics ... summaries = client.summaries( ... "SINUSOID", ... start="*-7d", ... end="*", ... summary_types=[SummaryType.AVERAGE, SummaryType.MAXIMUM] ... )
>>> # Using configuration >>> config = PIConfig( ... server=PIServerConfig(host="my-pi-server"), ... cache=CacheConfig(backend=CacheBackend.SQLITE), ... ) >>> client = PIClient(config=config)
- __init__(server=None, config=None, enable_cache=True)[source]¶
Initialize the PI client.
- Parameters:
server (str | PIServerConfig | None) – PI Server hostname or configuration
config (PIConfig | None) – Full PIPolars configuration
enable_cache (bool) – Whether to enable caching
Methods
__init__([server, config, enable_cache])Initialize the PI client.
Get cache statistics.
Clear all cached data.
connect()Connect to the PI Server.
Disconnect from the PI Server.
interpolated_values(tags, start, end[, ...])Get interpolated values at regular intervals.
last(tags[, hours, days, minutes])Get recorded values for the last N hours/days/minutes.
plot_values(tag, start, end[, intervals, ...])Get values optimized for plotting.
query(tags)Create a query builder for the specified tags.
recorded_values(tags, start, end[, ...])Get recorded values for one or more tags.
search_tags(pattern[, max_results])Search for PI Points matching a pattern.
snapshot(tag)Get the current snapshot value for a tag.
snapshots(tags)Get current snapshot values for multiple tags.
summaries(tag, start, end, interval[, ...])Get summary statistics over multiple intervals.
summary(tags, start, end[, summary_types])Get summary statistics for one or more tags.
tag_exists(tag)Check if a tag exists.
tag_info(tag)Get metadata for a tag.
today(tags, **kwargs)Get recorded values for today.
Attributes
Get the client configuration.
Check if connected to PI Server.
Get the connected server name.
- __init__(server=None, config=None, enable_cache=True)[source]¶
Initialize the PI client.
- Parameters:
server (str | PIServerConfig | None) – PI Server hostname or configuration
config (PIConfig | None) – Full PIPolars configuration
enable_cache (bool) – Whether to enable caching
- query(tags)[source]¶
Create a query builder for the specified tags.
- Parameters:
tags (str | list[str]) – Single tag or list of tags to query
- Returns:
PIQuery builder for method chaining
- Return type:
Example
>>> df = client.query("SINUSOID") \ ... .time_range("*-1d", "*") \ ... .recorded() \ ... .to_dataframe()
- snapshot(tag)[source]¶
Get the current snapshot value for a tag.
- Parameters:
tag (str) – PI Point name
- Returns:
DataFrame with single row containing current value
- Return type:
DataFrame
- recorded_values(tags, start, end, max_count=0, include_quality=False, pivot=False)[source]¶
Get recorded values for one or more tags.
- Parameters:
start (PITimestamp) – Start time
end (PITimestamp) – End time
max_count (int) – Maximum values per tag (0 = no limit)
include_quality (bool) – Include quality column
pivot (bool) – Pivot to wide format (tags as columns)
- Returns:
DataFrame with recorded values
- Return type:
pl.DataFrame
- interpolated_values(tags, start, end, interval='1h', include_quality=False, pivot=False)[source]¶
Get interpolated values at regular intervals.
- Parameters:
start (PITimestamp) – Start time
end (PITimestamp) – End time
interval (str) – Time interval (e.g., “1h”, “15m”, “1d”)
include_quality (bool) – Include quality column
pivot (bool) – Pivot to wide format
- Returns:
DataFrame with interpolated values
- Return type:
pl.DataFrame
- plot_values(tag, start, end, intervals=640, include_quality=False)[source]¶
Get values optimized for plotting.
- Parameters:
tag (str) – PI Point name
start (PITimestamp) – Start time
end (PITimestamp) – End time
intervals (int) – Number of intervals
include_quality (bool) – Include quality column
- Returns:
DataFrame with plot-optimized values
- Return type:
pl.DataFrame
- summary(tags, start, end, summary_types=SummaryType.AVERAGE)[source]¶
Get summary statistics for one or more tags.
- Parameters:
start (PITimestamp) – Start time
end (PITimestamp) – End time
summary_types (SummaryType | list[SummaryType]) – Summary type(s) to calculate
- Returns:
DataFrame with summary statistics
- Return type:
pl.DataFrame
- summaries(tag, start, end, interval, summary_types=SummaryType.AVERAGE)[source]¶
Get summary statistics over multiple intervals.
- Parameters:
tag (str) – PI Point name
start (PITimestamp) – Start time
end (PITimestamp) – End time
interval (str) – Interval for each summary
summary_types (SummaryType | list[SummaryType]) – Summary type(s) to calculate
- Returns:
DataFrame with time-series summary statistics
- Return type:
pl.DataFrame