pysage is a lightweight high-level message passing Python library supporting actor based concurrency.
It also extends the "actor model" to support actor partitioning/grouping to further scalability. pysage has a simple high-level interface. Messages are serialized and sent lightweight using pipes or domain sockets across local "groups". In the case of network messages, UDP is used.
* simple pythonic API
* efficient message propagation within group, across group, across network
* network messages can optionally be configured to be reliable and/or ordered using UDP
* grouping - actors can be partitioned into groups that are run in separate os processes
* process-local singleton manager - actor registration, discovery, message propagation
* publisher/subscriber pattern built-in
pysage strives to stay thin and lightweight.
pysage can be installed via setuptools:
Here, we have a simple actor that receives a "take damage" message in a 30 ticks/sec game loop.
from pysage import Actor, ActorManager, Message
mgr = ActorManager.get_singleton()
properties = ['damage']
packet_type = 101
subscriptions = ['BombMessage']
def handle_BombMessage(self, msg):
print 'I took %s damage from the bomb' % msg.get_property('damage')
processed = mgr.tick()
pysage allows you to use this same simple API, for messaging across processes and networks.
pysage does not confine you to the constraints of the "actor model". For example, the "grouping" concept allows many actors to reside in the same process. This allows you to avoid spawning too many os processes and reduce IPC overhead.
Further, actors in the same group are local to each other, so they can have access to each other. It's kind of like a: "what happens in the group, stays in the group" concept. Although, using messages are encouraged instead of straight calls for most situations, even in the same pysage group.