BranchKey Python Client
Official Python client for the BranchKey federated learning and analytics platform. Upload model weights, compute and upload federated analytics, download aggregated results, and track training runs — without raw data leaving your site.
Full documentation: app.branchkey.com/docs. This page is the short version.
3.0.0 is a breaking release. The AMQP/RabbitMQ transport is gone; WebSocket is the only transport and needs no configuration. Drop any
rabbitmq_configoruse_websocketargument — both now raiseTypeError. Nothing else changed.pip install "branchkey<3"pins the previous behaviour.
Installation
pip install branchkey
Requires Python 3.10 or higher (tested on 3.10 – 3.14).
Quick start
Create a leaf entity on the platform to obtain its credentials — see Getting started → Access and setup.
from branchkey import Client, Credentials
client = Client(
Credentials(
id="your-leaf-uuid",
name="my-client",
session_token="your-session-token-uuid",
owner_id="your-user-uuid",
tree_id="your-tree-uuid",
branch_id="your-branch-uuid",
)
)
# 1. Upload this round's model weights.
# `weighting` is this site's influence during aggregation — usually the
# number of training samples. `parameters` is a list of numpy arrays.
file_path = client.save_weights("model_weights", weighting=1000, parameters=parameters)
file_id = client.file_upload(file_path)
# 2. Wait for the aggregated result and download it.
aggregation_id = client.queue.get(block=True)
client.file_download(aggregation_id) # -> {client.output_dir}/{aggregation_id}.npz
client.queue.get(block=False) polls instead of blocking, and
client.get_latest_aggregation_id() returns the most recent notification or None.
The downloaded archive contains the aggregated layers only, under the keys layer_0,
layer_1, …, with no weighting field:
import numpy as np
npz = np.load(f"{client.output_dir}/{aggregation_id}.npz")
parameters = [npz[k] for k in sorted(npz.files) if k.startswith("layer_")]
Federated analytics
Federated analytics answers a question about the data itself — "what is the mean age across
the federation?" — with no model trained. Hand save_analytics a raw column and the SDK
reduces it to six combinable numbers before anything is written to disk or sent over the
wire:
file_path = client.save_analytics(
{
"age": patients["age"].to_numpy(),
"tumour_volume": patients["volume"].to_numpy(),
}
)
file_id = client.file_upload(file_path)
The archive holds six entries per column, and nothing else:
age -> age_n, age_sum, age_sumsq, age_min, age_max, age_nan
n is the count, sum is Σx, sumsq is Σx², min/max are the extremes, and nan is how
many values were missing and left out. Not a single patient's age is in the file. That is
a property of the library, not a request made of you: there is no argument that turns it off.
Sums are sent rather than statistics because sums combine across sites and statistics do not
— two sites each reporting a variance of zero can pool to a variance of 1600. From the
bundle the platform derives count, sum, min, max, range, mean, variance and standard
deviation, all exact. Columns must be 1-D and numeric; NaN is dropped by default and counted
in _nan.
Already computed the number yourself — a preprocessing planner's output, a label histogram? Send
it with save_fields instead, and choose its combining operation in the branch configuration.
Where to go next
| Topic | Link |
|---|---|
| Getting access and your first leaf | Access and setup |
| Federated analytics in full, with worked examples | Concepts → Federated analytics |
save_fields, per-field combining operations |
Per-field aggregation |
| Branch settings, aggregation strategy, run control | Configuring a branch |
| Client configuration, retries, proxies, framework examples | Documentation home |
| Common questions and troubleshooting | FAQ |
Support
- Documentation: app.branchkey.com/docs
- Website: branchkey.com
- Email: info@branchkey.com
Licence
GPL-3.0 — the full text ships with the package as
LICENSE.
BranchKey — Federated Learning Platform
Metadata
Release files for branchkey 3.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| branchkey-3.0.1.tar.gz | 32.1 kB | Without provenance | Details for branchkey-3.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| branchkey-3.0.1-py3-none-any.whl | Python 3 | none | any | Details for branchkey-3.0.1-py3-none-any.whl |
Total release size: 64.1 kB
Release files / branchkey-3.0.1.tar.gz
| Download URL | branchkey-3.0.1.tar.gz |
|---|---|
| Size | 32.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
883662eb1fe3a5c4ff74c7479d002fca3c39e23bbbc8e859ef6d12dc8cfadb76
|
|
BLAKE2b-256 checksum How to use checksums |
340688d79b8e33143a3c801953dca5a602bdf908f74b8b5f7a29dd8d801c4375
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / branchkey-3.0.1-py3-none-any.whl
| Download URL | branchkey-3.0.1-py3-none-any.whl |
|---|---|
| Size | 32.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ee72e4e98d419edaa6c54329a66e2b24ac43c34ea7261832aabed06de967cad9
|
|
BLAKE2b-256 checksum How to use checksums |
e566df0978388c0fe24af9f392d010ffe08bad42782b5486ccff30704de2837f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for branchkey 3.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.