Skip to main content

A client library for accessing Liveblocks API

Project description

Liveblocks Python SDK

The Python SDK for Liveblocks provides you with a client for accessing Liveblocks APIs. This library is complementary to the front end libraries provided by Liveblocks.

Installation

Install the Liveblocks package to get started.

pip install liveblocks

Quickstart

All API calls require a Liveblocks client set up with your secret key. Find your key in the Liveblocks Dashboard.

Synchronous

from liveblocks import Liveblocks

client = Liveblocks(secret="{{SECRET_KEY}}")

with client:
    rooms = client.get_rooms()
    print(rooms)

Asynchronous

from liveblocks import AsyncLiveblocks

client = AsyncLiveblocks(secret="{{SECRET_KEY}}")

async with client:
    rooms = await client.get_rooms()
    print(rooms)

API Reference

Room

get_rooms

This endpoint returns a list of your rooms. The rooms are returned sorted by creation date, from newest to oldest. You can filter rooms by room ID prefixes, metadata, users accesses, and groups accesses. Corresponds to liveblocks.getRooms.

There is a pagination system where the cursor to the next page is returned in the response as nextCursor, which can be combined with startingAfter. You can also limit the number of rooms by query.

Filtering by metadata works by giving key values like metadata.color=red. Of course you can combine multiple metadata clauses to refine the response like metadata.color=red&metadata.type=text. Notice here the operator AND is applied between each clauses.

Filtering by groups or userId works by giving a list of groups like groupIds=marketing,GZo7tQ,product or/and a userId like userId=user1. Notice here the operator OR is applied between each groupIds and the userId.

Example

result = client.get_rooms(
    # limit=20,
    # starting_after="eyJjcmVhdGVkQXQiOjE2NjAwMDA5ODgxMzd9",
    # organization_id="org_123456789",
    # query="metadata[\"color\"]:\"blue\"",
    # user_id="user-123",
    # group_ids="group1,group2",
)
print(result)

Parameters:

Name Type Required Description
limit int | Unset No A limit on the number of rooms to be returned. The limit can range between 1 and 100, and defaults to 20. (default: 20)
starting_after str | Unset No A cursor used for pagination. Get the value from the nextCursor response of the previous page.
organization_id str | Unset No A filter on organization ID.
query str | Unset No Query to filter rooms. You can filter by roomId and metadata, for example, metadata["roomType"]:"whiteboard" AND roomId^"liveblocks:engineering". Learn more about filtering rooms with query language.
user_id str | Unset No A filter on users accesses.
group_ids str | Unset No A filter on groups accesses. Multiple groups can be used.

create_room

This endpoint creates a new room. id and defaultAccesses are required. When provided with a ?idempotent query argument, will not return a 409 when the room already exists, but instead return the existing room as-is. Corresponds to liveblocks.createRoom, or to liveblocks.getOrCreateRoom when ?idempotent is provided.

  • defaultAccesses could be [] or ["room:write"] (private or public).
  • metadata could be key/value as string or string[]. metadata supports maximum 50 entries. Key length has a limit of 40 characters maximum. Value length has a limit of 256 characters maximum. metadata is optional field.
  • usersAccesses could be [] or ["room:write"] for every records. usersAccesses can contain 1000 ids maximum. Id length has a limit of 256 characters. usersAccesses is optional field.
  • groupsAccesses are optional fields.

Example

from liveblocks.models import CreateRoomRequestBody

result = client.create_room(
    body=CreateRoomRequestBody(
        id="...",
        default_accesses=[],
        # organization_id="...",
        # users_accesses=...,
        # groups_accesses=...,
    ),
    # idempotent=True,
)
print(result)

Parameters:

Name Type Required Description
idempotent bool | Unset No When provided, will not return a 409 when the room already exists, but instead return the existing room as-is. Corresponds to liveblocks.getOrCreateRoom.
body CreateRoomRequestBody Yes Request body (application/json)

get_room

This endpoint returns a room by its ID. Corresponds to liveblocks.getRoom.

Example

result = client.get_room(
    room_id="my-room-id",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room

update_room

This endpoint updates specific properties of a room. Corresponds to liveblocks.updateRoom.

It’s not necessary to provide the entire room’s information. Setting a property to null means to delete this property. For example, if you want to remove access to a specific user without losing other users: { "usersAccesses": { "john": null } } defaultAccesses, metadata, usersAccesses, groupsAccesses can be updated.

  • defaultAccesses could be [] or ["room:write"] (private or public).
  • metadata could be key/value as string or string[]. metadata supports maximum 50 entries. Key length has a limit of 40 characters maximum. Value length has a limit of 256 characters maximum. metadata is optional field.
  • usersAccesses could be [] or ["room:write"] for every records. usersAccesses can contain 1000 ids maximum. Id length has a limit of 256 characters. usersAccesses is optional field.
  • groupsAccesses could be [] or ["room:write"] for every records. groupsAccesses can contain 1000 ids maximum. Id length has a limit of 256 characters. groupsAccesses is optional field.

Example

from liveblocks.models import UpdateRoomRequestBody

result = client.update_room(
    room_id="my-room-id",
    body=UpdateRoomRequestBody(
        # default_accesses=[],
        # users_accesses=...,
        # groups_accesses=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
body UpdateRoomRequestBody Yes Request body (application/json)

delete_room

This endpoint deletes a room. A deleted room is no longer accessible from the API or the dashboard and it cannot be restored. Corresponds to liveblocks.deleteRoom.

Example

client.delete_room(
    room_id="my-room-id",
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room

prewarm_room

Speeds up connecting to a room for the next 10 seconds. Use this when you know a user will be connecting to a room with RoomProvider or enterRoom within 10 seconds, and the room will load quicker. Corresponds to liveblocks.prewarmRoom.

Example

client.prewarm_room(
    room_id="my-room-id",
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room

upsert_room

This endpoint updates specific properties of a room. Corresponds to liveblocks.upsertRoom.

It’s not necessary to provide the entire room’s information. Setting a property to null means to delete this property. For example, if you want to remove access to a specific user without losing other users: { "usersAccesses": { "john": null } } defaultAccesses, metadata, usersAccesses, groupsAccesses can be updated.

  • defaultAccesses could be [] or ["room:write"] (private or public).
  • metadata could be key/value as string or string[]. metadata supports maximum 50 entries. Key length has a limit of 40 characters maximum. Value length has a limit of 256 characters maximum. metadata is optional field.
  • usersAccesses could be [] or ["room:write"] for every records. usersAccesses can contain 1000 ids maximum. Id length has a limit of 256 characters. usersAccesses is optional field.
  • groupsAccesses could be [] or ["room:write"] for every records. groupsAccesses can contain 1000 ids maximum. Id length has a limit of 256 characters. groupsAccesses is optional field.

Example

from liveblocks.models import UpsertRoomRequestBody

result = client.upsert_room(
    room_id="my-room-id",
    body=UpsertRoomRequestBody(
        update=...,
        # create=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
body UpsertRoomRequestBody Yes Request body (application/json)

update_room_id

This endpoint permanently updates the room’s ID. All existing references to the old room ID will need to be updated. Returns the updated room. Corresponds to liveblocks.updateRoomId.

Example

result = client.update_room_id(
    room_id="my-room-id",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes The new ID for the room
body UpdateRoomIdRequestBody | Unset No Request body (application/json)

update_room_organization_id

This endpoint updates the room's organization ID. The fromOrganizationId must match the room's current organization ID. Returns the updated room.

Example

result = client.update_room_organization_id(
    room_id="my-room-id",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes The ID of the room
body UpdateRoomOrganizationIdRequestBody | Unset No Request body (application/json)

get_active_users

This endpoint returns a list of users currently present in the requested room. Corresponds to liveblocks.getActiveUsers.

For optimal performance, we recommend calling this endpoint no more than once every 10 seconds. Duplicates can occur if a user is in the requested room with multiple browser tabs opened.

Example

result = client.get_active_users(
    room_id="my-room-id",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room

set_presence

This endpoint sets ephemeral presence for a user in a room without requiring a WebSocket connection. The presence data will automatically expire after the specified TTL (time-to-live). This is useful for scenarios like showing an AI agent's presence in a room. The presence will be broadcast to all connected users in the room. Corresponds to liveblocks.setPresence.

Example

from liveblocks.models import SetPresenceRequestBody

client.set_presence(
    room_id="my-room-id",
    body=SetPresenceRequestBody(
        user_id="...",
        data=...,
        # user_info=...,
        # ttl=0,
    ),
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
body SetPresenceRequestBody Yes Request body (application/json)

broadcast_event

This endpoint enables the broadcast of an event to a room without having to connect to it via the client from @liveblocks/client. It takes any valid JSON as a request body. The connectionId passed to event listeners is -1 when using this API. Corresponds to liveblocks.broadcastEvent.

Example

client.broadcast_event(
    room_id="my-room-id",
    body=...,
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
body Any Yes Request body (application/json)

Storage

get_storage_document

Returns the contents of the room’s Storage tree. Corresponds to liveblocks.getStorageDocument.

The default outputted format is called “plain LSON”, which includes information on the Live data structures in the tree. These nodes show up in the output as objects with two properties, for example:

{
  "liveblocksType": "LiveObject",
  "data": ...
}

If you’re not interested in this information, you can use the simpler ?format=json query param, see below.

Example

result = client.get_storage_document(
    room_id="my-room-id",
    # format_=...,
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
format_ GetStorageDocumentFormat | Unset No Use the json format to output a simplified JSON representation of the Storage tree. In that format, each LiveObject and LiveMap will be formatted as a simple JSON object, and each LiveList will be formatted as a simple JSON array. This is a lossy format because information about the original data structures is not retained, but it may be easier to work with.

initialize_storage_document

This endpoint initializes or reinitializes a room’s Storage. The room must already exist. Calling this endpoint will disconnect all users from the room if there are any, triggering a reconnect. Corresponds to liveblocks.initializeStorageDocument.

The format of the request body is the same as what’s returned by the get Storage endpoint.

For each Liveblocks data structure that you want to create, you need a JSON element having two properties:

  • "liveblocksType" => "LiveObject" | "LiveList" | "LiveMap"
  • "data" => contains the nested data structures (children) and data.

The root’s type can only be LiveObject.

A utility function, toPlainLson is included in @liveblocks/client from 1.0.9 to help convert LiveObject, LiveList, and LiveMap to the structure expected by the endpoint.

Example

result = client.initialize_storage_document(
    room_id="my-room-id",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
body InitializeStorageDocumentBody | Unset No Request body (application/json)

delete_storage_document

This endpoint deletes all of the room’s Storage data. Calling this endpoint will disconnect all users from the room if there are any. Corresponds to liveblocks.deleteStorageDocument.

Example

client.delete_storage_document(
    room_id="my-room-id",
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room

patch_storage_document

Applies a sequence of JSON Patch operations to the room's Storage document, useful for modifying Storage. Operations are applied in order; if any operation fails, the document is not changed and a 422 response with a helpful message is returned.

Paths and data types: Be as specific as possible with your target path. Every parent in the chain of path segments must be a LiveObject, LiveList, or LiveMap. Complex nested objects passed in add or replace operations are automatically converted to LiveObjects and LiveLists.

Performance: For large Storage documents, applying a patch can be expensive because the full state is reconstructed on the server to apply the operations. Very large documents may not be suitable for this endpoint.

For a full guide with examples, see Modifying storage via REST API with JSON Patch.

Example

client.patch_storage_document(
    room_id="my-room-id",
    body=...,
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
body list[AddJsonPatchOperation | CopyJsonPatchOperation | MoveJsonPatchOperation | RemoveJsonPatchOperation | ReplaceJsonPatchOperation | TestJsonPatchOperation] Yes Request body (application/json)

Yjs

get_yjs_document

This endpoint returns a JSON representation of the room’s Yjs document. Corresponds to liveblocks.getYjsDocument.

Example

result = client.get_yjs_document(
    room_id="my-room-id",
    # formatting=True,
    # key="root",
    # type_=...,
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
formatting bool | Unset No If present, YText will return formatting.
key str | Unset No Returns only a single key’s value, e.g. doc.get(key).toJSON().
type_ GetYjsDocumentType | Unset No Used with key to override the inferred type, i.e. "ymap" will return doc.get(key, Y.Map).

send_yjs_binary_update

This endpoint is used to send a Yjs binary update to the room’s Yjs document. You can use this endpoint to initialize Yjs data for the room or to update the room’s Yjs document. To send an update to a subdocument instead of the main document, pass its guid. Corresponds to liveblocks.sendYjsBinaryUpdate.

The update is typically obtained by calling Y.encodeStateAsUpdate(doc). See the Yjs documentation for more details. When manually making this HTTP call, set the HTTP header Content-Type to application/octet-stream, and send the binary update (a Uint8Array) in the body of the HTTP request. This endpoint does not accept JSON, unlike most other endpoints.

Example

client.send_yjs_binary_update(
    room_id="my-room-id",
    body=...,
    # guid="subdoc-guid-123",
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
guid str | Unset No ID of the subdocument
body File Yes Request body (application/octet-stream)

get_yjs_document_as_binary_update

This endpoint returns the room's Yjs document encoded as a single binary update. This can be used by Y.applyUpdate(responseBody) to get a copy of the document in your back end. See Yjs documentation for more information on working with updates. To return a subdocument instead of the main document, pass its guid. Corresponds to liveblocks.getYjsDocumentAsBinaryUpdate.

Example

result = client.get_yjs_document_as_binary_update(
    room_id="my-room-id",
    # guid="subdoc-guid-123",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
guid str | Unset No ID of the subdocument

get_yjs_versions

This endpoint returns a list of version history snapshots for the room's Yjs document. The versions are returned sorted by creation date, from newest to oldest.

Example

result = client.get_yjs_versions(
    room_id="my-room-id",
    # limit=20,
    # cursor="eyJjcmVhdGVkQXQiOjE2NjAwMDA5ODgxMzd9",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
limit int | Unset No A limit on the number of versions to be returned. The limit can range between 1 and 100, and defaults to 20. (default: 20)
cursor str | Unset No A cursor used for pagination. Get the value from the nextCursor response of the previous page.

get_yjs_version

This endpoint returns a specific version of the room's Yjs document encoded as a binary Yjs update.

Example

result = client.get_yjs_version(
    room_id="my-room-id",
    version_id="vh_abc123",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
version_id str Yes ID of the version

create_yjs_version

This endpoint creates a new version history snapshot for the room's Yjs document.

Example

result = client.create_yjs_version(
    room_id="my-room-id",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room

Comments

get_threads

This endpoint returns the threads in the requested room. Corresponds to liveblocks.getThreads.

Example

result = client.get_threads(
    room_id="my-room-id",
    # query="metadata[\"color\"]:\"blue\"",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
query str | Unset No Query to filter threads. You can filter by metadata and resolved, for example, metadata["status"]:"open" AND metadata["color"]:"red" AND resolved:true. Learn more about filtering threads with query language.

create_thread

This endpoint creates a new thread and the first comment in the thread. Corresponds to liveblocks.createThread.

A comment’s body is an array of paragraphs, each containing child nodes. Here’s an example of how to construct a comment’s body, which can be submitted under comment.body.

{
  "version": 1,
  "content": [
    {
      "type": "paragraph",
      "children": [{ "text": "Hello " }, { "text": "world", "bold": true }]
    }
  ]
}

metadata supports maximum 50 entries. Key length has a limit of 40 characters maximum. Value length has a limit of 4000 characters maximum for strings.

Example

from liveblocks.models import CreateThreadRequestBody

result = client.create_thread(
    room_id="my-room-id",
    body=CreateThreadRequestBody(
        comment=...,
        # metadata=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
body CreateThreadRequestBody Yes Request body (application/json)

get_thread

This endpoint returns a thread by its ID. Corresponds to liveblocks.getThread.

Example

result = client.get_thread(
    room_id="my-room-id",
    thread_id="th_abc123",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread

delete_thread

This endpoint deletes a thread by its ID. Corresponds to liveblocks.deleteThread.

Example

client.delete_thread(
    room_id="my-room-id",
    thread_id="th_abc123",
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread

edit_thread_metadata

This endpoint edits the metadata of a thread. The metadata is a JSON object that can be used to store any information you want about the thread, in string, number, or boolean form. Set a property to null to remove it. Corresponds to liveblocks.editThreadMetadata.

metadata supports maximum 50 entries. Key length has a limit of 40 characters maximum. Value length has a limit of 4000 characters maximum for strings.

Example

from liveblocks.models import EditThreadMetadataRequestBody

result = client.edit_thread_metadata(
    room_id="my-room-id",
    thread_id="th_abc123",
    body=EditThreadMetadataRequestBody(
        metadata=...,
        user_id="...",
        # updated_at=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
body EditThreadMetadataRequestBody Yes Request body (application/json)

mark_thread_as_resolved

This endpoint marks a thread as resolved. The request body must include a userId to identify who resolved the thread. Returns the updated thread. Corresponds to liveblocks.markThreadAsResolved.

Example

from liveblocks.models import MarkThreadAsResolvedRequestBody

result = client.mark_thread_as_resolved(
    room_id="my-room-id",
    thread_id="th_abc123",
    body=MarkThreadAsResolvedRequestBody(
        user_id="...",
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
body MarkThreadAsResolvedRequestBody Yes Request body (application/json)

mark_thread_as_unresolved

This endpoint marks a thread as unresolved. The request body must include a userId to identify who unresolved the thread. Returns the updated thread. Corresponds to liveblocks.markThreadAsUnresolved.

Example

from liveblocks.models import MarkThreadAsUnresolvedRequestBody

result = client.mark_thread_as_unresolved(
    room_id="my-room-id",
    thread_id="th_abc123",
    body=MarkThreadAsUnresolvedRequestBody(
        user_id="...",
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
body MarkThreadAsUnresolvedRequestBody Yes Request body (application/json)

subscribe_to_thread

This endpoint subscribes to a thread. Corresponds to liveblocks.subscribeToThread.

Example

from liveblocks.models import SubscribeToThreadRequestBody

result = client.subscribe_to_thread(
    room_id="my-room-id",
    thread_id="th_abc123",
    body=SubscribeToThreadRequestBody(
        user_id="...",
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
body SubscribeToThreadRequestBody Yes Request body (application/json)

unsubscribe_from_thread

This endpoint unsubscribes from a thread. Corresponds to liveblocks.unsubscribeFromThread.

Example

from liveblocks.models import UnsubscribeFromThreadRequestBody

client.unsubscribe_from_thread(
    room_id="my-room-id",
    thread_id="th_abc123",
    body=UnsubscribeFromThreadRequestBody(
        user_id="...",
    ),
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
body UnsubscribeFromThreadRequestBody Yes Request body (application/json)

get_thread_subscriptions

This endpoint gets the list of subscriptions to a thread. Corresponds to liveblocks.getThreadSubscriptions.

Example

result = client.get_thread_subscriptions(
    room_id="my-room-id",
    thread_id="th_abc123",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread

create_comment

This endpoint creates a new comment, adding it as a reply to a thread. Corresponds to liveblocks.createComment.

A comment’s body is an array of paragraphs, each containing child nodes. Here’s an example of how to construct a comment’s body, which can be submitted under body.

{
  "version": 1,
  "content": [
    {
      "type": "paragraph",
      "children": [{ "text": "Hello " }, { "text": "world", "bold": true }]
    }
  ]
}

metadata supports maximum 50 entries. Key length has a limit of 40 characters maximum. Value length has a limit of 4000 characters maximum for strings.

Example

from liveblocks.models import CreateCommentRequestBody

result = client.create_comment(
    room_id="my-room-id",
    thread_id="th_abc123",
    body=CreateCommentRequestBody(
        user_id="...",
        body=...,
        # created_at=...,
        # metadata=...,
        # attachment_ids=[],
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
body CreateCommentRequestBody Yes Request body (application/json)

get_comment

This endpoint returns a comment by its ID. Corresponds to liveblocks.getComment.

Example

result = client.get_comment(
    room_id="my-room-id",
    thread_id="th_abc123",
    comment_id="cm_abc123",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
comment_id str Yes ID of the comment

edit_comment

This endpoint edits the specified comment. Corresponds to liveblocks.editComment.

A comment’s body is an array of paragraphs, each containing child nodes. Here’s an example of how to construct a comment’s body, which can be submitted under body.

{
  "version": 1,
  "content": [
    {
      "type": "paragraph",
      "children": [{ "text": "Hello " }, { "text": "world", "bold": true }]
    }
  ]
}

Example

from liveblocks.models import EditCommentRequestBody

result = client.edit_comment(
    room_id="my-room-id",
    thread_id="th_abc123",
    comment_id="cm_abc123",
    body=EditCommentRequestBody(
        body=...,
        # edited_at=...,
        # metadata=...,
        # attachment_ids=[],
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
comment_id str Yes ID of the comment
body EditCommentRequestBody Yes Request body (application/json)

delete_comment

This endpoint deletes a comment. A deleted comment is no longer accessible from the API or the dashboard and it cannot be restored. Corresponds to liveblocks.deleteComment.

Example

client.delete_comment(
    room_id="my-room-id",
    thread_id="th_abc123",
    comment_id="cm_abc123",
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
comment_id str Yes ID of the comment

add_comment_reaction

This endpoint adds a reaction to a comment. Corresponds to liveblocks.addCommentReaction.

Example

from liveblocks.models import AddCommentReactionRequestBody

result = client.add_comment_reaction(
    room_id="my-room-id",
    thread_id="th_abc123",
    comment_id="cm_abc123",
    body=AddCommentReactionRequestBody(
        user_id="...",
        emoji="...",
        # created_at=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
comment_id str Yes ID of the comment
body AddCommentReactionRequestBody Yes Request body (application/json)

remove_comment_reaction

This endpoint removes a comment reaction. A deleted comment reaction is no longer accessible from the API or the dashboard and it cannot be restored. Corresponds to liveblocks.removeCommentReaction.

Example

client.remove_comment_reaction(
    room_id="my-room-id",
    thread_id="th_abc123",
    comment_id="cm_abc123",
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
comment_id str Yes ID of the comment
body RemoveCommentReactionRequestBody | Unset No Request body (application/json)

get_attachment

Gets an attachment's metadata and a presigned download URL. The URL expires after 1 hour.

Example

result = client.get_attachment(
    room_id="my-room-id",
    attachment_id="at_abc123",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
attachment_id str Yes ID of the attachment

edit_comment_metadata

This endpoint edits the metadata of a comment. The metadata is a JSON object that can be used to store any information you want about the comment, in string, number, or boolean form. Set a property to null to remove it. Corresponds to liveblocks.editCommentMetadata.

metadata supports maximum 50 entries. Key length has a limit of 40 characters maximum. Value length has a limit of 4000 characters maximum for strings.

Example

from liveblocks.models import EditCommentMetadataRequestBody

result = client.edit_comment_metadata(
    room_id="my-room-id",
    thread_id="th_abc123",
    comment_id="cm_abc123",
    body=EditCommentMetadataRequestBody(
        metadata=...,
        user_id="...",
        # updated_at=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread
comment_id str Yes ID of the comment
body EditCommentMetadataRequestBody Yes Request body (application/json)

get_thread_inbox_notifications

This endpoint returns the inbox notifications associated with a specific thread. Because this endpoint is not user-scoped, each notification includes a userId field identifying which user the notification belongs to. Only thread-kind notifications are returned.

Example

result = client.get_thread_inbox_notifications(
    room_id="my-room-id",
    thread_id="th_abc123",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
thread_id str Yes ID of the thread

Auth

authorize_user

This endpoint lets your application server (your back end) obtain a token that one of its clients (your frontend) can use to enter a Liveblocks room. You use this endpoint to implement your own application’s custom authentication endpoint. When making this request, you’ll have to use your secret key.

Important: The difference with an ID token is that an access token holds all the permissions, and is the source of truth. With ID tokens, permissions are set in the Liveblocks back end (through REST API calls) and "checked at the door" every time they are used to enter a room.

Note: When using the @liveblocks/node package, you can use Liveblocks.prepareSession in your back end to build this request.

You can pass the property userId in the request’s body. This can be whatever internal identifier you use for your user accounts as long as it uniquely identifies an account. The property userId is used by Liveblocks to calculate your account’s Monthly Active Users. One unique userId corresponds to one MAU.

Additionally, you can set custom metadata to the token, which will be publicly accessible by other clients through the user.info property. This is useful for storing static data like avatar images or the user’s display name.

Lastly, you’ll specify the exact permissions to give to the user using the permissions field. This is done in an object where the keys are room names, or room name patterns (ending in a *), and a list of permissions to assign the user for any room that matches that name exactly (or starts with the pattern’s prefix). For tips, see Manage permissions with access tokens.

Example

from liveblocks.models import AuthorizeUserRequestBody

result = client.authorize_user(
    body=AuthorizeUserRequestBody(
        user_id="...",
        permissions=...,
        # user_info=...,
        # organization_id="...",
    ),
)
print(result)

Parameters:

Name Type Required Description
body AuthorizeUserRequestBody Yes Request body (application/json)

identify_user

This endpoint lets your application server (your back end) obtain a token that one of its clients (your frontend) can use to enter a Liveblocks room. You use this endpoint to implement your own application’s custom authentication endpoint. When using this endpoint to obtain ID tokens, you should manage your permissions by assigning user and/or group permissions to rooms explicitly, see our Manage permissions with ID tokens section.

Important: The difference with an access token is that an ID token doesn’t hold any permissions itself. With ID tokens, permissions are set in the Liveblocks back end (through REST API calls) and "checked at the door" every time they are used to enter a room. With access tokens, all permissions are set in the token itself, and thus controlled from your back end entirely.

Note: When using the @liveblocks/node package, you can use Liveblocks.identifyUser in your back end to build this request.

You can pass the property userId in the request’s body. This can be whatever internal identifier you use for your user accounts as long as it uniquely identifies an account. The property userId is used by Liveblocks to calculate your account’s Monthly Active Users. One unique userId corresponds to one MAU.

If you want to use group permissions, you can also declare which groupIds this user belongs to. The group ID values are yours, but they will have to match the group IDs you assign permissions to when assigning permissions to rooms, see Manage permissions with ID tokens).

Additionally, you can set custom metadata to the token, which will be publicly accessible by other clients through the user.info property. This is useful for storing static data like avatar images or the user’s display name.

Example

from liveblocks.models import IdentifyUserRequestBody

result = client.identify_user(
    body=IdentifyUserRequestBody(
        user_id="...",
        # organization_id="...",
        # group_ids=[],
        # user_info=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
body IdentifyUserRequestBody Yes Request body (application/json)

Notifications

get_inbox_notification

This endpoint returns a user’s inbox notification by its ID. Corresponds to liveblocks.getInboxNotification.

Example

result = client.get_inbox_notification(
    user_id="user-123",
    inbox_notification_id="in_abc123",
)
print(result)

Parameters:

Name Type Required Description
user_id str Yes ID of the user
inbox_notification_id str Yes ID of the inbox notification

delete_inbox_notification

This endpoint deletes a user’s inbox notification by its ID. Corresponds to liveblocks.deleteInboxNotification.

Example

client.delete_inbox_notification(
    user_id="user-123",
    inbox_notification_id="in_abc123",
)

Parameters:

Name Type Required Description
user_id str Yes ID of the user
inbox_notification_id str Yes ID of the inbox notification

get_inbox_notifications

This endpoint returns all the user’s inbox notifications. Corresponds to liveblocks.getInboxNotifications.

Example

result = client.get_inbox_notifications(
    user_id="user-123",
    # organization_id="org_123456789",
    # query="metadata[\"color\"]:\"blue\"",
    # limit=20,
    # starting_after="eyJjcmVhdGVkQXQiOjE2NjAwMDA5ODgxMzd9",
)
print(result)

Parameters:

Name Type Required Description
user_id str Yes ID of the user
organization_id str | Unset No The organization ID to filter notifications for.
query str | Unset No Query to filter notifications. You can filter by unread, for example, unread:true.
limit int | Unset No A limit on the number of inbox notifications to be returned. The limit can range between 1 and 50, and defaults to 50. (default: 50)
starting_after str | Unset No A cursor used for pagination. Get the value from the nextCursor response of the previous page.

delete_all_inbox_notifications

This endpoint deletes all the user’s inbox notifications. Corresponds to liveblocks.deleteAllInboxNotifications.

Example

client.delete_all_inbox_notifications(
    user_id="user-123",
)

Parameters:

Name Type Required Description
user_id str Yes ID of the user

get_notification_settings

This endpoint returns a user's notification settings for the project. Corresponds to liveblocks.getNotificationSettings.

Example

result = client.get_notification_settings(
    user_id="user-123",
)
print(result)

Parameters:

Name Type Required Description
user_id str Yes ID of the user

update_notification_settings

This endpoint updates a user's notification settings for the project. Corresponds to liveblocks.updateNotificationSettings.

Example

from liveblocks.models import UpdateNotificationSettingsRequestBody

result = client.update_notification_settings(
    user_id="user-123",
    body=UpdateNotificationSettingsRequestBody(
        # email=...,
        # slack=...,
        # teams=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
user_id str Yes ID of the user
body UpdateNotificationSettingsRequestBody Yes Request body (application/json)

delete_notification_settings

This endpoint deletes a user's notification settings for the project. Corresponds to liveblocks.deleteNotificationSettings.

Example

client.delete_notification_settings(
    user_id="user-123",
)

Parameters:

Name Type Required Description
user_id str Yes ID of the user

get_room_subscription_settings

This endpoint returns a user’s subscription settings for a specific room. Corresponds to liveblocks.getRoomSubscriptionSettings.

Example

result = client.get_room_subscription_settings(
    room_id="my-room-id",
    user_id="user-123",
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
user_id str Yes ID of the user

update_room_subscription_settings

This endpoint updates a user’s subscription settings for a specific room. Corresponds to liveblocks.updateRoomSubscriptionSettings.

Example

from liveblocks.models import UpdateRoomSubscriptionSettingsRequestBody

result = client.update_room_subscription_settings(
    room_id="my-room-id",
    user_id="user-123",
    body=UpdateRoomSubscriptionSettingsRequestBody(
        # threads=...,
        # text_mentions=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
user_id str Yes ID of the user
body UpdateRoomSubscriptionSettingsRequestBody Yes Request body (application/json)

delete_room_subscription_settings

This endpoint deletes a user’s subscription settings for a specific room. Corresponds to liveblocks.deleteRoomSubscriptionSettings.

Example

client.delete_room_subscription_settings(
    room_id="my-room-id",
    user_id="user-123",
)

Parameters:

Name Type Required Description
room_id str Yes ID of the room
user_id str Yes ID of the user

get_user_room_subscription_settings

This endpoint returns the list of a user's room subscription settings. Corresponds to liveblocks.getUserRoomSubscriptionSettings.

Example

result = client.get_user_room_subscription_settings(
    user_id="user-123",
    # starting_after="eyJjcmVhdGVkQXQiOjE2NjAwMDA5ODgxMzd9",
    # limit=20,
    # organization_id="org_123456789",
)
print(result)

Parameters:

Name Type Required Description
user_id str Yes ID of the user
starting_after str | Unset No A cursor used for pagination. Get the value from the nextCursor response of the previous page.
limit int | Unset No A limit on the number of elements to be returned. The limit can range between 1 and 50, and defaults to 50. (default: 50)
organization_id str | Unset No The organization ID to filter room subscription settings for.

trigger_inbox_notification

This endpoint triggers an inbox notification. Corresponds to liveblocks.triggerInboxNotification.

Example

client.trigger_inbox_notification()

Parameters:

Name Type Required Description
body TriggerInboxNotificationRequestBody | Unset No Request body (application/json)

mark_inbox_notification_as_read

This endpoint marks a specific inbox notification as read.

Example

client.mark_inbox_notification_as_read(
    inbox_notification_id="in_abc123",
)

Parameters:

Name Type Required Description
inbox_notification_id str Yes ID of the inbox notification

Groups

get_groups

This endpoint returns a list of all groups in your project. Corresponds to liveblocks.getGroups.

Example

result = client.get_groups(
    # limit=20,
    # starting_after="eyJjcmVhdGVkQXQiOjE2NjAwMDA5ODgxMzd9",
)
print(result)

Parameters:

Name Type Required Description
limit int | Unset No A limit on the number of groups to be returned. The limit can range between 1 and 100, and defaults to 20. (default: 20)
starting_after str | Unset No A cursor used for pagination. Get the value from the nextCursor response of the previous page.

create_group

This endpoint creates a new group. Corresponds to liveblocks.createGroup.

Example

result = client.create_group()
print(result)

Parameters:

Name Type Required Description
body CreateGroupRequestBody | Unset No Request body (application/json)

get_group

This endpoint returns a specific group by ID. Corresponds to liveblocks.getGroup.

Example

result = client.get_group(
    group_id="engineering",
)
print(result)

Parameters:

Name Type Required Description
group_id str Yes The ID of the group to retrieve.

delete_group

This endpoint deletes a group. Corresponds to liveblocks.deleteGroup.

Example

client.delete_group(
    group_id="engineering",
)

Parameters:

Name Type Required Description
group_id str Yes The ID of the group to delete.

add_group_members

This endpoint adds new members to an existing group. Corresponds to liveblocks.addGroupMembers.

Example

from liveblocks.models import AddGroupMembersRequestBody

result = client.add_group_members(
    group_id="engineering",
    body=AddGroupMembersRequestBody(
        member_ids=[],
    ),
)
print(result)

Parameters:

Name Type Required Description
group_id str Yes The ID of the group to add members to.
body AddGroupMembersRequestBody Yes Request body (application/json)

remove_group_members

This endpoint removes members from an existing group. Corresponds to liveblocks.removeGroupMembers.

Example

from liveblocks.models import RemoveGroupMembersRequestBody

result = client.remove_group_members(
    group_id="engineering",
    body=RemoveGroupMembersRequestBody(
        member_ids=[],
    ),
)
print(result)

Parameters:

Name Type Required Description
group_id str Yes The ID of the group to remove members from.
body RemoveGroupMembersRequestBody Yes Request body (application/json)

get_user_groups

This endpoint returns all groups that a specific user is a member of. Corresponds to liveblocks.getUserGroups.

Example

result = client.get_user_groups(
    user_id="user-123",
    # limit=20,
    # starting_after="eyJjcmVhdGVkQXQiOjE2NjAwMDA5ODgxMzd9",
)
print(result)

Parameters:

Name Type Required Description
user_id str Yes The ID of the user to get groups for.
limit int | Unset No A limit on the number of groups to be returned. The limit can range between 1 and 100, and defaults to 20. (default: 20)
starting_after str | Unset No A cursor used for pagination. Get the value from the nextCursor response of the previous page.

Ai

get_ai_copilots

This endpoint returns a paginated list of AI copilots. The copilots are returned sorted by creation date, from newest to oldest. Corresponds to liveblocks.getAiCopilots.

Example

result = client.get_ai_copilots(
    # limit=20,
    # starting_after="eyJjcmVhdGVkQXQiOjE2NjAwMDA5ODgxMzd9",
)
print(result)

Parameters:

Name Type Required Description
limit int | Unset No A limit on the number of copilots to be returned. The limit can range between 1 and 100, and defaults to 20. (default: 20)
starting_after str | Unset No A cursor used for pagination. Get the value from the nextCursor response of the previous page.

create_ai_copilot

This endpoint creates a new AI copilot with the given configuration. Corresponds to liveblocks.createAiCopilot.

Example

result = client.create_ai_copilot(
    body=...,
)
print(result)

Parameters:

Name Type Required Description
body CreateAiCopilotOptionsAnthropic | CreateAiCopilotOptionsGoogle | CreateAiCopilotOptionsOpenAi | CreateAiCopilotOptionsOpenAiCompatible Yes Request body (application/json)

get_ai_copilot

This endpoint returns an AI copilot by its ID. Corresponds to liveblocks.getAiCopilot.

Example

result = client.get_ai_copilot(
    copilot_id="cp_abc123",
)
print(result)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot

update_ai_copilot

This endpoint updates an existing AI copilot's configuration. Corresponds to liveblocks.updateAiCopilot.

This endpoint returns a 422 response if the update doesn't apply due to validation failures. For example, if the existing copilot uses the "openai" provider and you attempt to update the provider model to an incompatible value for the provider, like "gemini-2.5-pro", you'll receive a 422 response with an error message explaining where the validation failed.

Example

from liveblocks.models import UpdateAiCopilotRequestBody

result = client.update_ai_copilot(
    copilot_id="cp_abc123",
    body=UpdateAiCopilotRequestBody(
        # name="...",
        # description="...",
        # system_prompt="...",
    ),
)
print(result)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot
body UpdateAiCopilotRequestBody Yes Request body (application/json)

delete_ai_copilot

This endpoint deletes an AI copilot by its ID. A deleted copilot is no longer accessible and cannot be restored. Corresponds to liveblocks.deleteAiCopilot.

Example

client.delete_ai_copilot(
    copilot_id="cp_abc123",
)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot

get_knowledge_sources

This endpoint returns a paginated list of knowledge sources for a specific AI copilot. Corresponds to liveblocks.getKnowledgeSources.

Example

result = client.get_knowledge_sources(
    copilot_id="cp_abc123",
    # limit=20,
    # starting_after="eyJjcmVhdGVkQXQiOjE2NjAwMDA5ODgxMzd9",
)
print(result)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot
limit int | Unset No A limit on the number of knowledge sources to be returned. The limit can range between 1 and 100, and defaults to 20. (default: 20)
starting_after str | Unset No A cursor used for pagination. Get the value from the nextCursor response of the previous page.

get_knowledge_source

This endpoint returns a specific knowledge source by its ID. Corresponds to liveblocks.getKnowledgeSource.

Example

result = client.get_knowledge_source(
    copilot_id="cp_abc123",
    knowledge_source_id="ks_abc123",
)
print(result)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot
knowledge_source_id str Yes ID of the knowledge source

create_web_knowledge_source

This endpoint creates a web knowledge source for an AI copilot. This allows the copilot to access and learn from web content. Corresponds to liveblocks.createWebKnowledgeSource.

Example

from liveblocks.models import CreateWebKnowledgeSourceRequestBody

result = client.create_web_knowledge_source(
    copilot_id="cp_abc123",
    body=CreateWebKnowledgeSourceRequestBody(
        copilot_id="...",
        url="...",
        type_=...,
    ),
)
print(result)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot
body CreateWebKnowledgeSourceRequestBody Yes Request body (application/json)

create_file_knowledge_source

This endpoint creates a file knowledge source for an AI copilot by uploading a file. The copilot can then reference the content of the file when responding. Corresponds to liveblocks.createFileKnowledgeSource.

Example

result = client.create_file_knowledge_source(
    copilot_id="cp_abc123",
    name="document.pdf",
    body=...,
)
print(result)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot
name str Yes Name of the file
body File Yes Request body (application/octet-stream)

get_file_knowledge_source_markdown

This endpoint returns the content of a file knowledge source as markdown. This allows you to see what content the AI copilot has access to from uploaded files. Corresponds to liveblocks.getFileKnowledgeSourceMarkdown.

Example

result = client.get_file_knowledge_source_markdown(
    copilot_id="cp_abc123",
    knowledge_source_id="ks_abc123",
)
print(result)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot
knowledge_source_id str Yes ID of the knowledge source

delete_file_knowledge_source

This endpoint deletes a file knowledge source from an AI copilot. The copilot will no longer have access to the content from this file. Corresponds to liveblocks.deleteFileKnowledgeSource.

Example

client.delete_file_knowledge_source(
    copilot_id="cp_abc123",
    knowledge_source_id="ks_abc123",
)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot
knowledge_source_id str Yes ID of the knowledge source

delete_web_knowledge_source

This endpoint deletes a web knowledge source from an AI copilot. The copilot will no longer have access to the content from this source. Corresponds to liveblocks.deleteWebKnowledgeSource.

Example

client.delete_web_knowledge_source(
    copilot_id="cp_abc123",
    knowledge_source_id="ks_abc123",
)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot
knowledge_source_id str Yes ID of the knowledge source

get_web_knowledge_source_links

This endpoint returns a paginated list of links that were indexed from a web knowledge source. This is useful for understanding what content the AI copilot has access to from web sources. Corresponds to liveblocks.getWebKnowledgeSourceLinks.

Example

result = client.get_web_knowledge_source_links(
    copilot_id="cp_abc123",
    knowledge_source_id="ks_abc123",
    # limit=20,
    # starting_after="eyJjcmVhdGVkQXQiOjE2NjAwMDA5ODgxMzd9",
)
print(result)

Parameters:

Name Type Required Description
copilot_id str Yes ID of the AI copilot
knowledge_source_id str Yes ID of the knowledge source
limit int | Unset No A limit on the number of links to be returned. The limit can range between 1 and 100, and defaults to 20. (default: 20)
starting_after str | Unset No A cursor used for pagination. Get the value from the nextCursor response of the previous page.

Error Handling

All API methods raise errors.LiveblocksError when the server returns a non-2xx status code. You can catch and inspect these errors:

from liveblocks import errors, Liveblocks

client = Liveblocks(secret="sk_your_secret_key")

with client:
    try:
        room = client.get_room(room_id="my-room")
    except errors.LiveblocksError as e:
        print(f"API error: {e}")

Methods also raise httpx.TimeoutException if the request exceeds the timeout.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

liveblocks-3.15.4.tar.gz (105.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

liveblocks-3.15.4-py3-none-any.whl (255.2 kB view details)

Uploaded Python 3

File details

Details for the file liveblocks-3.15.4.tar.gz.

File metadata

  • Download URL: liveblocks-3.15.4.tar.gz
  • Upload date:
  • Size: 105.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for liveblocks-3.15.4.tar.gz
Algorithm Hash digest
SHA256 ec5cb302b43d1942d76135e97689871d69c61f1cb6a8877495736c3c635791e1
MD5 dc3f580ea9737f2b49b7406343a97faa
BLAKE2b-256 c8e14481ee9665e8c4e5d2e161a9bd76a818b4700e9d55851dba088c6b7d1320

See more details on using hashes here.

File details

Details for the file liveblocks-3.15.4-py3-none-any.whl.

File metadata

  • Download URL: liveblocks-3.15.4-py3-none-any.whl
  • Upload date:
  • Size: 255.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for liveblocks-3.15.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9fa10c30427f24002f2ef5b45bdd4c08407edd83c6b21562bc8b2f701c7a1f22
MD5 2188abda492d8b1e0b4c4a2c4189d539
BLAKE2b-256 dabc65fe99fded7cfd2087c45d7bc5adb032b6f681cdfc897356fc65fa3ffeb0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page