About flip-utils
flip-utils is the pip-installable distribution published from this repository. Its Python import package is flip, which contains the shared platform logic used by FLIP jobs and services including core training logic, NVFLARE components, Flower helpers, and utility helpers.
The FLIP platform uses this package to power federated learning applications across multiple job types: standard federated training, distributed evaluation, diffusion model training, and custom federated optimization.
Installation
Install the published package from PyPI:
pip install flip-utils
# or with uv
uv add flip-utils
To use the latest development version, clone the monorepo and install from source:
git clone https://github.com/londonaicentre/FLIP.git
cd FLIP/flip-utils
uv sync
# or
pip install .
To build a distributable wheel for development:
uv build
Package Structure & Modules
The flip package is organized into logical modules:
- flip.core
Core classes and abstractions:
FLIPBase — Abstract base class with common FL logic
FLIPStandardProd — Production implementation using FLIP platform APIs
FLIPStandardDev — Development implementation using local CSV/filesystem
FLIP() factory — Automatically selects the correct implementation based on environment
- flip.constants
Configuration and enumerations:
FlipConstants — Pydantic-settings configuration singleton
ResourceType — Enum for imaging resource types (DICOM, NIFTI, etc.)
ModelStatus — Enum for model training states
JobType — Enum for supported FL job types
PTConstants — PyTorch-specific constants and settings
- flip.utils
Utility helpers:
Utils — General utility functions
model_weights_handling — Model weight aggregation and manipulation
- flip.nvflare
NVFLARE-specific components:
controllers/ — Workflow controllers (ScatterAndGather, CrossSiteModelEval, etc.)
components/ — Event handlers, persistors, privacy filters, model locators, etc.
recipes/ — High-level NVFLARE job recipes
runtime.py — Runtime helpers for NVFLARE apps
metrics.py — Metrics collection and reporting
- flip.flower
Flower-specific helpers:
strategy.py — Flower Strategy implementations (e.g. FedAvgWithClientMetrics)
metrics.py — Server-side metrics collection and reporting for Flower runs
progress.py — Progress/status reporting helpers for Flower runs
Using the FLIP Factory
The FLIP() factory automatically selects between development and production implementations based on the LOCAL_DEV environment variable:
from flip import FLIP
# Uses FLIPStandardProd in production or FLIPStandardDev in local dev
flip = FLIP()
df = flip.get_dataframe(project_id, query)
See the API reference for detailed method documentation.
Job Types
Pass the job type to the FLIP() factory (FLIP(job_type=...)). The JobType enum (flip.constants.job_types) defines the values recognised by FLIP():
Type |
Description |
|---|---|
standard |
Federated training with FedAvg aggregation (default) |
evaluation |
Distributed model evaluation without training |
diffusion_model |
Two-stage training: VAE encoder followed by diffusion model training |
fed_opt |
Custom federated optimization with flexible aggregation strategies |
The NVFLARE backend additionally ships a template directory under fl-apps/nvflare/ for each Client-API job type (standard, evaluation, diffusion_model, fed_opt); the template names match the JobType enum values above. The Flower backend ships its own standard and evaluation templates under fl-apps/flower/ — selected at the deploy layer by FL_BACKEND=flower.
User Application Requirements
The job components dynamically import user-provided code from the job’s custom/ directory. On the platform that directory is assembled by the FL API, which merges the uploaded app files onto the matching fl-apps/nvflare/<template>/app template; in local SimEnv runs the tutorial’s job.py stages its app_files/ into the job’s custom/ directly.
File |
Description |
|---|---|
trainer.py |
Training logic — a plain nvflare.client script |
validator.py |
Extra validation module where the job type requires one |
models.py |
Model definitions — must export get_model() function |
config.json |
Hyperparameters — must include LOCAL_ROUNDS and LEARNING_RATE |
transforms.py |
Data transforms (optional) |
Development Mode
To test FL applications locally before deploying to production:
Set environment variables in .env.development:
LOCAL_DEV=true DEV_IMAGES_DIR=../data/accession-resources DEV_DATAFRAME=../data/sample_get_dataframe.csvPlace your application files in the tutorial’s app_files/ directory (e.g. fl-tutorials/nvflare/image_classification/xray_classification/app_files/). On the platform they are merged onto the matching fl-apps/nvflare/<template>/app/ template at submit time.
Run one of the shipped tutorials against the NVFLARE simulator from the repository root:
make -C fl-tutorials run-tutorial TUTORIAL=xray_classification # list every available tutorial with: make -C fl-tutorials list-tutorialsEach tutorial’s make run delegates to make sim — its job.py driving a FLIP recipe on the NVFLARE simulator (SimEnv) from the flip-utils venv — configured per-tutorial via that tutorial’s .env.app.
Running Tests
Run unit tests for the flip package:
make unit-test
# or
uv run pytest -s -vv
Tests use pytest with coverage reporting and are located in tests/unit/.
Building the Docs Locally
flip-utils is documented as part of the FLIP documentation. From the repository root, run:
cd docs && make docs
The generated HTML site will be written to docs/build/html. To clean previous builds:
cd docs && make clean
How the API Reference is Generated
The API reference is built with sphinx-autoapi and points directly at the flip/ source tree. That keeps the reference pages aligned with the code without maintaining hand-written module stubs. See the API Reference section of the built documentation for complete coverage of all public classes and functions.
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 flip_utils-0.5.0.tar.gz.
File metadata
- Download URL: flip_utils-0.5.0.tar.gz
- Upload date:
- Size: 105.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
409d6b7df1ade844d250d8d5bcfc9200edd8914ad66af7b990a90167f470b1ca
|
|
| MD5 |
d2480bc79829c773ec044fd2c26dfaac
|
|
| BLAKE2b-256 |
f51e809b1b0aac6e49af8dc98c336428e5d96121dfa49289010b07107a6bab26
|
File details
Details for the file flip_utils-0.5.0-py3-none-any.whl.
File metadata
- Download URL: flip_utils-0.5.0-py3-none-any.whl
- Upload date:
- Size: 149.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
884f21317875947d2bc9eda0b2dc102721b4dff1357652bc15d8b193d2299f44
|
|
| MD5 |
34242b6a2777d8dbc580700f83aa2e10
|
|
| BLAKE2b-256 |
d16d5670680ec789cb3bff2a0c1979ca16078cf2123999dcb358c7aa1fc11476
|