Skip to main content

Overview

The Network module provides the core functionality for working with power system networks in PyPowSyBl. It includes the main Network class for representing and manipulating power networks, as well as utilities for loading networks from files, creating test networks, and accessing network data.

Network Class

The Network class represents a power system network and provides methods for accessing and modifying network data.

Constructor

The Network class is typically not instantiated directly. Instead, use one of the factory functions like load() or create_empty().

Properties

id
str
The unique identifier of the network
name
str
The name of the network
source_format
str
The format of the source file from which the network was loaded (e.g., ‘XIIDM’, ‘UCTE’)
case_date
datetime.datetime
The date of the network case, in UTC timezone
forecast_distance
datetime.timedelta
The forecast distance (0 for a snapshot)
nominal_apparent_power
float
The nominal power used to convert the network to per-unit (in kVA). Default is 100.0
per_unit
bool
Whether the network data should be used in per-unit representation. Default is False

Key Methods

save

Save a network to a file using the specified format.
network.save(
    file: str,
    format: str = 'XIIDM',
    parameters: dict = None,
    report_node: ReportNode = None
)
file
str
required
Path to the exported file
format
str
default:"XIIDM"
Format to save the network (e.g., ‘XIIDM’, ‘UCTE’)
parameters
dict
A dictionary of export parameters
report_node
ReportNode
Reporter for creating an execution report
return
None
This method does not return a value
Example:
import pypowsybl as pp

network = pp.network.load('network.xiidm')
network.save('output.xiidm')
network.save('output.xiidm.gz')  # produces a gzipped file
network.save('output.uct', format='UCTE')

connect / disconnect

Connect or disconnect a network element.
network.connect(id: str) -> bool
network.disconnect(id: str) -> bool
id
str
required
The ID of the element to connect or disconnect
return
bool
True if the operation was successful

open_switch / close_switch

Open or close a switch.
network.open_switch(id: str) -> bool
network.close_switch(id: str) -> bool
id
str
required
The ID of the switch
return
bool
True if the operation was successful

reduce_by_voltage_range

Reduce the network to a smaller network by voltage range.
network.reduce_by_voltage_range(
    v_min: float = 0,
    v_max: float = float('inf'),
    with_dangling_lines: bool = False
)
v_min
float
default:"0"
Minimum voltage of the voltage levels kept after reducing (in kV)
v_max
float
default:"inf"
Maximum voltage of the voltage levels kept after reducing (in kV)
with_dangling_lines
bool
default:"False"
Whether dangling lines should be created to replace lines cut at the boundary of reduction

Loading Networks

load

Load a network from a file.
pp.network.load(
    file: str,
    parameters: dict = None,
    post_processors: list = None,
    report_node: ReportNode = None,
    allow_variant_multi_thread_access: bool = False
) -> Network
file
str
required
Path to the network file. Supported formats include XIIDM, UCTE, and more. Compression formats (gzip, bzip2) are also supported
parameters
dict
A dictionary of import parameters specific to the file format
post_processors
list
A list of import post-processors to apply after loading
report_node
ReportNode
Reporter for creating an execution report
allow_variant_multi_thread_access
bool
default:"False"
Allow multi-thread access to network variants
return
Network
The loaded network object
Example:
import pypowsybl as pp

# Load from various file formats
network = pp.network.load('network.xiidm')
network = pp.network.load('/path/to/network.xiidm')
network = pp.network.load('network.xiidm.gz')
network = pp.network.load('network.uct')

is_loadable

Check if a file is a loadable network.
pp.network.is_loadable(file: str) -> bool
file
str
required
Path to the file to check
return
bool
True if the file is a loadable network, False otherwise

Creating Networks

create_empty

Create an empty network.
pp.network.create_empty(
    network_id: str = "Default",
    allow_variant_multi_thread_access: bool = False
) -> Network
network_id
str
default:"Default"
ID of the network
allow_variant_multi_thread_access
bool
default:"False"
Allow multi-thread access to network variants
return
Network
A new empty network

IEEE Test Networks

Create standard IEEE test networks:
pp.network.create_ieee9() -> Network
pp.network.create_ieee14() -> Network
pp.network.create_ieee30() -> Network
pp.network.create_ieee57() -> Network
pp.network.create_ieee118() -> Network
pp.network.create_ieee300() -> Network
Example:
import pypowsybl as pp

# Create IEEE 14-bus test network
network = pp.network.create_ieee14()
print(network.id)
print(network.name)

Other Test Networks

# Create Eurostag tutorial example 1 network
pp.network.create_eurostag_tutorial_example1_network() -> Network

# Create four substations node breaker network
pp.network.create_four_substations_node_breaker_network() -> Network

# Create micro grid BE network
pp.network.create_micro_grid_be_network() -> Network

# Create micro grid NL network
pp.network.create_micro_grid_nl_network() -> Network

Utility Functions

get_import_formats

Get the list of supported import formats.
pp.network.get_import_formats() -> list
return
list
List of supported import format names

get_export_formats

Get the list of supported export formats.
pp.network.get_export_formats() -> list
return
list
List of supported export format names

get_import_parameters

Get the import parameters for a specific format.
pp.network.get_import_parameters(format: str) -> DataFrame
format
str
required
The import format name
return
DataFrame
DataFrame containing the available import parameters for the specified format

Enumerations

ElementType

Enumeration of network element types:
  • NETWORK
  • SUBSTATION
  • VOLTAGE_LEVEL
  • GENERATOR
  • LOAD
  • BUS
  • LINE
  • TWO_WINDINGS_TRANSFORMER
  • THREE_WINDINGS_TRANSFORMER
  • And more…

ValidationLevel

Enumeration of validation levels:
  • STEADY_STATE_HYPOTHESIS
  • EQUIPMENT

See Also

Build docs developers (and LLMs) love