Skip to main content

Python SDK for RealtimeX real-time messaging service

Project description

RealtimeX Python SDK

Python client library for RealtimeX real-time messaging service.

Installation

pip

pip install realtimex-python

Quick Start

from realtimex import RealtimeX

# Initialize
realtimex = RealtimeX('YOUR_API_KEY', {
    'cluster': 'eu',  # optional, default 'eu'
    'ws_host': 'ws.realtimex.net',  # optional
    'ws_port': 443,  # optional
    'encrypted': True,  # optional, default True
})

# Bind connection events
realtimex.connection.bind('connected', lambda: print('Connected!'))

# Connect to server
realtimex.connect()

# Subscribe to a channel
channel = realtimex.subscribe('my-channel')

# Listen for events
channel.bind('my-event', lambda data: print('Received:', data))

# Send client events
channel.trigger('client-my-event', {
    'message': 'Hello'
})

API

RealtimeX(api_key, options={})

Create a new RealtimeX instance.

Options:

  • cluster (str): Cluster name, default 'eu'
  • ws_host (str): WebSocket host, default 'ws.realtimex.net'
  • ws_port (int): WebSocket port, default 443
  • encrypted (bool): Use WSS, default True

Methods

subscribe(channel_name)

Subscribe to a channel.

channel = realtimex.subscribe('my-channel')

unsubscribe(channel_name)

Unsubscribe from a channel.

realtimex.unsubscribe('my-channel')

disconnect()

Disconnect from RealtimeX.

realtimex.disconnect()

Channel

bind(event, callback)

Bind to an event.

channel.bind('my-event', lambda data: print(data))

unbind(event, callback=None)

Unbind from an event.

channel.unbind('my-event')

trigger(event, data)

Trigger a client event (must be prefixed with client-).

channel.trigger('client-my-event', {'message': 'Hello'})

bind_global(callback)

Bind to all events on the channel.

channel.bind_global(lambda event, data: print(event, data))

Connection Events

realtimex.connection.bind('connecting', lambda: print('Connecting...'))
realtimex.connection.bind('connected', lambda: print('Connected!'))
realtimex.connection.bind('disconnected', lambda: print('Disconnected'))

Private Channels

Option 1: With auth_endpoint (automatic):

realtimex = RealtimeX('YOUR_API_KEY', {
    'ws_host': 'localhost',
    'ws_port': 3001,
    'encrypted': False,
    'auth_endpoint': 'http://localhost:3001/auth'  # SDK makes HTTP request automatically
})

realtimex.connect()
channel = realtimex.subscribe('private-my-channel')  # SDK handles auth automatically

Option 2: With custom auth_callback:

import requests

def authorizer(channel_name, socket_id):
    # Custom auth logic
    response = requests.post('http://localhost:3001/auth/channels', json={
        'channel_name': channel_name,
        'socket_id': socket_id
    })
    return response.json()  # Returns: {'auth': 'real_token', 'channel_data': '...'}

realtimex = RealtimeX('YOUR_API_KEY', 
    options={'ws_host': 'localhost', 'ws_port': 3001, 'encrypted': False},
    auth_callback=authorizer
)

realtimex.connect()
channel = realtimex.subscribe('private-my-channel')

Presence channels with user data:

realtimex = RealtimeX('YOUR_API_KEY',
    options={
        'ws_host': 'localhost',
        'ws_port': 3001,
        'encrypted': False,
        'auth_endpoint': 'http://localhost:3001/auth'
    },
    user_data={'user_id': '123', 'name': 'John'}
)

realtimex.connect()
channel = realtimex.subscribe('presence-room-1')

License

MIT

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

realtimex_python-1.0.4.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

realtimex_python-1.0.4-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file realtimex_python-1.0.4.tar.gz.

File metadata

  • Download URL: realtimex_python-1.0.4.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for realtimex_python-1.0.4.tar.gz
Algorithm Hash digest
SHA256 b8d446abb878679288f8467a7f3501c89eaee1855dacf137cfb74ae09eef45c3
MD5 65c4b88e27bc48d7f00e72a0eb59b20f
BLAKE2b-256 bf19bc93ada3ad1551c000cb2d8415deb38450149b71e133a72867ead16cd997

See more details on using hashes here.

File details

Details for the file realtimex_python-1.0.4-py3-none-any.whl.

File metadata

File hashes

Hashes for realtimex_python-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c084d1e7d906c1a398ff0a8ea827d2ad7d06a3907046a09268037b20dc18489a
MD5 3b537624b1e010b19869ceb7566c7b35
BLAKE2b-256 20ca3fe2896eba8cd4ec233b8988cfa04cd2c17b8d91da8263df1025d99ff43f

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