Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

A SOA framework in Python

Project Description

Vyked is an asyncio based python framework for service oriented architectures.

Requirements

Installation

$ pip install vyked

Vyked uses jsonstreamer, a fast streaming JSON parser for Python that generates SAX-like events using the yajl C library. To install yajl:

$ git clone git@github.com:lloyd/yajl.git
$ cd yajl
$ ./configure && make install

Getting Started

Service Registry

When Vyked services start they register with the service registry by advertising their name, ip,port and the names of other Vyked services they might require to function. The registry then co-ordinates all Vyked services and even balances loads across multiple instances of each service.

Vyked uses redis for pub-sub and registry storage, you must start a redis instance before you start the vyked registry.

You must start the Vyked registry before any services, as such:

$ python -m vyked.registry

or :

from vyked import Registry

registry = Registry('127.0.0.1', 4500)
registry.start()

Service

Vyked allows you to host HTTP and TCP services.

TCP Services

Vyked TCP services provide an RPC-like api by decorating typical class methods with decorators. There are two types of api’s available,

  • Request-Response using @api to provide such an api and @request to consume it from a remote client
  • Publish-Subscribe using @publish to automatically publish an event and @subscribe to receive it at a remote client

The following basic examples illustrate these decorators for both Services and remote Clients.

Sample TCP service:

from asyncio import sleep
from vyked import Host, TCPService, api, publish

class IdentityTCPService(TCPService):
    def __init__(self, ip, port):
        super(IdentityTCPService, self).__init__("IdentityService", 1, ip, port)

    @api
    def create(self, user_name, password):
        result = yield from sleep(5) #long running task
        if user_name is None:
            raise Exception('username cannot be none')
        return result

    @publish
    def password_changed(self, user_name):
        """ calling this method from within your code will cause a 'password_changed' event to be published
        to all subscribing services
        """
        # @publish decorated methods must return a dict of values to be published
        return locals() # easy way to return a dict containing all the params - in this case, user_name.

Sample HTTP service:

Vyked uses aiohttp to setup HTTP server.

from vyked import Host, HTTPService, get, post, Response, Request

class IdentityHTTPService(HTTPService):
    def __init__(self, ip, port):
        super(IdentityHTTPService, self).__init__("IdentityService", 1, ip, port)

    @get(path='/users/{username}')
    def get(self, request: Request):
        username = request.match_info.get('username')
        return Response(status=200, body=("Hello {}".format(username)).encode())

    @post(path='/users/{username}')
    def create(self, request: Request):
        data = yield from request.json()
        return Response(status=200, body=(json.dumps(data)).encode())

To start a service:

if __name__ == '__main__':
    http = IdentityHTTPService('0.0.0.0', 4501)
    tcp = IdentityTCPService('0.0.0.0', 4502)
    Host.registry_host = '127.0.0.1'
    Host.registry_port = 4500
    Host.pubsub_host = '127.0.0.1'
    Host.pubsub_port = 6379
    Host.name = 'Identity'
    Host.attach_service(http)
    Host.attach_service(tcp)
    Host.run()

Client

So far, the examples have only covered standalone services. But a service might interact with other services. To make such an interaction possible, vyked provides a TCP and HTTP client to interact with TCP and HTTP service respectively.

Sample TCP client for IdentityService we saw in the above example:

from vyked import Host, TCPService, TCPServiceClient, api, publish, request, subscribe
import asyncio

class IdentityClient(TCPServiceClient):
    def __init__(self):
        super(IdentityClient, self).__init__("IdentityService", 1)

    @request
    def create(self, user_name, password):
        return locals() #@request requires a dict containing params describing the request payload

    @subscribe
    def password_changed(self, user_name):
        print("Password changed event received")
        yield from asyncio.sleep(4)

Sample HTTP Client:

class Hello(HTTPServiceClient):
    def __init__(self):
        super(Hello, self).__init__('Hello', 1)

    @get()
    def person(self, name):
        path = '/{}'.format(name)
        params = {'key': 'value'}
        headers = {'Content-Type': 'application/json'}
        app_name = 'test'
        return locals()

Documentation

View documentation at read-the-docs

License

vyked is offered under the MIT license.

Source code

The latest developer version is available in a github repository: https://github.com/kashifrazzaqui/vyked

Release History

Release History

This version
History Node

2.1.91

History Node

2.1.90

History Node

2.1.89

History Node

2.1.88

History Node

2.1.87

History Node

2.1.86

History Node

2.1.85

History Node

2.1.84

History Node

2.1.83

History Node

2.1.82

History Node

2.1.81

History Node

2.1.80

History Node

2.1.78

History Node

2.1.77

History Node

2.1.76

History Node

2.1.75

History Node

2.1.74

History Node

2.1.73

History Node

2.1.72

History Node

2.1.71

History Node

2.1.70

History Node

2.1.69

History Node

2.1.68

History Node

2.1.67

History Node

2.1.66

History Node

2.1.65

History Node

2.1.64

History Node

2.1.63

History Node

2.1.62

History Node

2.1.61

History Node

2.1.60

History Node

2.1.59

History Node

2.1.58

History Node

2.1.57

History Node

2.1.56

History Node

2.1.55

History Node

2.1.54

History Node

2.1.53

History Node

2.1.52

History Node

2.1.51

History Node

2.1.50

History Node

2.1.49

History Node

2.1.48

History Node

2.1.47

History Node

2.1.46

History Node

2.1.45

History Node

2.1.44

History Node

2.1.43

History Node

2.1.42

History Node

2.1.41

History Node

2.1.40

History Node

2.1.39

History Node

2.1.37

History Node

2.1.36

History Node

2.1.35

History Node

2.1.34

History Node

2.1.33

History Node

2.1.32

History Node

2.1.31

History Node

2.1.30

History Node

2.1.29

History Node

2.1.28

History Node

2.1.27

History Node

2.1.26

History Node

2.1.25

History Node

2.1.24

History Node

2.1.23

History Node

2.1.22

History Node

2.1.21

History Node

2.1.20

History Node

2.1.19

History Node

2.1.18

History Node

2.1.17

History Node

2.1.16

History Node

2.1.15

History Node

2.1.14

History Node

2.1.13

History Node

2.1.12

History Node

2.1.11

History Node

2.1.10

History Node

2.1.9

History Node

2.1.8

History Node

2.1.7

History Node

2.1.6

History Node

2.1.5

History Node

2.1.3

History Node

2.1.2

History Node

2.1.1

History Node

2.1.0

History Node

2.0.9

History Node

2.0.8

History Node

2.0.7

History Node

2.0.6

History Node

2.0.5

History Node

2.0.4

History Node

2.0.3

History Node

2.0.2

History Node

2.0.1

History Node

2.0.0

History Node

1.2.64

History Node

1.2.63

History Node

1.2.62

History Node

1.2.61

History Node

1.2.60

History Node

1.2.59

History Node

1.2.58

History Node

1.2.57

History Node

1.2.56

History Node

1.2.55

History Node

1.2.54

History Node

1.2.53

History Node

1.2.52

History Node

1.2.51

History Node

1.2.50

History Node

1.2.49

History Node

1.2.48

History Node

1.2.47

History Node

1.2.46

History Node

1.2.45

History Node

1.2.44

History Node

1.2.43

History Node

1.2.42

History Node

1.2.41

History Node

1.2.40

History Node

1.2.39

History Node

1.2.38

History Node

1.2.37

History Node

1.2.36

History Node

1.2.35

History Node

1.2.34

History Node

1.2.33

History Node

1.2.32

History Node

1.2.31

History Node

1.2.30

History Node

1.2.29

History Node

1.2.28

History Node

1.2.27

History Node

1.2.26

History Node

1.2.25

History Node

1.2.24

History Node

1.2.23

History Node

1.2.22

History Node

1.2.21

History Node

1.2.2

History Node

1.2.1

History Node

1.2

History Node

1.1

History Node

1

History Node

0.1

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
vyked-2.1.91.tar.gz (24.5 kB) Copy SHA256 Checksum SHA256 Source Dec 17, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting