
Lahja – A generic event bus implementation written in Python - cburgdorf
https://github.com/ethereum/lahja
======
adamcharnock
I've been working on something similar for a while now called Lightbus:
[https://lightbus.org](https://lightbus.org)

Like Lahja this too is rather much in the alpha stage, but I have been using
it in production for over a year now.

I mention it here in case it is interesting to anyone, interest/feedback
always welcome!

------
steventhedev
From glancing at the code, this is an observer pattern over asyncio and unix
sockets. That means you're unable to communicate outside the current machine
(short of hacks like ssh socket forwarding), but adding support for tcp
endpoints shouldn't be too hard.

I'd be interested to see how well this holds up under load, especially
compared to other common event bus patterns.

~~~
pipermerriam
We've talked a bit about adding TCP support and really like some of the
options it opens up. However, we have to move away from the use of pickle for
event serialization before we can do that, otherwise we would have some
security issues with remote code execution.

------
eerikkivistik
Any chance the name is a play on words from the Estonian word "Lahja" as in
light-weight?

~~~
cxcorp
Good question, could also be the Finnish word "lahja" that translates to
"gift"

~~~
xlog
Could also mean 'talent'.

------
d__k
What is the closest (conceptual) analogue for this model:

\- [https://github.com/jodal/pykka](https://github.com/jodal/pykka) (Python)

\- [https://github.com/quantmind/pulsar](https://github.com/quantmind/pulsar)
(Python)

\- [https://github.com/akka/akka](https://github.com/akka/akka) (Java)

\- [https://github.com/eclipse-vertx/vert.x](https://github.com/eclipse-
vertx/vert.x) (Java)

\- etc.

------
kitd
Neat.

This feels quite a bit like Vert.x from the Java world, which flows data
between components via an event bus.

Noob python question: does Python support reactive extensions and chaining?
That would fit well on top of this too.

~~~
linsomniac
There is RxPY:
[https://rxpy.readthedocs.io/en/latest/](https://rxpy.readthedocs.io/en/latest/)

------
poorman
Pair this with Arrow IPC and you're golden
[https://arrow.apache.org/docs/python/ipc.html](https://arrow.apache.org/docs/python/ipc.html)

------
leetrout
That’s pretty neat!

I’ve used Redis in the past for lightweight pub/sub and zeromq for IPC before
we had adopted Python 3 (and I left that job before then). I hated juggling
threads and queues before that and then having to run Redis just to run your
program was a pain.

The syntax looks similar enough to both of those to get started quickly and
easily.

I’ve been writing Go so much I don’t know how much this is “needed” in Python
but the examples using context managers ring the “it’s Pythonic” bell.

------
turbinerneiter
How does this compare to D-Bus and when would you use which (apart from D-Bus
obviously being Linux-only)?

------
Tinfoilhat666
Is this somehow connected to processing cryptocurrencies? This is under
ethereum repo.

~~~
pipermerriam
It's a library we use in the "Trinity" client for the ethereum network. The
lahja library itself is however just an event bus and has no cryptocurrency
ties other than being used in the Trinity codebase.

[https://trinity.ethereum.org/](https://trinity.ethereum.org/)

------
sandGorgon
what is the usecase for something like this versus celery/rq ?

~~~
nurettin
AFAIK, celery doesn't provide a message passing bus between main process and
sub-processes.

~~~
zbentley
Well, it technically does (through its invocations of billiard, it's
multiprocessing fork), but it's pretty ad hoc and not exposed for much user
control. So you're basically right, I'm just being pedantic.

~~~
nurettin
Yes ok initial parameter passing and gathering results may be considered a
message bus. I was going to mention that, but I got lazy.

------
curzondax
cannot make sense of this library. whats this for?

~~~
StavrosK
Seems to be pubsub for asyncio.

------
kgraves
Love to try this out some day, a shame that this isn't in Python 2.

EDIT: Thanks HN, try working in an industry where every new project is in
Python 2, and have no intention to move on, before saying "moeve to 3", it
doesn't help at all.

~~~
newaccoutnas
[https://pythonclock.org/](https://pythonclock.org/) \- 5 Months and 2 days to
go. Do not do any new projects in Python 2. There is no technical reason for
you to do so. If management is an issue, show them the facts.

Also, Python 3.9 is now out which means there's been _more_ than enough time
to migrate -
[https://docs.python.org/3.9/whatsnew/3.9.html](https://docs.python.org/3.9/whatsnew/3.9.html)

~~~
newen
Seriously though, why would a company want to start a months long project of
moving from python 2 to 3, when their current setup works perfectly, and the
project involves the horrifying boring chore of going through every single
line of code and making simple changes, and hope that their tests still works,
there are no edge cases that crop up due to minor changes in the new version,
etc., etc., etc. Seems much more sensible to stick with something that works.

~~~
newaccoutnas
Well, because you're developing against an unsupported runtime. No bug or
_security_ updates. If that's fine for you, feel free, otherwise get with the
(supported) program.

If it's a new project, there are no excuses imho

~~~
newaccoutnas
In addition I don't think you'd have to interrogate every line, depending on
your codebase and upstream module support for Python 3. There are tools like:

[http://python-future.org/automatic_conversion.html](http://python-
future.org/automatic_conversion.html) and [https://python-
modernize.readthedocs.io/en/latest/](https://python-
modernize.readthedocs.io/en/latest/)

Which should get you most of the way there. Look at
[https://docs.python.org/3/howto/pyporting.html](https://docs.python.org/3/howto/pyporting.html)
for more info

