Skip to content

Send data

nebra.send(event, reuse_session=True)

Send an event to the AT Protocol. The NEBRA_HANDLE and NEBRA_PASSWORD environment variables must be set to the handle and app password of your AT Protocol account. In addition, NEBRA_BASE_URL should be set to the base URL of your AT Protocol PDS if you are not on a Bluesky PDS (e.g., https://eurosky.social).

Parameters:

Name Type Description Default
event dict

The event to send, which must include a "$type" field.

required
reuse_session bool

Whether to reuse an existing session if available. Defaults to True.

True
Source code in nebra/client.py
def send(event: dict, reuse_session: bool = True):
    """Send an event to the AT Protocol. The NEBRA_HANDLE and NEBRA_PASSWORD environment
    variables must be set to the handle and app password of your AT Protocol account. In
    addition, NEBRA_BASE_URL should be set to the base URL of your AT Protocol PDS if
    you are not on a Bluesky PDS (e.g., https://eurosky.social).

    Parameters
    ----------
    event : dict
        The event to send, which must include a "$type" field.
    reuse_session : bool, optional
        Whether to reuse an existing session if available. Defaults to True.
    """
    handle, password, base_url = get_credentials()
    client = get_client(
        handle, password, base_url=base_url, reuse_session=reuse_session
    )

    # Encode floating point numbers before sending
    encoded_event = encode_floats_in_event(event)

    client.com.atproto.repo.create_record(
        models.ComAtprotoRepoCreateRecord.Data(
            collection=encoded_event["$type"], record=encoded_event, repo=handle#, validate=True
        )
    )