Skip to content
Documentation

Documentation

github.com • December 1, 2026

High-performance FHIR data transformation for Python. Transform FHIR resources into tabular formats (CSV, JSON, Parquet) using declarative ViewDefinitions from the SQL on FHIR specification .

Built in Rust for speed, exposed to Python with a simple, Pythonic API. Part of the Helios FHIR Server project.

🚀 High Performance : Native Rust implementation with minimal Python overhead

📊 Multiple Output Formats : CSV, JSON, NDJSON, and Parquet

🔄 Parallel Processing : Automatic multithreading with 5-7x speedup on multi-core systems

📦 Streaming Support : Memory-efficient chunked processing for large NDJSON files

🌐 Multi-Version FHIR : Supports R4, R4B, R5, and R6 (based on build features)

🎯 Type-Safe : Leverages Rust's type safety with a Pythonic interface

⚡ GIL-Friendly : the GIL is released during parsing and processing, so other Python threads stay responsive

📨 Flexible Input : ViewDefinitions and Bundles as Python dicts or pre-serialized JSON ( str / bytes )

Working with FHIR data in Python just got faster. pysof lets you:

Transform complex FHIR resources into clean, analyzable tables without writing custom parsers

Process large datasets efficiently with automatic parallel processing and Rust-level performance

Use standard SQL on FHIR ViewDefinitions for portable, maintainable data transformations

Export to multiple formats (CSV, JSON, NDJSON, Parquet) for analytics, ML, or reporting workflows

Perfect for healthcare data engineers, researchers, and developers building FHIR-based analytics pipelines.

From PyPI (Recommended)

Linux : x86_64 (glibc and musl)

Windows : x86_64 (MSVC)

macOS : AArch64 (Apple Silicon)

Python : 3.10, 3.11, 3.12, 3.13, 3.14

Download pre-built wheels from the releases page :

Transform FHIR patient data to CSV in just a few lines:

Multiple Output Formats

Remote resolve() (Trusted Servers)

resolve() dereferences references against the input bundle by default. You can optionally let it fetch references that point at explicitly trusted FHIR servers and fold them into the resolution pool before rows are generated. This is off by default and gated by a strict allowlist (matching scheme + host + port

path-prefix; private/loopback addresses are blocked unless opted in).

When config.is_active() is False (disabled or empty allowlist) these behave exactly like their non-remote counterparts. Enabling remote resolution makes output depend on remote server state at run time. See the SQL-on-FHIR guide for the full security model and configuration reference.

Streaming Large NDJSON Files

For memory-efficient processing of large NDJSON files, use the ChunkedProcessor iterator or process_ndjson_to_file function:

When to use streaming:

Processing NDJSON files larger than available memory

Working with datasets of 100K+ resources

Building ETL pipelines that process data incrementally

When you need fault-tolerant processing (skip invalid lines)

Automatic Parallel Processing

pysof automatically processes FHIR resources in parallel using rayon:

5-7x speedup on typical batch workloads with multi-core CPUs

Streaming benefits : ChunkedProcessor and process_ndjson_to_file also use parallel processing

Zero configuration - parallelization is always enabled

Python GIL released during parsing and processing, so other Python threads stay responsive

Because each call already fans out across all cores via rayon's shared thread pool, running pysof from multiple Python threads does not multiply throughput — one call can saturate the machine. Use Python threads for concurrency (overlapping I/O, serving requests), not to speed up transforms.

Pass Pre-Serialized JSON for Maximum Speed

If your data is already JSON text (from a file, an HTTP body, a database), pass the str or bytes directly instead of json.loads -ing it first:

This skips the Python-dict conversion entirely and parses the JSON with the GIL released — measured 20-27% faster per call on large bundles, with GIL hold time dropping from tens of milliseconds to microseconds.

Performance Benchmarks

Measured with scripts/bench_threading.py (a 7-column Patient ViewDefinition; Windows 11, 12 logical CPUs, Python 3.11, release build with mimalloc):

Numbers vary with hardware and ViewDefinition complexity — re-run scripts/bench_threading.py on your target machine.

Streaming mode ( ChunkedProcessor , process_ndjson_to_file ) keeps memory bounded by chunk_size regardless of input size, so it is recommended for large NDJSON files; batch mode holds the whole bundle and result in memory.

Controlling Thread Count (RAYON_NUM_THREADS)

Set the RAYON_NUM_THREADS environment variable to control parallel processing:

Or from the command line:

When to adjust thread count:

Reduce threads ( RAYON_NUM_THREADS=2-4 ): On shared systems, containers with CPU limits, or when running multiple instances

Increase threads : Rarely needed; rayon auto-detects available cores

Single thread ( RAYON_NUM_THREADS=1 ): For debugging or deterministic output ordering

Use all available cores for large datasets (default behavior)

Limit threads on shared systems to avoid resource contention

Prefer streaming mode ( ChunkedProcessor ) for NDJSON files > 100MB

R4 (default, always available)

R4B (if compiled with R4B feature)

R5 (if compiled with R5 feature)

R6 (if compiled with R6 feature)

Use pysof.get_supported_fhir_versions() to check available versions in your build.

Python 3.10 or later (3.10, 3.11, 3.12, 3.13, 3.14 supported)

uv (package and environment manager)

Rust toolchain (for building from source)

Note : This crate is excluded from the default workspace build. When running cargo build from the repository root, pysof will not be built automatically.

Note : This crate is excluded from the default workspace build. When running cargo build from the repository root, pysof will not be built automatically.

This crate is excluded from the default workspace build to allow building the core Rust components without Python. To build it explicitly:

Building with Maturin (Recommended)

For Python development, it's recommended to use maturin via uv :

Installing from Source

Requires Rust toolchain:

The project has separate test suites for Python and Rust components:

Run the comprehensive Python test suite:

Run the Rust unit and integration tests:

Configuring FHIR Version Support

Change Default FHIR Version

To change from R4 to another version (e.g., R5):

Edit crates/pysof/Cargo.toml : [ features ] default = [ " R5 " ] # Changed from ["R4"] R4 = [ " helios-sof/R4 " , " helios-fhir/R4 " ] R4B = [ " helios-sof/R4B " , " helios-fhir/R4B " ] R5 = [ " helios-sof/R5 " , " helios-fhir/R5 " ] R6 = [ " helios-sof/R6 " , " helios-fhir/R6 " ]

Edit crates/pysof/Cargo.toml :

Rebuild the extension : cd crates/pysof uv run maturin develop --release

Rebuild the extension :

Verify the change : uv run python -c " import pysof versions = pysof.get_supported_fhir_versions() print('Supported FHIR versions:', versions) " This should now show ['R5'] instead of ['R4'] .

This should now show ['R5'] instead of ['R4'] .

Enable Multiple FHIR Versions

To support multiple FHIR versions simultaneously:

Edit crates/pysof/Cargo.toml : [ features ] default = [ " R4 " , " R5 " ] # Enable both R4 and R5 # Or enable all versions: # default = ["R4", "R4B", "R5", "R6"]

Edit crates/pysof/Cargo.toml :

Rebuild and verify : uv run maturin develop --release uv run python -c " import pysof; print(pysof.get_supported_fhir_versions()) " This should show ['R4', 'R5'] (or all enabled versions).

This should show ['R4', 'R5'] (or all enabled versions).

Use specific versions in code : import pysof # Use R4 explicitly result_r4 = pysof . run_view_definition ( view , bundle , "json" , fhir_version = "R4" ) # Use R5 explicitly result_r5 = pysof . run_view_definition ( view , bundle , "json" , fhir_version = "R5" )

Use specific versions in code :

Build with Specific Features (Without Changing Default)

To temporarily build with different features without modifying Cargo.toml :

Testing After Version Changes

After changing FHIR version support, run the test suite to ensure compatibility:

MIT License - See LICENSE.md for details.

Copyright (c) 2025 Helios Software

Contributions are welcome! Please see our Contributing Guidelines for details.

Bug Reports : GitHub Issues

Security Issues : Email team@heliossoftware.com

See the Development section above for instructions on setting up your development environment.

PyO3 - Rust bindings for Python

maturin - Build system for Rust Python extensions

helios-sof - Core SQL-on-FHIR implementation in Rust

Part of the Helios FHIR Server project.

Made with ❤️ by Helios Software

Extracted Entities

Domains (1)

Industries (1)

Platforms (3)

Tools (1)