Python API wrapper for Rocket.Chat's REST API, enabling developers to programmatically interact with Rocket.Chat servers for chat automation, bot development, and integration purposes
npx @tessl/cli install tessl/pypi-rocketchat-a-p-i@1.36.0A comprehensive Python wrapper for the Rocket.Chat REST API, enabling developers to programmatically interact with Rocket.Chat servers for chat automation, bot development, and integration purposes. It provides complete coverage of the Rocket.Chat API with support for authentication, channel management, messaging, user administration, and server configuration.
pip install rocketchat_APIfrom rocketchat_API.rocketchat import RocketChatfrom rocketchat_API.rocketchat import RocketChat
# Username/password authentication
rocket = RocketChat('username', 'password', server_url='https://your-server.com')
# Token authentication (recommended for production)
rocket = RocketChat(user_id='user_id', auth_token='auth_token', server_url='https://your-server.com')
# Get current user info
response = rocket.me()
print(response.json())
# List channels
channels = rocket.channels_list()
print(channels.json())
# Send a message
result = rocket.chat_post_message(
text='Hello from Python!',
channel='general'
)
print(result.json())
# Get channel history
history = rocket.channels_history('GENERAL', count=10)
print(history.json())The RocketChat class inherits from 20+ specialized API section classes, each providing methods for specific functionality areas:
RocketChatBase provides HTTP methods and authenticationrequests.Response objectsclass RocketChat:
def __init__(
self,
user=None,
password=None,
auth_token=None,
user_id=None,
server_url="http://127.0.0.1:3000",
ssl_verify=True,
proxies=None,
timeout=30,
session=None,
client_certs=None,
): ...def login(self, user, password):
"""
Authenticate with username/email and password.
Parameters:
- user (str): Username or email address
- password (str): User password
Returns:
requests.Response: Authentication result with token and user ID
"""
def logout(self, **kwargs):
"""
Invalidate your REST rocketchat_API authentication token.
Returns:
requests.Response: Logout result
"""
def info(self, **kwargs):
"""
Information about the Rocket.Chat server.
Returns:
requests.Response: Server information including version and build
"""
def me(self, **kwargs):
"""
Get current authenticated user information.
Returns:
requests.Response: Current user details
"""class RocketException(Exception): ...
class RocketConnectionException(Exception): ...
class RocketAuthenticationException(Exception): ...
class RocketMissingParamException(Exception): ...
class RocketUnsuportedIntegrationType(Exception): ...Complete channel lifecycle management including creation, configuration, membership, and administration. Supports public channels with features like moderation, custom fields, and integration management.
def channels_create(self, name, **kwargs): ...
def channels_info(self, room_id=None, channel=None, **kwargs): ...
def channels_list(self, **kwargs): ...
def channels_invite(self, room_id, user_id, **kwargs): ...
def channels_kick(self, room_id, user_id, **kwargs): ...
def channels_history(self, room_id, **kwargs): ...Core messaging functionality including sending, editing, deleting, and searching messages. Supports message reactions, threading, pinning, starring, and advanced features like message reports and read receipts.
def chat_post_message(self, text, room_id=None, channel=None, **kwargs): ...
def chat_update(self, room_id, msg_id, text, **kwargs): ...
def chat_delete(self, room_id, msg_id, **kwargs): ...
def chat_search(self, room_id, search_text, **kwargs): ...
def chat_react(self, msg_id, emoji="smile", **kwargs): ...Private group management with similar functionality to public channels but with enhanced privacy controls. Includes group creation, membership management, and administrative functions.
def groups_create(self, name, **kwargs): ...
def groups_info(self, room_id=None, room_name=None, **kwargs): ...
def groups_list(self, **kwargs): ...
def groups_invite(self, room_id, user_id, **kwargs): ...
def groups_kick(self, room_id, user_id, **kwargs): ...One-on-one and multi-user direct messaging capabilities. Includes DM creation, message history, file sharing, and conversation management features.
def im_create(self, username, **kwargs): ...
def im_list(self, **kwargs): ...
def im_history(self, room_id, **kwargs): ...
def im_open(self, room_id, **kwargs): ...
def im_close(self, room_id, **kwargs): ...Comprehensive user administration including account creation, profile management, authentication, and user preferences. Supports user roles, presence status, and avatar management.
def users_create(self, email, name, password, username, **kwargs): ...
def users_info(self, user_id=None, username=None, **kwargs): ...
def users_list(self, **kwargs): ...
def users_update(self, user_id, **kwargs): ...
def users_delete(self, user_id, **kwargs): ...Team-based organization features for managing collections of channels and users. Includes team creation, member management, and room assignment within teams.
def teams_create(self, name, team_type, **kwargs): ...
def teams_info(self, team_id=None, team_name=None, **kwargs): ...
def teams_members(self, team_id=None, team_name=None, **kwargs): ...
def teams_add_rooms(self, team_id=None, team_name=None, rooms=None, **kwargs): ...Customer support and live chat functionality for external visitor engagement. Includes visitor management, inquiry handling, agent assignment, and message routing.
def livechat_register_visitor(self, token, **kwargs): ...
def livechat_room(self, token, **kwargs): ...
def livechat_message(self, token, rid, msg, **kwargs): ...
def livechat_inquiries_take(self, inquiry_id, **kwargs): ...Server administration and configuration management including settings, permissions, roles, statistics, and integration management. Requires appropriate administrative permissions.
def settings_get(self, _id, **kwargs): ...
def permissions_list_all(self, **kwargs): ...
def roles_create(self, name, **kwargs): ...
def statistics(self, **kwargs): ...Webhook and integration management for connecting Rocket.Chat with external systems. Supports incoming and outgoing webhooks with script execution capabilities.
def integrations_create(self, integrations_type, name, enabled, username, channel, script_enabled, **kwargs): ...
def integrations_get(self, integration_id, **kwargs): ...
def integrations_list(self, **kwargs): ...
def integrations_update(self, integrations_type, name, enabled, username, channel, script_enabled, integration_id, **kwargs): ...Role management system for server administration. Create, assign, and manage user roles with optional room-specific scope.
def roles_list(self, **kwargs): ...
def roles_create(self, name, **kwargs): ...
def roles_add_user_to_role(self, role_name, username, **kwargs): ...
def roles_remove_user_from_role(self, role_name, username, **kwargs): ...Extended room functionality including file uploads, history management, favorites, and administrative functions that work across all room types.
def rooms_get(self, **kwargs): ...
def rooms_upload(self, rid, file, **kwargs): ...
def rooms_clean_history(self, room_id, latest, oldest, **kwargs): ...
def rooms_favorite(self, room_id=None, room_name=None, favorite=True): ...Server configuration and settings management including system settings, OAuth configurations, and service configurations.
def settings_get(self, _id, **kwargs): ...
def settings_update(self, _id, value, **kwargs): ...
def settings_oauth(self, **kwargs): ...
def settings_addcustomoauth(self, name, **kwargs): ...Server permission management for controlling user capabilities and access rights within Rocket.Chat.
def permissions_list_all(self, **kwargs): ...
def permissions_update(self, permissions, **kwargs): ...Server statistics and metrics for monitoring usage, performance, and system information.
def statistics(self, **kwargs): ...
def statistics_list(self, **kwargs): ...User subscription management for tracking relationships with rooms, including read status and notifications.
def subscriptions_get(self, **kwargs): ...
def subscriptions_get_one(self, room_id, **kwargs): ...
def subscriptions_read(self, rid, **kwargs): ...
def subscriptions_unread(self, room_id, **kwargs): ...Server asset management for uploading and managing custom assets like logos, favicons, and branding elements.
def assets_set_asset(self, asset_name, file, **kwargs): ...
def assets_unset_asset(self, asset_name, **kwargs): ...Additional utility functions for directory search and spotlight functionality.
def directory(self, query, **kwargs): ...
def spotlight(self, query, **kwargs): ...