Skip to main content

CLI and Python library for manipulating BIDS datasets

Project description

bids-utils

CI License: Apache 2.0 Python: 3.10+ Code style: ruff Typed: mypy

A CLI and Python library for manipulating BIDS datasets: rename files, subjects, sessions, and runs; migrate datasets between BIDS versions; aggregate, segregate, and audit metadata; merge and split datasets. Schema-driven throughout (via bidsschematools) and aware of version control, including git-annex and DataLad datasets.

⚠️ Status: early development. APIs, CLI commands, and behaviors may change before the first tagged release.

What it does

  • File / subject / session / run renaming with sidecar, _scans.tsv, and participants.tsv updates, plus BIDS URI fix-up.
  • Schema-driven migration between BIDS versions, including 1.x deprecation fixes and 2.0 structural changes. Tiered rule levels (safe / advisory / non-auto-fixable).
  • Metadata management — aggregate, segregate, and audit inheritance chains across sidecar JSONs.
  • Dataset-level operationsmerge, split, remove.
  • VCS-aware — git, git-annex, and DataLad backends; annexed content is fetched / unlocked / re-added as needed (--annexed=get).

Install

# one-shot (isolated) invocation
uvx bids-utils --help

# inside a project env
uv pip install bids-utils     # or: pip install bids-utils

Commands

$ bids-utils --help
Usage: bids-utils [OPTIONS] COMMAND [ARGS]...

  CLI for manipulating BIDS datasets.

Options:
  --version                       Show the version and exit.
  --annexed [error|get|skip-warning|skip]
                                  How to handle git-annex files without local
                                  content.
  -h, --help                      Show this message and exit.

Commands:
  completion      Output shell completion activation script.
  merge           Merge multiple BIDS datasets.
  metadata        Metadata manipulation commands.
  migrate         Apply schema-driven migrations to resolve deprecations.
  remove          Remove a subject from the dataset.
  remove-run      Remove a run and optionally reindex subsequent runs.
  rename          Rename a BIDS file and all its sidecars.
  session-rename  Rename a session.
  split           Extract a subset of a BIDS dataset.
  subject-rename  Rename a subject across the entire dataset.

Run bids-utils <COMMAND> --help for per-command options.

Quick tour

# Rename a BOLD file; sidecars and _scans.tsv follow automatically.
bids-utils rename path/to/sub-01_task-rest_bold.nii.gz --set task=nback

# Migrate an older 1.x dataset to the current 1.x release.
bids-utils migrate /data/ds001 --dry-run

# Rename a subject across the whole dataset (VCS-aware).
bids-utils subject-rename /data/ds001 --from 01 --to 99

The same operations are available as a Python library:

from bids_utils import BIDSDataset
from bids_utils.subject import rename_subject

ds = BIDSDataset.from_path("/data/ds001")
rename_subject(ds, old="01", new="99")

Shell completion

bids-utils completion emits an activation script for the detected shell (bash, zsh, or fish) with BIDS-aware suggestions for sub-*, ses-*, and entity keys from the schema.

# Enable for the current shell (one-shot):
eval "$(bids-utils completion)"

# Persist it: append to your shell rc file.
echo 'eval "$(bids-utils completion)"' >> ~/.bashrc   # or ~/.zshrc

For fish:

bids-utils completion fish | source

Contributing

See CONTRIBUTING.md for tooling conventions, the pre-commit tox gate, and where to find the design documents under .specify/specs/. Integration tests use the bids-examples submodule — run git submodule update --init --recursive after cloning.

License

Apache License 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bids_utils-0.1.1.tar.gz (16.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bids_utils-0.1.1-py3-none-any.whl (59.0 kB view details)

Uploaded Python 3

File details

Details for the file bids_utils-0.1.1.tar.gz.

File metadata

  • Download URL: bids_utils-0.1.1.tar.gz
  • Upload date:
  • Size: 16.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for bids_utils-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9b83d97aef47f180215e031dc51e15b74bc1f7ff677434670cece25806c3f097
MD5 75900d585dc8dd9c69257102eb886d3c
BLAKE2b-256 9bc75e13ddf7a57adc5a993fb173f4ef2da9cd4f82ffacdfa686181a0d3d249f

See more details on using hashes here.

File details

Details for the file bids_utils-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: bids_utils-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 59.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for bids_utils-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8bc4a0f356afe79aef39a7657fcb3d53cc5e1b127335766c3687f2d70191dcf8
MD5 b81a8056c609c88f8f92223f4c9207a7
BLAKE2b-256 9f9b25048a10eb513ba92982f7937b55fba9c4fcb4adc8c3e39d836c6604fb8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page