Skip to main content

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

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 sets so they can be called through the proxy. In the _tell set will be named those methods meant to be asynchronous and in the _ask set, 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/')

And 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 features. 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.

Release files for pyactor 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyactor 2.0.1
File Size Uploaded
pyactor-2.0.1.tar.gz 31.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyactor 2.0.1
File Interpreter ABI Platform
pyactor-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 81.7 kB

Release files / pyactor-2.0.1.tar.gz

Download URL pyactor-2.0.1.tar.gz
Size 31.3 kB
Tags Source
SHA-256 checksum
How to use checksums
758b2c9d6964a70b31d3acf596c5a23032207481eac70a4141c5eb014c53645c
BLAKE2b-256 checksum
How to use checksums
2e92dd86de7f943b40c2e00177e479488391ea104afdd164a850c7fc5d0ec3b9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.2

Release files / pyactor-2.0.1-py3-none-any.whl

Download URL pyactor-2.0.1-py3-none-any.whl
Size 50.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69bb0262df12004937ede6f0d21f4922ade95de879172eef8cbce61d4d38e9b9
BLAKE2b-256 checksum
How to use checksums
4f7eb64c3d706b4a3cf1e42a40458125eff94f3ca8f709c002dfbd8769d87454
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.7.2

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.7

2 release files

1.2.6

2 release files

1.2.5

2 release files

1.2.4

2 release files

1.2.3

2 release files

1.2.2

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.9.3

3 release files

0.9.2

2 release files

0.9.1

2 release files

0.9

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page