distributed-state-network
Distributed State Network (DSN) is a Python framework for distributed applications. Each node sends its state to the other nodes automatically. An application does not send a request for the data.
Basis
DSN is a helper for Language Pipes. It is the default technology for shared state in Language Pipes. Two research documents give the basis of the design.
The Maintenance of Duplicate Databases (Paul R. Johnson, Robert H. Thomas)
Language Pipes needs a distributed database. This document was the first to describe direct mail updates. DSN uses this method.
Epidemic algorithms in replicated databases (extended abstract)
DSN uses a simple form of the gossip protocol from this paper. Each node does a check of the health of its connections every 3 seconds. At each check, the node selects one peer at random and sends an update to that peer. The paper shows that this method gives the best ratio of complexity to benefit. Thus all the nodes become synchronized after a short time. DSN operates on a local network, where the loss of packets is not frequent.
Quick start
1. Create the first node
The most simple DSN network has one node. To create this node, do these steps:
- Import
DSNodeServerandDSNodeConfig. - Set
bootstrap_nodesto an empty list. The first node in a network has no bootstrap node. - Start the node with
DSNodeServer.start(). - Write the data to the state of the node with
update_data().
from distributed_state_network import DSNodeServer, DSNodeConfig
def alert(message: str) -> None:
print(message)
# Start a node
node = DSNodeServer.start(
DSNodeConfig.from_dict({
"node_id": "my_first_node",
"port": 8000,
"bootstrap_nodes": [] # Empty for the first node
}),
alert
)
# Write some data
node.update_data("status", "online")
node.update_data("temperature", "72.5")
How it works
DSN makes a peer-to-peer network. Each node keeps its own state database.
Key concepts:
- Each node owns its state. Only that node can change its state.
- The node sends each change of its state to all the connected nodes automatically.
- A node can read the state of each other node immediately.
- The nodes can encrypt all communication with AES-128-CBC. Each message has a new random IV.
Example: a distributed temperature monitor
This example shows a network of temperature sensors. Each sensor writes its temperature to its own state. The monitor station reads the temperature from each sensor.
Do these steps on each Raspberry Pi that has a sensor:
sensor_node = DSNodeServer.start(
DSNodeConfig.from_dict({
"node_id": f"sensor_{location}",
"port": 8000,
"bootstrap_nodes": [{"address": "coordinator.local", "port": 8000}]
}),
alert
)
# Update the temperature every 60 seconds
while True:
temp = read_temperature_sensor()
sensor_node.update_data("temperature", str(temp))
sensor_node.update_data("timestamp", str(time.time()))
time.sleep(60)
Do this step on the monitor station:
for node_id in monitor.peers():
if node_id.startswith("sensor_"):
temp = monitor.read_data(node_id, "temperature")
print(f"{node_id}: {temp}°F")
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 distributed_state_network-1.2.0.tar.gz.
File metadata
- Download URL: distributed_state_network-1.2.0.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4993e6053fed178a9ab9d8b575abe7c24cc2b0e6c01334201fd6d9981473f4a8
|
|
| MD5 |
4aadb0d3e11401b03f1c79dd5e069f5b
|
|
| BLAKE2b-256 |
f1863a961a02de6bcfa39e03627b2942f0ca984c41ec7883f53cb3db3d45800b
|
Provenance
The following attestation bundles were made for distributed_state_network-1.2.0.tar.gz:
Publisher:
publish-packages.yml on erinclemmer/language-pipes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
distributed_state_network-1.2.0.tar.gz -
Subject digest:
4993e6053fed178a9ab9d8b575abe7c24cc2b0e6c01334201fd6d9981473f4a8 - Sigstore transparency entry: 2401637509
- Sigstore integration time:
-
Permalink:
erinclemmer/language-pipes@d7208076595a18ec000731f83caff81602778a0e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/erinclemmer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-packages.yml@d7208076595a18ec000731f83caff81602778a0e -
Trigger Event:
push
-
Statement type:
File details
Details for the file distributed_state_network-1.2.0-py3-none-any.whl.
File metadata
- Download URL: distributed_state_network-1.2.0-py3-none-any.whl
- Upload date:
- Size: 21.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c07e73dda614e0d75412ae18bce6104b54cb27ccc51c04e56e0280ced1c115d
|
|
| MD5 |
25081aa7ad47762572afff272248add7
|
|
| BLAKE2b-256 |
c88d0ab45d276167995f9d1b4f6f46054d5ef9ea76e8e3c54ecf050030f23d1e
|
Provenance
The following attestation bundles were made for distributed_state_network-1.2.0-py3-none-any.whl:
Publisher:
publish-packages.yml on erinclemmer/language-pipes
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
distributed_state_network-1.2.0-py3-none-any.whl -
Subject digest:
9c07e73dda614e0d75412ae18bce6104b54cb27ccc51c04e56e0280ced1c115d - Sigstore transparency entry: 2401637609
- Sigstore integration time:
-
Permalink:
erinclemmer/language-pipes@d7208076595a18ec000731f83caff81602778a0e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/erinclemmer
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-packages.yml@d7208076595a18ec000731f83caff81602778a0e -
Trigger Event:
push
-
Statement type: