The increasing complexity of power electronic circuits calls for the use of advanced control algorithms, which in turns rely on extensive and accurate models. This paper lays out the rigorous mathematical framework for an elegant and automatable state space modelling of a linear electrical circuit. The steps consist in extracting key information of a netlist and de-riving the state space model after identifying independent states. The netlist can either be written by the designer or a SPICE software. The resulting Multi-Input Multi-Output (MIMO) state space model can then be fed into classic control design methods, e.g. linear quadratic gaussian control (LQG) or model predictive control (MPC), possibly coupled with robust observing methods, e.g. Kalman filter, to create performant regulators. The proposed automatised derivation strategy is verified by a simple case of electrical circuit and a case of modular multilevel converter (MMC).