Skip to content

The Python API

James Dunkerley edited this page Nov 20, 2026 · 3 revisions

Home · Architecture · Backend core

In short

  • tz_ps_conductor exports Project, Network and ComponentHandle.
  • A notebook or script calls them directly, and the HTTP routes call the same objects.
  • Project owns every operation that names a network, Network wraps one network and its version, and ComponentHandle edits one component.
  • They sit over the plain models of the domain model.

Project

Project owns every operation that names a network:

  • create, read, save, copy, rename and delete;
  • version history: list_versions, compare_versions, restore_version;
  • series reads and writes;
  • the partial edits: update_components, update_timesteps, update_constraints, and the like;
  • results;
  • file import and export.

Project.create, Project.get and Project.list_projects pull the warehouse from the composition root.

Object or record. A plain name answers an object to act on. The _record name answers the stored, frozen value without building a model.

  • On Project the pair is get_network and get_network_record.
  • For projects themselves the record reads are on ProjectFactory: list_project_records and get_project_record, beside its list_projects and get.

Network

  • It wraps a NetworkModel and the VersionInfo it was loaded from or last saved as.
  • It offers the self-named call over each Project method (save, get_results, has_results, list_versions), and solve.
  • It keeps a digest of the saved model, so has_unsaved_changes needs no read.

add_component, add_or_replace_component and set_timesteps answer the network, so they chain:

network = Network(name="dispatch", framework="PyPSA")
network.timesteps = ("t0", "t1", "t2")
network.add_component("Bus", "bus").add_component(
    "Generator", "cheap", bus="bus", p_nom=100.0, marginal_cost=10.0
)

ComponentHandle

Network.get_component_handle answers a handle that edits one component.

  • set(**attributes), set_curve(**curves) and clear(*attributes) answer the handle.
  • find_value and find_curve read.
  • A handle refuses once its network no longer holds that component.

The conductor turns a framework's pydantic.ValidationError into its own InvalidComponentAttributesError, so a caller never has to catch a third-party error.

Clone this wiki locally