Skip to content

Component Operations

Functions for creating and managing network components (buses, generators, loads, etc.).

create_component

python
create_component((conn: sqlite3.Connection, component_type: str, name: str, description: Optional[str] = None, longitude: Optional[float] = None, latitude: Optional[float] = None, carrier_id: Optional[int] = None, bus_id: Optional[int] = None, bus0_id: Optional[int] = None, bus1_id: Optional[int] = None) -> int)

Create a component and return its ID - convenience function (single network per database).

Parameters:

  • conn: Database connection
  • component_type: Type of component (e.g., "BUS", "GENERATOR")
  • name: Component name
  • description: Optional description
  • longitude: Optional longitude coordinate
  • latitude: Optional latitude coordinate
  • carrier_id: Optional carrier ID
  • bus_id: Optional bus ID (for single-bus components)
  • bus0_id: Optional first bus ID (for two-bus components)
  • bus1_id: Optional second bus ID (for two-bus components)

Returns:

ID of the newly created component

get_component

python
get_component((conn: sqlite3.Connection, component_id: int) -> pyconvexity.core.types.Component)

Get component by ID (single network per database).

Parameters:

  • conn: Database connection
  • component_id: ID of the component

Returns:

Component object with all fields populated

Raises:

  • ComponentNotFound: If component doesn't exist

update_component

python
update_component((conn: sqlite3.Connection, component_id: int, name: Optional[str] = None, description: Optional[str] = None, longitude: Optional[float] = None, latitude: Optional[float] = None, carrier_id: Optional[int] = None, bus_id: Optional[int] = None, bus0_id: Optional[int] = None, bus1_id: Optional[int] = None) -> None)

Update a component.

Parameters:

  • conn: Database connection
  • component_id: ID of component to update
  • name: New name (optional)
  • description: New description (optional)
  • longitude: New longitude (optional)
  • latitude: New latitude (optional)
  • carrier_id: New carrier ID (optional)
  • bus_id: New bus ID (optional)
  • bus0_id: New first bus ID (optional)
  • bus1_id: New second bus ID (optional)

Raises:

  • ComponentNotFound: If component doesn't exist

delete_component

python
delete_component((conn: sqlite3.Connection, component_id: int) -> None)

Delete a component and all its attributes.

Parameters:

  • conn: Database connection
  • component_id: ID of component to delete

Raises:

  • ComponentNotFound: If component doesn't exist

list_components_by_type

python
list_components_by_type((conn: sqlite3.Connection, component_type: Optional[str] = None) -> List[pyconvexity.core.types.Component])

List components by type (single network per database).

Parameters:

  • conn: Database connection
  • component_type: Optional component type filter (e.g., "BUS", "GENERATOR")

Returns:

List of Component objects

© Copyright 2025 Bayesian Energy