ReferenceClientAdvancedWrite Authorities

Write Authorities

Dynamic control handoff with write authorities for concurrent access.

Writers support dynamic control handoff. Multiple writers can be opened on a channel at the same time, but only one writer is allowed to write to the channel. To determine which writer has control, an authority from 0 to 255 is assigned to each writer (or, optionally, each channel in the writer). The writer with the highest authority will be allowed to write. If two writers have the same authority, the writer that opened first will be allowed to write. For more information, see the concepts page.

By default, writers are opened with an authority of ABSOLUTE (255). This means that no other writers can write to the channel as long as the writer is open.

Same Authority on All Channels

To open a writer with the same authority on all channels, pass the authorities parameter with an integer.

Python

TypeScript

writer = client.open_writer(
    start=sy.TimeStamp.now(),
    channels=["time", "temperature"],
    authorities=100,
)

Different Authorities per Channel

To open a writer with different authorities on each channel, pass the authorities parameter with a list of integers. This list must be the same length as the number of channels in the writer.

Python

TypeScript

writer = client.open_writer(
    start=sy.TimeStamp.now(),
    channels=["time", "temperature"],
    authorities=[100, 200],
)

Adjusting Authority After Open

To change the authority of a writer during operation, use the set_authority method.

Python

TypeScript

# Set the authority on all channels
writer.set_authority(200)

# Set the authority on specific channels
writer.set_authority({
    "time": 150,
    "temperature": 250,
})

Here’s a complete example showing dynamic authority changes during a write session:

Python

TypeScript

with client.open_writer(
    start=sy.TimeStamp.now(),
    channels=["time", "temperature"],
    authorities=100,
) as writer:
    # Start with low authority
    writer.write({"time": sy.TimeStamp.now(), "temperature": 25.0})

    # Increase authority to take control from other writers
    writer.set_authority(200)
    writer.write({"time": sy.TimeStamp.now(), "temperature": 26.0})

    # Release control by lowering authority
    writer.set_authority(50)