Giter VIP home page Giter VIP logo

pseud's Introduction

pseud

Continues Integration

Coverage Status

Documentation Status

Pythonic bidirectional-rpc API built on top of ØMQ with pluggable encryption, authentication and heartbeating support.

Features

  1. ØMQ transport layer.
  2. All native python types supported (msgpack).
  3. First citizen exceptions.
  4. Bi-bidirectional (server can initiate calls to connected clients).
  5. Encryption based on CURVE.
  6. Pluggable Authentication.
  7. Pluggable Heartbeating.
  8. Pluggable Remote Call Routing.
  9. Built-in proxy support. A server can delegate the work to another one.
  10. SyncClient (using zmq.REQ) to use within non event based processes. (Heartbeating, Authentication and job execution are not supported with the SyncClient.)

Installation

$ pip install pseud

Execution

The Server

from pseud import Server


server = Server('service')
server.bind('tcp://127.0.0.1:5555')

@server.register_rpc
def hello(name):
    return 'Hello {0}'.format(name)

await server.start()  # this will block forever

The Client

from pseud import Client


client = Client('service', io_loop=loop)
client.connect('tcp://127.0.0.1:5555')

# Assume we are inside a coroutine
async with client:
    response = await client.hello('Charly')
    assert response == 'Hello Charly'

The SyncClient

# to use within a non-asynchronous process or in a command interpreter
from pseud import SyncClient


client = SyncClient()
client.connect('tcp://127.0.0.1:5555')

assert client.hello('Charly') == 'Hello Charly'

The Server send a command to the client

It is important to note that the server needs to know which peers are connected to it. This is why the security_plugin trusted_peer comes handy. It will register all peer id and be able to route messages to each of them.

from pseud import Server


server = Server('service', security_plugin='trusted_peer')
server.bind('tcp://127.0.0.1:5555')

@server.register_rpc
def hello(name):
    return 'Hello {0}'.format(name)

await server.start()  # this will block forever

The client needs to send its identity to the server. This is why plain security plugin is used. The server will not check the password, he will just take into consideration the user_id to perform the routing.

from pseud import Client


client = Client('service',
                security_plugin='plain',
                user_id='alice',
                password='')
client.connect('tcp://127.0.0.1:5555')

# Action that the client will perform when
# requested by the server.
@client.register_rpc(name='draw.me.a.sheep')
def sheep():
    return 'beeeh'

Back on server side, we can send to it any commands the client is able to do.

# assume we are inside a coroutine
sheep = await server.send_to('alice').draw.me.a.sheep()
assert sheep == 'beeeh'

Documentation

Pseud on Readthedocs

pseud's People

Contributors

dependabot[bot] avatar fahhem avatar ticosax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pseud's Issues

zope error - no module name

I have libzmq, czmq, pyzmq installed. I used requirements.txt to install dependencies. There seems to be something with the zope version. The most recent zope interface has no module named name.

https://github.com/zopefoundation/zope.interface/tree/master/src/zope/interface

_______________________ ServerTestCase.test_job_running ________________________

self = <tornado_based.test_server.ServerTestCase testMethod=test_job_running>
args = (), kwargs = {}

    @functools.wraps(coro)
    def post_coroutine(self, *args, **kwargs):
        try:
            return self.io_loop.run_sync(
                functools.partial(coro, self, *args, **kwargs),
>               timeout=timeout)

/usr/local/lib/python2.7/dist-packages/tornado/testing.py:494: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py:418: in run_sync
    return future_cell[0].result()
/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py:109: in result
    raise_exc_info(self._exc_info)
/usr/local/lib/python2.7/dist-packages/tornado/gen.py:175: in wrapper
    yielded = next(result)
tests/tornado_based/test_server.py:80: in test_job_running
    from pseud.common import msgpack_packb
pseud/__init__.py:13: in <module>
    from . import auth, heartbeat, predicate  # NOQA
pseud/auth.py:4: in <module>
    import zope.component
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

    """
    from zope.interface import Interface
    from zope.interface import implementedBy
    from zope.interface import moduleProvides
>   from zope.interface import named
E   ImportError: cannot import name named

/usr/local/lib/python2.7/dist-packages/zope.component-4.2.1-py2.7.egg/zope/component/__init__.py:19: ImportError

python-dateutil is unused?

It seems the only use is to create the UTC object in common.py, but it's not used in pseud anywhere. Could we remove this and remove the dependency on dateutil (at least for installation)?

Import error when installed from github

I installed pseud from the github repo this time as the following:

pip3 install git+https://github.com/ezeep/pseud.git

But got this error:

In [1]: import pseud

ImportError Traceback (most recent call last)
in ()
----> 1 import pseud

/home/ghassen/dev/python/.ve3/pseud/lib/python3.4/site-packages/pseud/init.py in ()
29 raise ImportError
30 except ImportError:
---> 31 from ._gevent import Client, Server # NOQA
32
33

/home/ghassen/dev/python/.ve3/pseud/lib/python3.4/site-packages/pseud/_gevent.py in ()
3 import pprint
4
----> 5 import gevent
6 from gevent.timeout import Timeout
7 import zmq.green as zmq

ImportError: No module named 'gevent'

I don't think using gevent is good thing on python 3.4, the gevent project still not ready for the python 3.

but problem was caused on relative import please change all the relative imports to absolute one example instead of:

from . import auth, heartbeat, predicate

change to:
from pseud import auth, heartbeat, predicate

Linking against system libzmq leads to unexpected testing results

pyzmq tries to link against the system libzmq on installation. I experienced failing tests when running this on Mac with my system libzmq. I will further investigate. Forcing --install-option="--zmq=bundled" solves the issue. There might be a version incompatibility between my libzmq and pyzmq although it should not link against non-supported versions at all.

Tests are sometimes flaky

follow up from #70
Under certain circumstances (CPU load ? Disk IO load ?) some tests are failing.

It seems that increasing the warm-up time of ømq sockets to establish to connection, address this issue.
But, Ideally, I would like to get notified when the socket is ready to resume the init process to not wait more time than necessary.

Server stop responding after remote call failed

I created a method X on the server, and on the other side created I used the SyncClient, connected to the server and I called the remote method, but it failed for some reason, after that server itself stopped responding, I have to restart, otherwise it hands there.

ZMQStream mocking to reduce flakiness

https://github.com/chainreactionmfg/cara/blob/master/tests/cara_pseud_test.py

To reduce flakiness, I took the mocking route and mocked out ZMQStream and ZMQContext. The downside was that I had to implement the ROUTER behavior in the mocked ZMQStream, but now I don't even open a port to test my code and so I can run it a hundred times (in parallel) without any failures. Of course, 100 parallel py.test instances take 40 seconds to return, but none fail now when at least 20% failed before.

Another benefit is I can check the packets that go by for the correct sender, receiver, and data. If you're interested, I can look into putting the fixture into pseud or into a separate shared project like pytest-zmq?

Import error when installed from the pypi

After installing the pseud project from the pip, I had the following error:

In [1]: import pseud

ImportError Traceback (most recent call last)
in ()
----> 1 import pseud

/home/ghassen/dev/python/.ve3/pseud/lib/python3.4/site-packages/pseud/init.py in ()
----> 1 import builtin
2 import logging
3 import os
4 import pprint
5 import uuid

ImportError: No module named 'builtin'

Transfering ownership of pseud

Hi,
This project is dormant since 2 years.

Are you willing to transfer ownership to my account ?
I have a need to revive it.

Use pseud in windows

I try to use pseud as the basic communication tools of my application. However, my client application should run in windows and I failed to make pseud work in windows. So, is any way there to make pseud run in windows?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.