PyPi README Page

circuits is a Lightweight Event driven and Asynchronous Application Framework for the Python Programming Language with a strong Component Architecture.

circuits also includes a lightweight, high performance and scalable HTTP/WSGI compliant web server as well as various I/O and Networking components.

Got questions?

Examples

Hello

 1#!/usr/bin/env python
 2
 3"""circuits Hello World"""
 4
 5from circuits import Component, Event
 6
 7
 8class hello(Event):
 9
10    """hello Event"""
11
12
13class App(Component):
14
15    def hello(self):
16        """Hello Event Handler"""
17
18        print("Hello World!")
19
20    def started(self, component):
21        """Started Event Handler
22
23        This is fired internally when your application starts up and can be used to
24        trigger events that only occur once during startup.
25        """
26
27        self.fire(hello())  # Fire hello Event
28
29        raise SystemExit(0)  # Terminate the Application
30
31App().run()

Download Source Code: hello.py:

Echo Server

 1#!/usr/bin/env python
 2
 3"""Simple TCP Echo Server
 4
 5This example shows how you can create a simple TCP Server (an Echo Service)
 6utilizing the builtin Socket Components that the circuits library ships with.
 7"""
 8
 9from circuits import Debugger, handler
10from circuits.net.sockets import TCPServer
11
12
13class EchoServer(TCPServer):
14
15    @handler("read")
16    def on_read(self, sock, data):
17        """Read Event Handler
18
19        This is fired by the underlying Socket Component when there has been
20        new data read from the connected client.
21
22        ..note :: By simply returning, client/server socket components listen
23                  to ValueChagned events (feedback) to determine if a handler
24                  returned some data and fires a subsequent Write event with
25                  the value returned.
26        """
27
28        return data
29
30# Start and "run" the system.
31# Bind to port 0.0.0.0:8000
32app = EchoServer(("0.0.0.0", 8000))
33Debugger().register(app)
34app.run()

Download Source Code: echoserver.py:

Hello Web

 1#!/usr/bin/env python
 2
 3from circuits.web import Controller, Server
 4
 5
 6class Root(Controller):
 7
 8    def index(self):
 9        """Index Request Handler
10
11        Controller(s) expose implicitly methods as request handlers.
12        Request Handlers can still be customized by using the ``@expose``
13        decorator. For example exposing as a different path.
14        """
15
16        return "Hello World!"
17
18app = Server(("0.0.0.0", 8000))
19Root().register(app)
20app.run()

Download Source Code: helloweb.py:

More examples

Features

  • event driven

  • concurrency support

  • component architecture

  • asynchronous I/O components

  • no required external dependencies

  • full featured web framework (circuits.web)

  • coroutine based synchronization primitives

Requirements

Supported Platforms

  • Linux, FreeBSD, Mac OS X, Windows

  • Python 2.7, 3.4, 3.5, 3.6

  • pypy (the newer the better)

Installation

The simplest and recommended way to install circuits is with pip. You may install the latest stable release from PyPI with pip:

$ pip install circuits

If you do not have pip, you may use easy_install:

$ easy_install circuits

Alternatively, you may download the source package from the PyPi or the Downloads extract it and install using:

$ python setup.py install

Note

You can install the development version via pip install circuits==dev.

License

circuits is licensed under the MIT License.

Feedback

We welcome any questions or feedback about bugs and suggestions on how to improve circuits.

Let us know what you think about circuits. @pythoncircuits.

Do you have suggestions for improvement? Then please Create an Issue with details of what you would like to see. I’ll take a look at it and work with you to either incorporate the idea or find a better solution.

Community

There are also several places you can reach out to the circuits community:


Disclaimer

Whilst I (James Mills) continue to contribute and maintain the circuits project I do not represent the interests or business of my employer Facebook Inc. The contributions I make are of my own free time and have no bearing or relevance to Facebook Inc.