Skip to main content

Python Open-source package for simulating federated learning and differential privacy

Project description

MEDfl: A Collaborative Framework for Federated Learning in Medicine

Python Versions License: GPL v3 Build Status Contributors PyPI version Downloads


📚 Table of Contents

  1. Introduction
  2. Key Features
  3. Installation
  4. Modes of Operation
  5. Quick Start
  6. Documentation
  7. Contributing
  8. Acknowledgment
  9. Authors

1. Introduction

MEDfl is an open-source Federated Learning (FL) framework designed for both simulation and real-world distributed trainingin the medical and healthcare domains. It integrates Differential Privacy (DP), Transfer Learning (TL), and secure communication to enable privacy-preserving model training across multiple institutions—particularly suited for medical and clinical data.


2. Key Features

  • 🧩 Two Operation Modes

    • Simulation Mode: Run FL experiments locally for testing and benchmarking.
    • Real-World Mode: Connect remote clients for production-grade FL.
  • 🔒 Differential Privacy (Opacus Integration)
    Ensures client updates are mathematically protected against data leakage.

  • 🧠 Transfer Learning Integration
    Improve convergence and accuracy in small or heterogeneous datasets.

  • ⚙️ Modular Design
    Plug-and-play components for models, optimizers, datasets, and aggregation strategies.


3. Installation

pip install medfl

✅ Requires Python 3.9+.

If you prefer the development version:

git clone https://github.com/MEDomics-UdeS/MEDfl.git
cd MEDfl
pip install -e .

4. Modes of Operation

Mode Description Typical Use Case
Simulation FL Runs all clients locally in a controlled environment. Benchmarking, debugging, or prototyping.
Real-World FL Connects distributed client machines. Multi-institution collaboration, production deployments.

5. Quick Start

🌍 Real-World Federated Learning Example

Server Setup

from MEDfl.rw.server import FederatedServer, Strategy

custom_strategy = Strategy(
    name="FedAvg",
    fraction_fit=1,
    min_fit_clients=1,
    min_evaluate_clients=1,
    min_available_clients=1,
    local_epochs=1,
    threshold=0.5,
    learning_rate=0.01,
    optimizer_name="SGD",
    saveOnRounds=3,
    savingPath="./",
    total_rounds=10,
    datasetConfig={"isGlobal": True, "globalConfig": {"target": "label", "testFrac": 0.2}},
)

server = FederatedServer(
    host="0.0.0.0",
    port=8080,
    num_rounds=10,
    strategy=custom_strategy,
)
server.start()

Client Setup

from MEDfl.rw.client import FlowerClient, DPConfig

# Example: XGBoost client
xgb_params = {
    "objective": "binary:logistic",
    "eval_metric": "logloss",
    "eta": 0.1,
    "max_depth": 6,
    "subsample": 0.8,
    "colsample_bytree": 0.8,
    "tree_method": "hist",  # GPU: "gpu_hist"
}

client = FlowerClient(
    server_address="100.65.215.27:8080",
    data_path="../data/client1.csv",
    dp_config=None,            # DP only applies to neural networks
    model_type="xgb",
    xgb_params=xgb_params,
    xgb_rounds=10,
)
client.start()

💡 Tip:
Use Tailscale to connect clients and server under the same secure VPN for real-world deployments.


6. Documentation

You can generate and host the documentation locally with Sphinx:

cd docs
make clean && make html
cd _build/html
python -m http.server

7. Contributing

We welcome contributions of all kinds — from bug fixes to new modules.

  1. Fork the repo and create a feature branch.
  2. Run tests and format your code with black and flake8.
  3. Submit a Pull Request with clear details on your changes.

8. Acknowledgment

MEDfl is part of the MEDomicsLab initiative at the Université de Sherbrooke.
It was developed to enable secure, privacy-preserving, and reproducible machine learning across distributed medical datasets.


9. Authors


If you find this project useful, please consider starring it on GitHub to support continued development.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

MEDfl-2.0.5.dev0.tar.gz (31.8 MB view details)

Uploaded Source

Built Distributions

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

medfl-2.0.5.dev0-py3-none-any.whl (67.1 kB view details)

Uploaded Python 3

MEDfl-2.0.5.dev0-py3-none-any.whl (68.7 kB view details)

Uploaded Python 3

File details

Details for the file MEDfl-2.0.5.dev0.tar.gz.

File metadata

  • Download URL: MEDfl-2.0.5.dev0.tar.gz
  • Upload date:
  • Size: 31.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for MEDfl-2.0.5.dev0.tar.gz
Algorithm Hash digest
SHA256 597097006fb08794204944314e8c0d7983e64f22482c8e932b36e70c0be9dbe7
MD5 cdadbc3f93760f4eb2533552afb7844f
BLAKE2b-256 20fe8c47fc2ce28d0f1fd85da5b131d43bf5332f96293c8a818af37a38660310

See more details on using hashes here.

File details

Details for the file medfl-2.0.5.dev0-py3-none-any.whl.

File metadata

  • Download URL: medfl-2.0.5.dev0-py3-none-any.whl
  • Upload date:
  • Size: 67.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for medfl-2.0.5.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 651ff39f92f9aca93e7230a818f78b1221a65dafd5dc51693c94572883516582
MD5 8199a5f0bef562444c47b52982731733
BLAKE2b-256 5d3231a87c91b31788b21c71ee3f2a5f510d2770d95c10ede989983a989742b7

See more details on using hashes here.

File details

Details for the file MEDfl-2.0.5.dev0-py3-none-any.whl.

File metadata

  • Download URL: MEDfl-2.0.5.dev0-py3-none-any.whl
  • Upload date:
  • Size: 68.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for MEDfl-2.0.5.dev0-py3-none-any.whl
Algorithm Hash digest
SHA256 69875fb311201716b5f6a46da821d01e7b10c7518f156f7200cf0557312349af
MD5 1cd8ee1ed62e4aa13f15a4ab6f551b19
BLAKE2b-256 6fda18dfd218b192db289b6ecb38892bd82f3d0a9e885cab5aedb1da3d360b37

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page