Skip to main content

A Python client for the Jolt in-memory messaging broker

Project description

Jolt Python API

PyPI version PyPI downloads

A Python client for the Jolt in-memory messaging broker. This library provides direct access to the Jolt protocol over TCP, enabling efficient pub/sub communication without external dependencies.

The client is designed for real-time messaging, distributed event systems, internal service communication, and data streaming pipelines. It relies solely on the Python standard library and supports thread-safe message sending and background message handling.

Features

This implementation communicates with Jolt using its native NDJSON protocol over TCP sockets and does not require additional third-party packages. It includes a configurable message handler architecture for processing subscription data, status responses, and connection events.

Protocol Overview

The Jolt broker communicates through newline-delimited JSON messages. Clients send operational requests and receive corresponding acknowledgements or topic messages.

Client commands:

{"op": "auth", "user": "username", "pass": "password"}
{"op": "sub", "topic": "channel.name"}
{"op": "unsub", "topic": "channel.name"}
{"op": "pub", "topic": "channel.name", "data": "message"}
{"op": "ping"}

Broker responses:

{"ok": true}
{"ok": false, "error": "error_message"}
{"topic": "channel.name", "data": "message"}

Installation

pip install jolt-python-api

From source:

git clone https://github.com/Jolt-Database/jolt-python-api.git
cd jolt-python-api
pip install -e .

Quick Start Example

from jolt import JoltClient, JoltConfig, JoltMessageHandler
from jolt.response import JoltErrorResponse, JoltTopicMessage
from typing import Optional
import time

class MyHandler(JoltMessageHandler):
    def on_ok(self, raw_line: str):
        print("OK")
    
    def on_error(self, error: JoltErrorResponse, raw_line: str):
        print(f"Error: {error.get_error()}")
    
    def on_topic_message(self, msg: JoltTopicMessage, raw_line: str):
        print(f"[{msg.get_topic()}] {msg.get_data()}")
    
    def on_disconnected(self, cause: Optional[Exception]):
        print("Disconnected")

config = JoltConfig.new_builder() \
    .host("127.0.0.1") \
    .port(8080) \
    .build()

handler = MyHandler()
client = JoltClient(config, handler)
client.connect()

client.subscribe("chat.general")
client.publish("chat.general", "Hello, Jolt!")
client.ping()

time.sleep(1)
client.close()

API Structure

JoltClient

Primary interface for interacting with the broker:

client = JoltClient(config, handler)

client.connect()
client.close()
client.is_connected()

client.auth(username, password)
client.subscribe(topic)
client.unsubscribe(topic)
client.publish(topic, data)
client.ping()

JoltMessageHandler

Application code processes broker events by subclassing JoltMessageHandler:

class MyHandler(JoltMessageHandler):
    def on_ok(self, raw_line: str):
        pass
    
    def on_error(self, error: JoltErrorResponse, raw_line: str):
        pass
    
    def on_topic_message(self, msg: JoltTopicMessage, raw_line: str):
        pass
    
    def on_disconnected(self, cause: Optional[Exception]):
        pass

Response Types

response.is_ok()

error.get_error()
error.is_ok()

message.get_topic()
message.get_data()

Example Usage Scenarios

Simple Topic Subscription

client.connect()
client.subscribe("chat.room1")
client.publish("chat.room1", "Hello everyone")

Handling Multiple Topics

topics = ["news", "sports", "weather"]

for t in topics:
    client.subscribe(t)

client.publish("news", "Python API released")

Robust Error Handling

class RobustHandler(JoltMessageHandler):
    def on_error(self, error: JoltErrorResponse, raw_line: str):
        print(error.get_error())
    
    def on_disconnected(self, cause: Optional[Exception]):
        if cause:
            print(f"Connection lost: {cause}")

Testing

The client includes tests for configuration, request generation, and response parsing.

pytest src/tests/test_config.py -v
pytest src/tests/test_request.py -v
pytest src/tests/test_response.py -v

pytest src/tests/ -v

Running the Jolt Broker

The Python API requires a running Jolt broker instance:

git clone https://github.com/Jolt-Database/Jolt.git
cd Jolt
go build -o jolt-broker
./jolt-broker -port 8080

Troubleshooting

  1. Connection failures commonly result from incorrect host configuration, inactive broker instances, or firewall restrictions.
  2. Publishing without first subscribing will not trigger message delivery.
  3. Authentication errors require correct credentials via .auth() before other operations.

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

jolt_python_api-2.4.3.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

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

jolt_python_api-2.4.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file jolt_python_api-2.4.3.tar.gz.

File metadata

  • Download URL: jolt_python_api-2.4.3.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for jolt_python_api-2.4.3.tar.gz
Algorithm Hash digest
SHA256 a50edcbf8ef277eaa407da4a89a4cb8d38700976d1e7188524887612eb95c540
MD5 cae9dc757738001cb6a0c7fa5bab2dde
BLAKE2b-256 8669a75e90cafc3d9fc0ed67e2de7575c62d8203ccb3254206aec061187284a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for jolt_python_api-2.4.3.tar.gz:

Publisher: pypi-publish.yml on Jolt-Database/jolt-python-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file jolt_python_api-2.4.3-py3-none-any.whl.

File metadata

File hashes

Hashes for jolt_python_api-2.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0ba0c2303e2b393c93df1c510470feb34e61dc7bc6ae978704a018ee3db93aad
MD5 3a7c0655d22ab01aa336c86bf6f70f7d
BLAKE2b-256 340b687e0ac3b36bd78af1851274cd0068494dc79350d9e3e7d6e4daa1fd9e22

See more details on using hashes here.

Provenance

The following attestation bundles were made for jolt_python_api-2.4.3-py3-none-any.whl:

Publisher: pypi-publish.yml on Jolt-Database/jolt-python-api

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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