Skip to main content

The minimalistic Python Actor middleware

Project description

PyActor is a python actor middleware for an object oriented architecture constructed with the idea of getting two remote actors to quickly communicate in a very simple, lightweight and minimalistic way.

It supports two versions:

  • Threading

  • Gevent green threads

It also includes communication between machines using XMLRPC and a second version that uses RabbitMQ message system in a transparent way.

Installation

Install using:

python setup.py install

or:

pip install pyactor

Check that works executing the examples that you can find by cloning the repository:

cd examples
python sample1.py
...

Check also the docs for a tutorial:

Documentation Status

Commits are build and tested automatically at Travis-CI.

https://travis-ci.org/pedrotgn/pyactor.svg?branch=master

See code coverage at codecov.io or coveralls.io.

https://codecov.io/gh/pedrotgn/pyactor/branch/master/graph/badge.svg

The code is also checked for its health at every push by landscape.io (PEP8, common bad smells, etc.):

Code Health

First steps

This library is implemented using two types of concurrence:

  • 'thread' : classic threads

  • 'green_thread' : Gevent

Green threads give a performance almost twice better.

You will need to specify which one you are going to use at the beginning of your script with set_context('TYPE'). Where type is one of the two keywords above.

Then, first of all, a Host is needed in order to create some actors. Use it to spawn actors by giving the class type of the actor to create and one string that will identify it among the host. See example:

h = create_host()
actor1 = h.spawn('id1', MyClass)

The class of an actor must have defined its methods in the _tell and _ask lists so they can be called through the proxy. In the _tell list will be named those methods meant to be asynchronous and in the _ask list, the synchronous ones. In this example we have a class MyClass with a sync method ask_me() and an async method tell_me():

class MyClass:
    _tell =['tell_me']
    _ask = ['ask_me']
    def tell_me(self, msg):
        print msg
    def ask_me(self):
        return 'hello back'

As you can see, the async method receives a message and simply prints it while the sync method returns a result. You can now call this methods from your main code:

actor1.tell_me('Hello')
print actor1.ask_me()

Remote connections

Unlike other library solutions, PyActor supports remote communication between various machines by only giving an IP to the host. For example:

host = create_host('http://127.0.0.1:1277/')

An this host is online, so the other machine only needs to lookup for it:

host = create_host('http://127.0.0.1:1679')
remote_host = host.lookup_url('http://127.0.0.1:1277/', Host)

Or directly get one of its actors:

c = host.lookup_url('http://127.0.0.1:1277/id1', 'MyClass', 'module')

Tutorial

PyActor has many examples and a tutorial explaining all its functionalities. This examples can be found in the 'pyactor/examples' directory of the project (github). They are also explained in the documentation as a tutorial, hosted at readthedocs.org which you can find above.

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

pyactor-1.4.0.tar.gz (25.6 kB view details)

Uploaded Source

Built Distribution

pyactor-1.4.0-py2-none-any.whl (34.5 kB view details)

Uploaded Python 2

File details

Details for the file pyactor-1.4.0.tar.gz.

File metadata

  • Download URL: pyactor-1.4.0.tar.gz
  • Upload date:
  • Size: 25.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyactor-1.4.0.tar.gz
Algorithm Hash digest
SHA256 b54a6449f984e8a63b4b6f35b5cd5d9659f97a2870285b7a9bc6f59ee9938d40
MD5 3e7d799d2a5882354cee7a6fddce2ef4
BLAKE2b-256 a56dcb370f43eb2632e21a1220dbca5eca57ae3846f47f6c4ef507a5333c99a9

See more details on using hashes here.

File details

Details for the file pyactor-1.4.0-py2-none-any.whl.

File metadata

File hashes

Hashes for pyactor-1.4.0-py2-none-any.whl
Algorithm Hash digest
SHA256 102a011ee65f03c6a9d0ed0d392efd447333c5c66b2b788ee97beab215848ba4
MD5 c79c2b4b4681ba9d30e8d5a7a1c1618f
BLAKE2b-256 c1b49c21e1f0a4aa0cbe52b22da0a008c9a41516180ceb366da755c8ece6235b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page