pyedflib

raw JSON →
0.1.42 verified Mon Apr 27 auth: no python

A Python library to read and write EDF+/BDF+ files, commonly used for biomedical signal data (e.g., EEG, ECG). Current version 0.1.42. Low release cadence, maintenance mode.

pip install pyedflib
error FileNotFoundError: [Errno 2] No such file or directory: 'example.edf'
cause File path does not exist or is relative to the wrong directory.
fix
Use an absolute path or ensure the current working directory is correct.
error ValueError: The physical_min and physical_max values are too small. The scaling factor is too large.
cause Previous versions (pre-0.1.39) raised an error for extreme physical ranges.
fix
Set physical_min and physical_max to reasonable values matching the signal amplitude, or upgrade to >=0.1.39 which only warns.
error ImportError: cannot import name 'EdfReader' from 'pyedflib'
cause Trying to import from the wrong module or an older version of pyedflib.
fix
Use from pyedflib import EdfReader and ensure version >=0.1.0.
breaking In v0.1.38, pyedflib dropped support for Python <3.8 and numpy <2.0. Ensure your environment uses Python 3.8+.
fix Upgrade to pyedflib >=0.1.38 and use Python 3.8+.
deprecated The parameter `sample_rate` in `setSignalHeader` is deprecated since v0.1.39. Use `sample_frequency` instead.
fix Replace `sample_rate` with `sample_frequency` in `setSignalHeader` calls.
gotcha When writing EDF files, `physical_min` and `physical_max` are no longer strictly asserted (since v0.1.39). Incorrect values may produce warnings but still write, potentially corrupting data.
fix Ensure physical_min and physical_max correctly represent the expected signal range.
gotcha The `readSignal` method returns a numpy array; indexing and handling differ from raw digital values. Be aware of the scaling applied.
fix Refer to documentation for signal scaling details.

Basic read/write of EDF+ files with pyedflib.

from pyedflib import EdfReader, EdfWriter
import numpy as np

# Read an EDF file
reader = EdfReader('example.edf')
signal = reader.readSignal(0)
print(f'Signal length: {len(signal)}')
reader.close()

# Write an EDF file
writer = EdfWriter('output.edf', n_channels=1, file_type=1)  # EDF+ type: 1=EDF, 0=BDF
writer.setSignalHeader(0, label='ECG', dimension='mV', sample_rate=256, physical_min=-5, physical_max=5, digital_min=-32768, digital_max=32767)
data = np.sin(np.linspace(0, 10, 2560))
writer.writeSamples([data])
writer.close()