ancpBIDS is a modular Python library for reading, querying, validating, and writing BIDS datasets. Its architecture is designed for extensibility and maintainability.
Key Features
-
BIDS Dataset Loading
Load BIDS datasets of any size or complexity, with support for multiple BIDS schema versions. -
Flexible Query Engine
Query files, folders, and metadata using a powerful, Pythonic API. Supports entity-based, scope-based, and custom queries. -
Validation
Validate datasets against the BIDS specification and custom rules using a plugin-based validation system. -
Writing and Derivatives
Write and update BIDS datasets, including support for creating and saving BIDS derivatives. -
Lazy Loading
Efficiently handle large datasets with optional lazy loading, reducing memory usage and speeding up initial access. -
Plugin Architecture
Extend or customize core functionality (validation, file handling, schema, etc.) via a robust plugin system. -
PyBIDS Compatibility Layer
Drop-in compatibility for manypybidsAPI calls, easing migration from or integration with existing codebases. -
Synthetic and Real Data Support
Works with both synthetic test datasets and real-world BIDS datasets. -
CI/CD Ready
Includes a comprehensive suite of automated and manual tests, with synthetic datasets for reproducibility. -
Extensible and Versioned Schema
Supports multiple BIDS schema versions and allows for easy extension as the BIDS standard evolves.
Architecture
-
Core Models:
The in-memory graph is hand-maintained inancpbids/model_base.py. Versioned enums are loaded at runtime from official BIDSschema.jsonfiles vendored inancpbids/schema/. -
Plugin System:
The plugin mechanism (seeancpbids/plugin.py) allows for dynamic extension of core functionality. Plugins can hook into schema modification, dataset processing, file handling, writing, and validation. Graph methods (query,get_schema, …) live on the model classes;SchemaPluginremains an extension point. -
Query Engine:
The query logic is implemented inancpbids/query.py, providing flexible access to dataset contents and metadata. -
Compatibility Layer:
ancpbids/pybids_compat.pyprovides compatibility with the pybids API for easier migration and integration. -
Utilities:
Helper functions and utilities are inancpbids/utils.py. -
Testing:
Thetests/directory is organized intoauto(CI-safe) andmanual(non-deterministic or performance) tests, with synthetic datasets undertests/data/.
Plugin System
The plugin system is a core feature for extensibility:
-
Plugin Types:
SchemaPlugin: Modify or extend the BIDS schema.DatasetPlugin: Operate on in-memory dataset graphs.FileHandlerPlugin: Register custom file readers/writers.WritingPlugin: Add files/folders during dataset writing.ValidationPlugin: Add custom validation rules.
-
Registration and Discovery:
Plugins are registered viaregister_pluginor discovered withload_plugins_by_package. They are prioritized by arankingvalue. -
Execution:
At key points (e.g., dataset load, write, validate), the system retrieves and executes all relevant plugins usingget_plugins. -
How to Add a Plugin:
- Subclass the appropriate plugin base class from
plugin.py. - Implement the required
executemethod. - Register your plugin using
register_pluginor by placing it in a discoverable package.
- Subclass the appropriate plugin base class from
Versioning and Schema Evolution
- The codebase supports multiple BIDS schema versions via vendored
schema.jsonfiles. - The schema is loaded dynamically based on the dataset version, allowing for forward compatibility.
Testing and CI
- Unit Tests:
Located intests/auto/, these are run automatically in CI. - Manual/Performance Tests:
Located intests/manual/, these are for benchmarking or non-deterministic checks. - Synthetic Data:
All tests use synthetic datasets intests/data/to ensure reproducibility.
Developer Guidelines
- Extending the Model:
Add a newancpbids/schema/schema_v<version>.json(see Model Generation Utility). Type stubs andmodel_latestupdate from the vendored JSON files. - Adding Plugins:
Follow the plugin system described above. - Testing:
Add new tests totests/auto/for CI-safe code, and totests/manual/for performance or integration tests. - Documentation:
UpdateREADME.mdand docstrings for any new features or changes.
Code Quality
- The codebase uses type hints and docstrings for clarity.
- Contributions should follow PEP8 and include tests and documentation.
Model Generation Utility
The in-memory graph (ancpbids/model_base.py) is hand-maintained. tools/generatemodel.py fetches an official BIDS schema.json into ancpbids/schema/ and writes version-specific type stubs (v1_X_Y.pyi) so IDEs can see enum literals such as SuffixEnum.bold. Enums are still built from JSON at runtime.
Usage:
uv run --with requests python tools/generatemodel.py [--schema-version <version>]
uv run python tools/generatemodel.py --stubs-only
- If
--schema-versionis omitted, the latest available schema version is used. --stubs-onlyregenerates stubs from JSON files already inancpbids/schema/.- Output:
ancpbids/schema/schema_v<version>.json,ancpbids/schema/v1_X_Y.pyi, andancpbids/schema/aliases.pyi.
Further Reading
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ancpbids-0.4.1.tar.gz.
File metadata
- Download URL: ancpbids-0.4.1.tar.gz
- Upload date:
- Size: 659.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f38ac7ae28261c4b97f4f4941b0e93c3cf157214abfd1ea6e078c56c99a9c99e
|
|
| MD5 |
9761c4d79fcb2da1199bb674d4f7e8ef
|
|
| BLAKE2b-256 |
8d30bb146ec9b7fe0067fd1191c3c873c5dd9f0c3ff28bcd7d2b34b69799dd3f
|
File details
Details for the file ancpbids-0.4.1-py3-none-any.whl.
File metadata
- Download URL: ancpbids-0.4.1-py3-none-any.whl
- Upload date:
- Size: 657.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
uv/0.12.4 {"installer":{"name":"uv","version":"0.12.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96118f6a4f936ef7e33da000832496dddbe4a800416c0f6f1a1282a60fe138ca
|
|
| MD5 |
db182f0395ac1415a56e642b6fbcf2ef
|
|
| BLAKE2b-256 |
0182079230f876d31651448762b5b80217ecb46d853557509da5f5f176e9f801
|