Skip to content

Attributes

pyconvexity.models.attributes

Attribute management operations for PyConvexity.

Provides operations for setting, getting, and managing component attributes with support for both static values and timeseries data.

set_static_attribute(conn: sqlite3.Connection, component_id: int, attribute_name: str, value: StaticValue, scenario_id: Optional[int] = None) -> None

Set a static attribute value for a component in a specific scenario.

Parameters:

Name Type Description Default
conn Connection

Database connection

required
component_id int

Component ID

required
attribute_name str

Name of the attribute

required
value StaticValue

Static value to set

required
scenario_id Optional[int]

Scenario ID (uses master scenario if None)

None

Raises:

Type Description
ComponentNotFound

If component doesn't exist

ValidationError

If attribute doesn't allow static values or validation fails

set_timeseries_attribute(conn: sqlite3.Connection, component_id: int, attribute_name: str, timeseries: Union[Timeseries, List[float]], scenario_id: Optional[int] = None) -> None

Set a timeseries attribute value for a component in a specific scenario.

Parameters:

Name Type Description Default
conn Connection

Database connection

required
component_id int

Component ID

required
attribute_name str

Name of the attribute

required
timeseries Union[Timeseries, List[float]]

Timeseries object or list of float values

required
scenario_id Optional[int]

Scenario ID (uses master scenario if None)

None

Raises:

Type Description
ComponentNotFound

If component doesn't exist

ValidationError

If attribute doesn't allow timeseries values

TimeseriesError

If timeseries serialization fails

get_attribute(conn: sqlite3.Connection, component_id: int, attribute_name: str, scenario_id: Optional[int] = None) -> AttributeValue

Get an attribute value with scenario fallback logic.

Parameters:

Name Type Description Default
conn Connection

Database connection

required
component_id int

Component ID

required
attribute_name str

Name of the attribute

required
scenario_id Optional[int]

Scenario ID (uses master scenario if None)

None

Returns:

Type Description
AttributeValue

AttributeValue containing either static or timeseries data

Raises:

Type Description
ComponentNotFound

If component doesn't exist

AttributeNotFound

If attribute doesn't exist

delete_attribute(conn: sqlite3.Connection, component_id: int, attribute_name: str, scenario_id: Optional[int] = None) -> None

Delete an attribute from a specific scenario.

Parameters:

Name Type Description Default
conn Connection

Database connection

required
component_id int

Component ID

required
attribute_name str

Name of the attribute

required
scenario_id Optional[int]

Scenario ID (uses master scenario if None)

None

Raises:

Type Description
AttributeNotFound

If attribute doesn't exist

serialize_values_to_binary(values: List[float]) -> bytes

Serialize f32 values to binary format - EXACT MATCH WITH RUST.

Ultra-fast binary format: just raw Float32 array, little-endian.

deserialize_values_from_binary(data: bytes) -> List[float]

Deserialize f32 values from binary format - EXACT MATCH WITH RUST.

Ultra-fast deserialization: read raw Float32 values only.

get_timeseries_length_from_binary(data: bytes) -> int

Get the length of a timeseries without deserializing the full data.

get_timeseries(conn: sqlite3.Connection, component_id: int, attribute_name: str, scenario_id: Optional[int] = None, start_index: Optional[int] = None, end_index: Optional[int] = None, max_points: Optional[int] = None) -> Timeseries

Get timeseries data with unified interface matching Rust implementation.

Parameters:

Name Type Description Default
conn Connection

Database connection

required
component_id int

Component ID

required
attribute_name str

Name of the attribute

required
scenario_id Optional[int]

Scenario ID (uses master scenario if None)

None
start_index Optional[int]

Start index for range queries

None
end_index Optional[int]

End index for range queries

None
max_points Optional[int]

Maximum number of points (for sampling)

None

Returns:

Type Description
Timeseries

Timeseries object with efficient array-based data

Raises:

Type Description
ComponentNotFound

If component doesn't exist

AttributeNotFound

If attribute doesn't exist

get_timeseries_metadata(conn: sqlite3.Connection, component_id: int, attribute_name: str, scenario_id: Optional[int] = None) -> TimeseriesMetadata

Get timeseries metadata without loading the full data.

Parameters:

Name Type Description Default
conn Connection

Database connection

required
component_id int

Component ID

required
attribute_name str

Name of the attribute

required
scenario_id Optional[int]

Scenario ID (uses master scenario if None)

None

Returns:

Type Description
TimeseriesMetadata

TimeseriesMetadata with length and type information