Registry / data / pynwb
library3.1.3pypypi✓ verified 89d ago

PyNWB is the official Python API for working with Neurodata Without Borders (NWB) files, a standardized data format for neurophysiology data. It facilitates reading, writing, and manipulating NWB files, providing a high-level interface to the underlying HDF5 structure. The current version is 3.1.3, and it maintains an active release cadence with regular minor updates and less frequent major versions supporting new NWB schema versions.

pip install pynwb
INSTALL
IMPORT
SIG · PYNWB
P
pynwb
datapythonv3.1.3
Install
9.8s avg
Import
3621ms
Disk
196MB
Pass rate
9/ 10
Env Coverage9 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v3.1.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 9.85s
py 3.11
✓ —
✓ 9.23s
py 3.12
✓ —
✓ 9.25s
py 3.13
✓ —
✓ 9.3s
py 3.9
✕ build_error
✓ 11.45s
196MB installed
● package 196MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

NWBFile
✓ from pynwb import NWBFile
NWBHDF5IO
✓ from pynwb import NWBHDF5IO
✗ from pynwb.io import NWBHDF5IO
NWBHDF5IO is directly available from the top-level pynwb package since version 2.0.0. Importing from pynwb.io is deprecated.
TimeSeries
✓ from pynwb.base import TimeSeries
ElectricalSeries
✓ from pynwb.ecephys import ElectricalSeries
ImageSeries
✓ from pynwb.ophys import ImageSeries

This quickstart demonstrates how to create a basic NWB file, add a TimeSeries to it, and then write and read the file from disk using `NWBFile` and `NWBHDF5IO`. It covers the fundamental steps for data archival in the NWB format.

from datetime import datetime from pynwb import NWBFile, TimeSeries, NWBHDF5IO import numpy as np import os # 1. Create a new NWBFile nwbfile = NWBFile( session_description='My first NWB file tutorial', identifier='NWB_Tutorial_1', session_start_time=datetime.now().astimezone(), experimenter='John Doe', lab='Neuroscience Lab', institution='University of Example', experiment_description='Simple data creation for testing PyNWB.' ) # 2. Add some TimeSeries data data = np.random.rand(100, 1) timestamps = np.linspace(0, 9.9, 100) series = TimeSeries( name='my_timeseries', data=data, timestamps=timestamps, unit='volts', description='A simple random time series.' ) nwbfile.add_acquisition(series) # 3. Write the NWBFile to disk filename = 'quickstart_example.nwb' with NWBHDF5IO(filename, 'w') as io: io.write(nwbfile) print(f"NWB file '{filename}' created successfully.") # 4. Read the NWBFile from disk with NWBHDF5IO(filename, 'r') as io: read_nwbfile = io.read() print(f"\nRead NWB file. Session description: {read_nwbfile.session_description}") read_series = read_nwbfile.acquisition['my_timeseries'] print(f"Read TimeSeries data shape: {read_series.data.shape}") print(f"Read TimeSeries unit: {read_series.unit}") # Clean up the created file # os.remove(filename)
Debug
Known issues
breakingThe behavior of `pynwb.validate(io=...)` changed in version 3.0.0. It now matches `pynwb.validate(path=...)` and uses cached namespaces. Previous versions did not use cached namespaces for `io` validation.
fix
If you rely on the pre-3.0.0 behavior of `pynwb.validate(io=...)` without cached namespaces, update your call to `pynwb.validate(io=..., use_cached_namespaces=False)` to explicitly disable caching for that operation.
affects: >=3.0.0
breakingSeveral unused internal functions (e.g., `prepend_string`, `_not_parent` in `core.py`, `_not_parent` in `file.py`, `NWBBaseTypeMapper.get_nwb_file` in `io/core.py`) were removed.
fix
These were internal functions. If your code was inadvertently using them, you will need to refactor to use documented public APIs or directly interact with the NWB schema as needed.
affects: >=3.1.0
gotchaFiles written with `NWBHDF5IO` without a `.nwb` extension will trigger a warning.
fix
Always ensure your NWB file paths end with the `.nwb` extension (e.g., `myfile.nwb`) to adhere to NWB best practices and avoid warnings.
affects: >=2.8.3
gotchaA performance regression introduced in pynwb 2.8.0 affected reading NWB files with a large number of objects or fields of objects.
fix
Upgrade to pynwb version 3.1.2 or later to benefit from the performance fix for large NWB files.
affects: 2.8.0 - 3.1.1
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'pynwb.io'
Attempting to import `NWBHDF5IO` from a submodule `pynwb.io` which is not the primary import path for recent pynwb versions.
fix
Import `NWBHDF5IO` directly from the top-level `pynwb` package: `from pynwb import NWBHDF5IO`.
ValueError: NWBFile requires 'session_start_time' and 'identifier'
When creating an `NWBFile` instance, the `session_start_time` and `identifier` arguments are mandatory according to the NWB schema.
fix
Ensure `session_start_time` (a `datetime` object) and `identifier` (a unique string) are always provided during `NWBFile` initialization. Example: `NWBFile(session_description='...', identifier='my_session', session_start_time=datetime.now().astimezone())`.
RuntimeError: Unable to open object (object 'acquisition' not found)
This usually means you are trying to access a group or data field within the NWB file (e.g., `nwbfile.acquisition['my_data']`) that does not exist or has a different name.
fix
Verify the exact name of the object you are trying to access. Use `nwbfile.acquisition.keys()` to list available acquisition objects, or consult the NWB file's structure or the code that generated it.
Upgrade
Version history
3.1.3latest on PyPI · released Dec 9, 2025
Audit
Dependencies
h5pyrequiredCore dependency for HDF5 file operations.
numpyrequiredFundamental for numerical data handling.
Agent activity
8 hits · last 30 days
node
8
Resources
pynwb — pip install pynwb · libregistry