# Does Flower support differential privacy?

**URL:** <https://discuss.flower.ai/t/does-flower-support-differential-privacy/93>\
**Category:** Privacy & Security\
**Tags:** faq\
**Created:** [February 26, 2024, 8:58am UTC](https://discuss.flower.ai/t/does-flower-support-differential-privacy/93 "2024-02-26T08:58:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![flower](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/flower/32/17_2.png) [@flower](https://discuss.flower.ai/u/flower)\
**Post date:** [February 26, 2024, 8:58am UTC](https://discuss.flower.ai/t/does-flower-support-differential-privacy/93/1 "2024-02-26T08:58:19Z")

</div>

**A frequently asked question we get is:**

Does Flower support differential privacy? 🔒

---

<div class="post-metadata">

**Author:** ![mohammad](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/mohammad/32/35_2.png) [@mohammad](https://discuss.flower.ai/u/mohammad)\
**Post date:** [February 29, 2024, 5:19pm UTC](https://discuss.flower.ai/t/does-flower-support-differential-privacy/93/2 "2024-02-29T17:19:30Z")

</div>

Flower supports central differential privacy (known as user-level DP) and local DP. In central DP, the noising part is on the server side, with options for fixed and adaptive clipping. The clipping phase can be decided to be on the client or server side. For example, if you want to implement it with server-side fixed clipping:

```auto
from flwr.server.strategy.dp_fixed_clipping import DifferentialPrivacyServerSideFixedClipping
# Configure the strategy
strategy = fl.server.strategy.FedAvg( ... )
# Wrap the strategy with the DifferentialPrivacyServerSideFixedClipping wrapper
dp_strategy = DifferentialPrivacyServerSideFixedClipping(strategy, cfg.noise_multiplier, cfg.clipping_norm, cfg.num_sampled_clients)

```

Moreover, if you want to perform it with client-side fixed clipping:

```auto
# Server-side:
from flwr.server.strategy.dp_fixed_clipping import DifferentialPrivacyClientSideFixedClipping
# Configure the strategy
strategy = fl.server.strategy.FedAvg( ... )
# Wrap the strategy with the DifferentialPrivacyClientSideFixedClipping wrapper
dp_strategy = DifferentialPrivacyClientSideFixedClipping(strategy, cfg.noise_multiplier, cfg.clipping_norm, cfg.num_sampled_clien

```

```auto

# Client-side:
from flwr.client.mod.centraldp_mods import fixedclipping_mod
# Add fixedclipping_mod to the client-side mods
app = fl.client.ClientApp(client_fn=client_fn, mods=[fixedclipping_mod])

```

For local DP, LocalDpMod can be utilized where it clips the client model updates and adds noise to the params before sending them to the server:

```auto
local_dp_mod = LocalDpMod( ... )
app = fl.client.ClientApp(client_fn=client_fn, mods=[local_dp_mod])

```

Furthermore, for sample-level DP, privacy engines like Opacus and TensorFlowPrivacy can be used on the client side. You can refer to examples of such implementations in the repository.

For more info, please refer to Flower docs about differential privacy.

---

<div class="post-metadata">

**Author:** ![flower](https://dub1.discourse-cdn.com/flex013/user_avatar/discuss.flower.ai/flower/32/17_2.png) [@flower](https://discuss.flower.ai/u/flower)\
**Post date:** [March 1, 2024, 11:05am UTC](https://discuss.flower.ai/t/does-flower-support-differential-privacy/93/3 "2024-03-01T11:05:34Z")

</div>

Closed on March 1, 2024, 11:05am UTC


