Skip to content

What is Lightbus?

Lightbus is a powerful but intuitive messaging client for your backend services. Lightbus is for use with Python, but can communicate with services written in other languages.

Lightbus uses Redis 5 as its underlying transport, although support for other platforms may be added in future.

Lightbus is under active development and is still pre-release.

How Lightbus works

Lightbus provides you with two tools:

  1. A client with which to fire events, and make remote procedure calls (RPCs) from anywhere within your codebase.
  2. A stand-alone Lightbus worker process in which you can setup event listeners. This process will also respond to RPCs calls.

For example, you could architect an e-commerce system as follows:

A simple Lightbus deployment

In this example:

  • Django serves pages using data from the database
  • Django performs remote procedure calls to resize images. The Lightbus worker in the image resizing service performs the image resize and responds.
  • The price monitoring service fires price_monitor.competitor_price_changed events
  • The Lightbus worker in the online shop web service listens for price_monitor.competitor_price_changed events and updates prices in the database accordingly.

See the anatomy lesson for further discussion.

Designed for ease of use

Lightbus is designed to be intuitive and familiar, and common problems are caught with clear and helpful error messages.

For example, a naïve authentication API:

class AuthApi(Api):
    user_registered = Event(parameters=('user', 'email'))

    class Meta:
        name = 'auth'

    def check_password(self, user, password):
        return (
            user == 'admin'
            and password == 'secret'
        )

This can be called as follows:

import lightbus

bus = lightbus.create()

is_valid = bus.auth.check_password(
    user='admin',
    password='secret'
)
# is_valid is True

You can also listen for events:

# bus.py
import lightbus

bus = lightbus.create()

# Our event handler
def send_signup_email(event_message,
                      user, email):
    send_mail(email,
        subject=f'Welcome {user}'
    )

# Setup our listeners on startup
def before_server_start():
    bus.auth.user_registered.listen(
        send_signup_email,
        listener_name="send_signup_email"
    )

Where to start?

Starting with the tutorials section will give you a practical introduction to Lightbus. Alternatively, the explanation section will give you a grounding in the high level concepts and theory.

Start with whichever section suits you best. You should ultimately look through both sections for a complete understanding.