Skip to content

Flywheel Gear Toolkit

Introduction

flywheel-gear-toolkit is a Python package designed to simplify the development of Flywheel gears. It provides a set of modules that make gear creation more efficient and streamlined. The package is maintained by Flywheel and requires Python 3.8 or higher.

This documentation provides an overview of the fw-gear library and points to the official documentation for detailed information.

Key Features

  • Simplified Gear Development: Provides a standardized framework for creating Flywheel gears
  • Context Management: Easily access and manage gear inputs, outputs, and configuration
  • Specification Handling: Tools for working with gear specifications and manifests
  • Utility Functions: Common operations for file handling, logging, and more
  • SDK Integration: Optional integration with the Flywheel SDK

Installation

The package can be installed using pip or poetry:

pip install flywheel-gear-toolkit  # or
poetry add flywheel-gear-toolkit

Optional Dependencies

The flywheel-gear-toolkit library supports several optional dependencies that provide additional functionality:

  • all: Installs all optional dependencies
  • dicom: Provides the fw-file and nibabel packages
  • fw-file: Adds support for interacting with various file types and their metadata
  • nipype: Includes the nipype and nibabel packages
  • numpy: Adds support for numpy arrays in JSON operations
  • sdk: Provides the flywheel-sdk and flywheel-bids packages

Install optional dependencies using:

pip install "flywheel-gear-toolkit"  # or
poetry add flywheel-gear-toolkit

Core Modules

Context

The Context module provides access to the gear's runtime environment, including:

  • Input files and their metadata
  • Configuration options
  • Output directory
  • Logging facilities

Specs

The Specs module helps with handling gear specifications and manifests, including:

  • Parsing and validating manifest files
  • Working with input and configuration specifications
  • Managing gear metadata

Utils

The Utils module offers various utility functions for common gear operations:

  • File handling and manipulation
  • Logging and error reporting
  • Data conversion and formatting

Basic Usage Example

Here's a simple example of using fw-gear in a gear script:

from flywheel_gear_toolkit import GearToolkitContext
from my_awesome_module import do_something

def main(context):
    # Do something with your input dicom file
    do_something(
        dicom=context.get_input_path('dicom'),
        output_dir=context.output_dir
    )

if __name__ == "__main__":
    with GearToolkitContext() as context:
        # Setup basic logging
        context.init_logging()
        # Call my main function
        main(context)

API Reference

For detailed API documentation, please refer to the official documentation.

Additional Resources