Skip to main content

Ask DeepWiki Documentation Status Latest Version PyPI - Python Version Test Status Codecov License

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 many pybids API 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 in ancpbids/model_base.py. Versioned enums are loaded at runtime from official BIDS schema.json files vendored in ancpbids/schema/.

  • Plugin System:
    The extension mechanism (see ancpbids/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; SchemaPlugin remains an extension point.

  • Query Engine:
    The query logic is implemented in ancpbids/query.py, providing flexible access to dataset contents and metadata.

  • Compatibility Layer:
    ancpbids/pybids_compat.py provides compatibility with the pybids API for easier migration and integration.

  • Utilities:
    Helper functions and utilities are in ancpbids/utils.py.

  • Testing:
    The tests/ directory is organized into auto (CI-safe) and manual (non-deterministic or performance) tests, with synthetic datasets under tests/data/.

Plugin and mixin system

Extensibility comes in two shapes:

  • Plugins — hook into load / write / validate / schema / file I/O (execute methods).
  • Mixins — add methods to a host class such as BIDSLayout via @mixin(target=...).

Built-in plugins/mixins are registered the same way: decorated with @hook(ranking=0, system=True) / @mixin(...) and listed under ancpbids.plugins / ancpbids.mixins in this project's pyproject.toml. Third-party packages add their own entries to those groups. Hooks are lifecycle contributors (execute); mixins add methods to host classes.

Registering an external plugin

  1. Decorate a plugin subclass:

    from ancpbids.plugin import ValidationPlugin, hook
    
    @hook(ranking=1000)
    class SiteRulesPlugin(ValidationPlugin):
        def execute(self, dataset, report: ValidationPlugin.ValidationReport):
            pass
    
  2. In your package’s pyproject.toml:

    [project.entry-points."ancpbids.plugins"]
    site_rules = "lab_bids_extensions.validation:SiteRulesPlugin"
    
  3. Install alongside ancpBIDS; importing ancpbids loads the plugin.

Registering an external mixin

  1. Decorate a mixin with a target (live class or "module:Class" string):

    from ancpbids import BIDSLayout
    from ancpbids.plugin import mixin
    
    @mixin(target=BIDSLayout, ranking=1000)
    class MyExportMixin:
        def to_custom(self):
            ...
    
  2. Advertise under ancpbids.mixins:

    [project.entry-points."ancpbids.mixins"]
    my_export = "lab_bids_extensions.exports:MyExportMixin"
    

Built-in DataFrameMixin lives in ancpbids.mixins.mixin_dataframe, uses @mixin(target=BIDSLayout, ranking=0), and is listed as to_df under the ancpbids.mixins entry-point group in this project's pyproject.toml.

Full guide: docs/source/plugins.rst.

Versioning and Schema Evolution

  • The codebase supports multiple BIDS schema versions via vendored schema.json files.
  • The schema is loaded dynamically based on the dataset version, allowing for forward compatibility.

Testing and CI

  • Unit Tests:
    Located in tests/auto/, these are run automatically in CI.
  • Manual/Performance Tests:
    Located in tests/manual/, these are for benchmarking or non-deterministic checks.
  • Synthetic Data:
    All tests use synthetic datasets in tests/data/ to ensure reproducibility.

Developer Guidelines

  • Extending the Model:
    Add a new ancpbids/schema/schema_v<version>.json (see Model Generation Utility). Type stubs and model_latest update from the vendored JSON files.
  • Adding Plugins:
    Follow the plugin system described above (including external entry points).
  • Testing:
    Add new tests to tests/auto/ for CI-safe code, and to tests/manual/ for performance or integration tests.
  • Documentation:
    Update README.md and 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-version is omitted, the latest available schema version is used.
  • --stubs-only regenerates stubs from JSON files already in ancpbids/schema/.
  • Output: ancpbids/schema/schema_v<version>.json, ancpbids/schema/v1_X_Y.pyi, and ancpbids/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

ancpbids-0.4.4.tar.gz (2.4 MB view details)

Uploaded Source

Built Distribution

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

ancpbids-0.4.4-py3-none-any.whl (660.7 kB view details)

Uploaded Python 3

File details

Details for the file ancpbids-0.4.4.tar.gz.

File metadata

  • Download URL: ancpbids-0.4.4.tar.gz
  • Upload date:
  • Size: 2.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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

Hashes for ancpbids-0.4.4.tar.gz
Algorithm Hash digest
SHA256 e49e8c99feb1145f8d3deb82e552c154f9b0ec0e47e99ab7d585303f3f9a5a1e
MD5 af1454f723562a517f5423a40f2a4507
BLAKE2b-256 a0faa6c11e9d1ae3c543c0e2915a02ace53188f736c70f8344ec136231eddd0a

See more details on using hashes here.

File details

Details for the file ancpbids-0.4.4-py3-none-any.whl.

File metadata

  • Download URL: ancpbids-0.4.4-py3-none-any.whl
  • Upload date:
  • Size: 660.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","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

Hashes for ancpbids-0.4.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b47367c44eca1ebafd908bac11be7df0ed8a748c3520e67c2470128f5144aaf4
MD5 af8b1714673d366e1032b03f6a331129
BLAKE2b-256 4f97f4ad4558a6f8cdff3ac3770f9a2fd9081a5cf08bd3daf4191767be444f45

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.10

2 files

0.4.9

2 files

0.4.8

2 files

0.4.7

2 files

0.4.6

2 files

0.4.5

2 files

This release

0.4.4 This release

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.9

2 files

0.2.8

2 files

0.2.7

2 files

0.2.6

2 files

0.2.5

2 files

0.2.4

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

0.0.22

2 files

0.0.21

2 files

0.0.20

2 files

0.0.19

2 files

0.0.18

2 files

0.0.17

2 files

0.0.16

2 files

0.0.15

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page