BIDS Schema Tools

1.2.2 · active · verified Thu Apr 16

bidsschematools is a Python library providing utilities for programmatic interaction with the Brain Imaging Data Structure (BIDS) schema. It enables loading, parsing, and validating BIDS datasets against the official specification. The current version is 1.2.2, with releases typically coinciding with major BIDS specification updates or essential bug fixes and enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load the default BIDS schema, inspect its properties like version and entities, and perform a basic check for filename pattern validity. For full dataset validation, a more complete BIDS dataset structure would be required.

from bidsschematools import schema
import pprint

# Load the default, current BIDS schema
bids_schema = schema.BIDS_SCHEMA

print(f"BIDS Schema Version: {bids_schema.version}")
print(f"Number of entities in schema: {len(bids_schema.entities)}")

# Accessing a specific entity definition
entity_sub = bids_schema.entities.get("subject")
if entity_sub:
    print("\n'subject' entity definition:")
    pprint.pprint(entity_sub)

# Example: Check if a filename pattern is valid according to schema rules
# Note: Full file validation requires a dataset context.
filename_pattern = "sub-<label>[_ses-<label>][_task-<label>]_bold.nii.gz"
is_valid_pattern = bids_schema.validate_pattern_string(filename_pattern)
print(f"\nIs example filename pattern valid according to schema? {is_valid_pattern}")

# To load a specific schema from a path:
# custom_schema = schema.BIDS_SCHEMA.from_path("path/to/your/custom_bids_schema_directory")

view raw JSON →