Hostname: page-component-5d59c44645-lfgmx Total loading time: 0 Render date: 2024-02-26T01:53:09.344Z Has data issue: false hasContentIssue false

Keypy – An Open Source Library For EEG Microstate Analysis

Published online by Cambridge University Press:  23 March 2020

P. Milz*
The KEY Institute for Brain-Mind Research, Department of Psychiatry, Psychotherapy and Psychosomatics, University Hospital of Psychiatry, Zurich, Switzerland


Core share and HTML view are not available for this content. However, as you have access to this content, a full PDF is available via the ‘Save PDF’ action button.

The brain's electric field configuration reflects its momentary, global functional state. The fluctuations of these states can be analyzed at millisecond resolution by the EEG microstate analysis. This analysis reportedly allowed the detection of brain state duration, occurrence, and sequence aberrations in psychiatric disorders such as schizophrenia, dementia, and depression. Several existing software solutions implement the microstate analysis, but they all require extensive user-interaction. This represents a major obstacle to time-efficient automated analyses and parameter exploration of large EEG datasets. Scriptable programming languages such as Python provide a means to efficiently automate such analysis workflows.

For this reason, I developed the KEY EEG Python Library keypy. This library implements all steps necessary to compute the microstate analysis based on artefact free segments of EEG. It includes functions to carry out the necessary preprocessing (data loading, filtering, average referencing), modified k-means clustering based microstate identification, principal component based mean computation (across recording runs, conditions, participants, and or participant groups), and to retrieve the microstate class based statistics necessary to compare microstate parameters between groups and/or conditions. Keypy is an open source library and freely available from

Keypy provides a platform for automated microstate analysis of large-scale EEG datasets from psychiatric patient populations and their comparison to healthy controls. It is easily applicable and allows efficient identification of deviant brain states in clinical conditions.

Disclosure of interest

The authors have not supplied their declaration of competing interest.

Copyright © European Psychiatric Association 2016
Submit a response


No Comments have been published for this article.