Python for Power Systems Analysis
Project description
PyPSA - Python for Power System Analysis
PyPSA stands for Python for Power System Analysis. It is pronounced pipes-ah.
PyPSA is an open-source Python framework for optimising and simulating modern power and energy systems that include features such as conventional generators with unit commitment, variable wind and solar generation, hydro-electricity, inter-temporal storage, coupling to other energy sectors, elastic demands, and linearised power flow with loss approximations in DC and AC networks. PyPSA is designed to scale well with large networks and long time series. It is made for researchers, planners and utilities with basic coding aptitude who need a fast, easy-to-use and transparent tool for power and energy system analysis.
[!NOTE] PyPSA has many contributors, with the maintenance led by the Department of Digital Transformation in Energy Systems at the Technical University of Berlin. The project is currently supported by the German Research Foundation (grant number
528775426). Previous versions were developed at the Karlsruhe Institute of Technology funded by the Helmholtz Association, and at FIAS funded by the German Federal Ministry for Education and Research (BMBF).
Features
-
Economic Dispatch (ED): Models short-term market-based dispatch including unit commitment, renewable availability, short-duration and seasonal storage including hydro reservoirs with inflow and spillage dynamics, elastic demands, load shedding and conversion between energy carriers, using either perfect operational foresight or rolling horizon time resolution.
-
Linear Optimal Power Flow (LOPF): Extends economic dispatch to determine the least-cost dispatch while respecting network constraints in meshed AC-DC networks, using a linearised representation of power flow (KVL, KCL) with optional loss approximations.
-
Security-Constrained LOPF (SCLOPF): Extends LOPF by accounting for line outage contingencies to ensure system reliability under $N-1$ conditions.
-
Capacity Expansion Planning (CEP): Supports least-cost long-term system planning with investment decisions for generation, storage, conversion, and transmission infrastructure. Handles both single and multiple investment periods. Continuous and discrete investments are supported.
-
Pathway Planning: Supports co-optimisation of multiple investment periods to plan energy system transitions over time with perfect planning foresight.
-
Stochastic Optimisation: Implements two-stage stochastic programming framework with scenario-weighted uncertain inputs, with investments as first-stage decisions and dispatch as recourse decisions.
-
Modelling-to-Generate-Alternatives (MGA): Explores near-optimal decision spaces to provide insight into the range of feasible system configurations with similar costs.
-
Sector-Coupling: Modelling integrated energy systems with multiple energy carriers (electricity, heat, hydrogen, etc.) and conversion between them. Flexible representation of technologies such as heat pumps, electrolysers, battery electric vehicles (BEVs), direct air capture (DAC), and synthetic fuels production.
-
Static Power Flow Analysis: Computes both full non-linear and linearised load flows for meshed AC and DC grids using Newton-Raphson method.
Documentation
PyPSA has extensive documentation with tutorials, user guides, examples and an API reference.
Installation
pip:
pip install pypsa
conda/mamba:
conda install -c conda-forge pypsa
uv:
uv add pypsa
Usage
import pypsa
# create a new network
n = pypsa.Network()
n.add("Bus", "mybus")
n.add("Load", "myload", bus="mybus", p_set=100)
n.add("Generator", "mygen", bus="mybus", p_nom=100, marginal_cost=20)
# load an example network
n = pypsa.examples.ac_dc_meshed()
# run the optimisation
n.optimize()
# plot results
n.generators_t.p.plot()
n.plot()
# get statistics
n.statistics()
n.statistics.energy_balance()
Dependencies
PyPSA relies heavily on other open-source Python packages. Some of them are:
- pandas for storing data about components and time series
- numpy and scipy for linear algebra and matrix calculations
- linopy for preparing optimisation problems
- matplotlib, seaborn and plotly for static and interactive plotting
- networkx for network calculations
- pytest for unit testing
Find the full list of dependencies in the pyproject.toml file.
PyPSA can be used with different solvers. For instance, the free solvers HiGHS (installed by default), GLPK and CBC or commercial solvers like Gurobi or FICO Xpress for which free academic licenses are available.
Contributing and Support
We strongly welcome anyone interested in contributing to this project. If you have any ideas, suggestions or encounter problems, feel invited to file issues or make pull requests on GitHub.
- To discuss with other PyPSA users, organise projects, share news, and get in touch with the community you can use the Discord server.
- For bugs and feature requests, please open an issue.
- For troubleshooting and support, please check the troubleshooting and support sectionsin the documentation.
Detailed guidelines can be found in the Contributing guidelines of our documentation.
Code of Conduct
Please respect our Code of Conduct.
Citing PyPSA
If you use PyPSA for your research, we would appreciate it if you would cite the following paper:
- T. Brown, J. Hörsch, D. Schlachtberger, PyPSA: Python for Power System Analysis, 2018, Journal of Open Research Software, 6(1), arXiv:1707.09913, DOI:10.5334/jors.188
Please use the following BibTeX:
@article{PyPSA,
author = {T. Brown and J. H\"orsch and D. Schlachtberger},
title = {{PyPSA: Python for Power System Analysis}},
journal = {Journal of Open Research Software},
volume = {6},
issue = {1},
number = {4},
year = {2018},
eprint = {1707.09913},
url = {https://doi.org/10.5334/jors.188},
doi = {10.5334/jors.188}
}
If you want to cite a specific PyPSA version, each release of PyPSA is archived
on Zenodo with a release-specific DOI:
Licence
Copyright PyPSA Contributors
PyPSA is licensed under the open source MIT License. The documentation is licensed under CC-BY-4.0.
The repository uses REUSE to expose the licenses of its files.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pypsa-1.0.7.tar.gz.
File metadata
- Download URL: pypsa-1.0.7.tar.gz
- Upload date:
- Size: 12.9 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5f26d19eba7201c5a2f46413eef1b717bbb5f9bfedfb66d49c488c5c10f49064
|
|
| MD5 |
33ed8557434aad6c215045bbc5b44f0b
|
|
| BLAKE2b-256 |
cbf8dfb73925255714c0a450849f3026537950839ec15d8ac11ab2e6f6f68e9e
|
Provenance
The following attestation bundles were made for pypsa-1.0.7.tar.gz:
Publisher:
release.yml on PyPSA/PyPSA
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypsa-1.0.7.tar.gz -
Subject digest:
5f26d19eba7201c5a2f46413eef1b717bbb5f9bfedfb66d49c488c5c10f49064 - Sigstore transparency entry: 817235055
- Sigstore integration time:
-
Permalink:
PyPSA/PyPSA@16cb35eebe4f9781794ebbf7bbc34a1247daccc4 -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/PyPSA
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@16cb35eebe4f9781794ebbf7bbc34a1247daccc4 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pypsa-1.0.7-py3-none-any.whl.
File metadata
- Download URL: pypsa-1.0.7-py3-none-any.whl
- Upload date:
- Size: 318.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbda31994040fc9fa43bb94e82022a6752f9c99bda414d74232bf7fdefa2176e
|
|
| MD5 |
4e495c222d995799e40afdbd6cc96ed3
|
|
| BLAKE2b-256 |
2b4cdfd10c54c2b43fafc319749cca75d2d12c141595db8bbdc075ff040f32bf
|
Provenance
The following attestation bundles were made for pypsa-1.0.7-py3-none-any.whl:
Publisher:
release.yml on PyPSA/PyPSA
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pypsa-1.0.7-py3-none-any.whl -
Subject digest:
cbda31994040fc9fa43bb94e82022a6752f9c99bda414d74232bf7fdefa2176e - Sigstore transparency entry: 817235122
- Sigstore integration time:
-
Permalink:
PyPSA/PyPSA@16cb35eebe4f9781794ebbf7bbc34a1247daccc4 -
Branch / Tag:
refs/tags/v1.0.7 - Owner: https://github.com/PyPSA
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@16cb35eebe4f9781794ebbf7bbc34a1247daccc4 -
Trigger Event:
push
-
Statement type: