Skip to main content

Event driven concurrent framework for Python

Project description

Pulsar


Badges:

license pyversions status pypiversion contributors

CI:

circleci coverage appveyor travis docs

Documentation:

https://docs.pulsarweb.org

Downloads:

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

Source:

https://github.com/quantmind/pulsar

Benchmarks:

https://quantmind.github.io/pulsar-bench/

Stack overflow:

questions tagged python-pulsar

Mailing list:

google user group

Design by:

Quantmind and Luca Sbardella

Platforms:

Linux, OSX, Windows. Python 3.5 and above

Keywords:

python, asyncio, multiprocessing, 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 module 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

async with http.HttpClient() as session:
    response1 = await session.get('https://github.com/timeline.json')
    response2 = await session.get('https://api.github.com/emojis.json')

The http client maintains connections alive (by default 15 seconds) and therefore any requests that you make within a session will automatically reuse the appropriate connection. All connections are released once the session exits the asynchronous with block.

Installing

Pulsar has one hard dependency:

install via pip:

pip install pulsar

or download the tarball from pypi.

To speedup pulsar by a factor of 2 or more these soft dependencies are recommended

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:

Examples

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

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.

Pulsar 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:

  • greenlet: required by the pulsar.apps.greenio module and useful for developing implicit asynchronous applications

  • uvloop: if available it is possible to use it as the default event loop for actors by passing --io uv in the command line (or event_loop="uv" in the config file)

  • httptools: if available, the default Http Parser for both client and server is replaced by the C implementation in this package

  • 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

  • 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.

Download files

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

Source Distribution

pulsar-2.0.1.tar.gz (1.8 MB view details)

Uploaded Source

Built Distributions

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

pulsar-2.0.1-py3-none-any.whl (281.3 kB view details)

Uploaded Python 3

pulsar-2.0.1-cp36-cp36m-manylinux1_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.6m

pulsar-2.0.1-cp36-cp36m-manylinux1_i686.whl (1.2 MB view details)

Uploaded CPython 3.6m

pulsar-2.0.1-cp36-cp36m-macosx_10_12_x86_64.whl (525.4 kB view details)

Uploaded CPython 3.6mmacOS 10.12+ x86-64

pulsar-2.0.1-cp35-cp35m-manylinux1_x86_64.whl (1.2 MB view details)

Uploaded CPython 3.5m

pulsar-2.0.1-cp35-cp35m-manylinux1_i686.whl (1.1 MB view details)

Uploaded CPython 3.5m

pulsar-2.0.1-cp35-cp35m-macosx_10_12_x86_64.whl (525.8 kB view details)

Uploaded CPython 3.5mmacOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pulsar-2.0.1.tar.gz
Algorithm Hash digest
SHA256 cfc4dad3dda2a9d28c4b7599810aee17418ee7a63cc3851fe8e2f391215aede5
MD5 ac4dceda4d78a9747da71db8c6520c22
BLAKE2b-256 2185df9e2550858e09db6a13baa2b323bd5581510c5ddfc678c392d30cd9d292

See more details on using hashes here.

File details

Details for the file pulsar-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pulsar-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 10990f401c29db93eb78d77b2c7034afcc1812cd0cd3d3951a78a7f8dbfe1564
MD5 783d86fbe3fca947ed0c70e04b66ebf2
BLAKE2b-256 4bad17a95d91f97f1feb8bfd8b6d67a219bd30008d4dc3d1bae5e6a9eb26fc71

See more details on using hashes here.

File details

Details for the file pulsar-2.0.1-cp36-cp36m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for pulsar-2.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3cee6544bfa969bb231a784772050d84a06507befeae4ddb358b5fd5816941bc
MD5 9b91da92a076da9c7d872c18e3050f4c
BLAKE2b-256 55bb53d67e6d398d7f3725613c9bcbaf88a168c6fa60aab61621e661b97bb7ec

See more details on using hashes here.

File details

Details for the file pulsar-2.0.1-cp36-cp36m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for pulsar-2.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 d2f37a2c2a50b16e14869671925b991f70e8bd9f7f6f59ee953d3256f50bcf78
MD5 b1e07626fa44c0ee91f5560b40e33abd
BLAKE2b-256 2eccd418f14c04ef540f3c387939fc7794460f9c553fa879ef72d35f614be5cd

See more details on using hashes here.

File details

Details for the file pulsar-2.0.1-cp36-cp36m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pulsar-2.0.1-cp36-cp36m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 fd0805f681a23e40f5f2388cd9858a52d39b724cc848161866e07bc603066cae
MD5 eb8cbe36acfa162090fb6adca8cdc39d
BLAKE2b-256 75f8ff36df4a69d821368ff3469798eba29d7411dbbf441a615b67586e6d736c

See more details on using hashes here.

File details

Details for the file pulsar-2.0.1-cp35-cp35m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for pulsar-2.0.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 0c9c1a86a179f2a0ac5f65273281df4aa98ccc9da838b2feeed980e3390bbf97
MD5 858a032f8ee59875e6f28ff4d898d29a
BLAKE2b-256 a5a15fdfca92f6f5b2903a989bc9ce4955bca2697329f8fd713d53c089687908

See more details on using hashes here.

File details

Details for the file pulsar-2.0.1-cp35-cp35m-manylinux1_i686.whl.

File metadata

File hashes

Hashes for pulsar-2.0.1-cp35-cp35m-manylinux1_i686.whl
Algorithm Hash digest
SHA256 472b4f025a9da873416c90b97554c4bcbf2f464b8598f512ede396d78bfbed7b
MD5 6d9c9d43f2d8dda2468c4bf92df53b84
BLAKE2b-256 94e03c5fc4835c0c90bda8633cfc7e1d53c347b78700e99d05b7963505d27c69

See more details on using hashes here.

File details

Details for the file pulsar-2.0.1-cp35-cp35m-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pulsar-2.0.1-cp35-cp35m-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 e2064883dbf9c15e832b654d7ae729f3270abf33c601baed2fc89015a643530a
MD5 7ca527d749c592609653465b8dc75540
BLAKE2b-256 c2368264e0b51827c59994dd6a8c844c568d38fc7e25be6be4769f6766df9727

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