Skip to main content

Event driven concurrent framework for Python

Project description

Event driven concurrent framework for python. With pulsar you can write asynchronous servers performing one or several activities in different threads and/or processes.

Badges:

license pyversions status downloads

Master CI:

master-build coverage-master

Dev CI:

dev-build coverage-dev

Documentation:

http://pythonhosted.org/pulsar/

Downloads:

http://pypi.python.org/pypi/pulsar

Source:

https://github.com/quantmind/pulsar

Mailing list:

google user group

Design by:

Quantmind and Luca Sbardella

Platforms:

Linux, OSX, Windows. Python 3.4 and above

Keywords:

client, server, asynchronous, concurrency, actor, thread, process, socket, wsgi, websocket, redis, json-rpc

An example of a web server written with pulsar which responds with “Hello World!” for every request:

from pulsar.apps import wsgi

def hello(environ, start_response):
    data = b'Hello World!\n'
    response_headers = [
        ('Content-type','text/plain'),
        ('Content-Length', str(len(data)))
    ]
    start_response('200 OK', response_headers)
    return [data]


if __name__ == '__main__':
    wsgi.WSGIServer(callable=hello).start()

Pulsar’s goal is to provide an easy way to build scalable network programs. In the Hello world! web server example above, many client connections can be handled concurrently. Pulsar tells the operating system (through epoll or select) that it should be notified when a new connection is made, and then it goes to sleep.

Pulsar uses the asyncio and multiprocessing modules from the standard python library and it can be configured to run in multi-processing mode.

Another example of pulsar framework is the asynchronous HttpClient:

from pulsar.apps import http

session = http.HttpClient()

and somewhere in a coroutine you can wait for responses:

response = await session.get('https://github.com/timeline.json')

Installing

Pulsar has no hard dependencies, install via pip:

pip install pulsar

or downloading the tarball from pypi.

If cython is available, c extensions will be compiled and installed.

Applications

Pulsar design allows for a host of different asynchronous applications to be implemented in an elegant and efficient way. Out of the box it is shipped with the the following:

  • Socket servers

  • WSGI server

  • HTTP client

  • JSON-RPC

  • Web Sockets

  • Test suite

  • Data stores

  • django integration

Examples

Check out the examples directory for various working applications. It includes:

  • Hello world! wsgi example

  • An Httpbin WSGI application

  • An HTTP Proxy server

  • A JSON-RPC Calculator server

  • Websocket random graph.

  • Websocket chat room.

  • django web site with a websocket based chat room.

  • The dining philosophers problem.

Design

Pulsar internals are based on actors primitive. Actors are the atoms of pulsar’s concurrent computation, they do not share state between them, communication is achieved via asynchronous inter-process message passing, implemented using the standard python socket library.

Two special classes of actors are the Arbiter, used as a singleton, and the Monitor, a manager of several actors performing similar functions. The Arbiter runs the main eventloop and it controls the life of all actors. Monitors manage group of actors performing similar functions, You can think of them as a pool of actors.

More information about design and philosophy in the documentation.

Add-ons

Pulsar checks if some additional libraries are available at runtime, and uses them to add additional functionalities or improve performance:

  • setproctitle: if installed, pulsar can use it to change the processes names of the running application.

  • psutil: if installed, a system key is available in the dictionary returned by Actor info method.

  • python-certifi: The [HttpClient][] will attempt to use certificates from certifi if it is present on the system.

  • ujson: if installed it is used instead of the native json module.

  • django: required by the pulsar.apps.pulse application.

  • unidecode: to enhance the slugify function

Running Tests

Pulsar test suite uses the pulsar test application. To run tests:

python setup.py test

For options and help type:

python setup.py test --help

flake8 check (requires flake8 package):

flake8

Contributing

Development of pulsar happens at Github. We very much welcome your contribution of course. To do so, simply follow these guidelines:

  • Fork pulsar on github

  • Create a topic branch git checkout -b my_branch

  • Push to your branch git push origin my_branch

  • Create an issue at https://github.com/quantmind/pulsar/issues with pull request for the dev branch.

  • Alternatively, if you need to report a bug or an unexpected behaviour, make sure to include a mcve in your issue.

A good pull request should:

  • Cover one bug fix or new feature only

  • Include tests to cover the new code (inside the tests directory)

  • Preferably have one commit only (you can use rebase to combine several commits into one)

  • Make sure flake8 tests pass

License

This software is licensed under the BSD 3-clause License. See the LICENSE file in the top distribution directory for the full license text.

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

pulsar-1.3.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pulsar-1.3.0-cp35-cp35m-macosx_10_11_x86_64.whl (349.7 kB view details)

Uploaded CPython 3.5mmacOS 10.11+ x86-64

File details

Details for the file pulsar-1.3.0.tar.gz.

File metadata

  • Download URL: pulsar-1.3.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pulsar-1.3.0.tar.gz
Algorithm Hash digest
SHA256 fb459bbdd64aaf182d51496f688f8fd75c789b0f01f7b1205a77e995b34b9c32
MD5 bd7c0e5ff456cdcc0b56c46f96c4abab
BLAKE2b-256 64360032619336d520b70b1d6161b6dbb45969af85cc390b8c24d32fe19d4c6a

See more details on using hashes here.

File details

Details for the file pulsar-1.3.0-cp35-cp35m-macosx_10_11_x86_64.whl.

File metadata

File hashes

Hashes for pulsar-1.3.0-cp35-cp35m-macosx_10_11_x86_64.whl
Algorithm Hash digest
SHA256 6a3a3154627053db329ea3828a679c194a6492ab77081d5deda5f914d911805f
MD5 8791c920f1300254d67d83443caf343b
BLAKE2b-256 e7c4f95ff1f44ddc7dd41dace962350607fdcd2cb467f570e761fa09475afd71

See more details on using hashes here.

Supported by

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