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.
To take full advantage of circuits and its architecture, circuits requires that your application be designed in terms of components and their interactions (events) with each other. An application written using the circuits application framework is maintainable, scalable and easy to develop.
circuits’ Loosely Coupled Component Architecture allows for a high level of Reuse and Scalability. Components are Componsable and much of the component library that circuits ships with are implemented as composed components.
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 `circuits Page on PyPI`_ or the `circuits Downloads page`_ on the `circuits Website`_; extract it and install using:
> python setup.py install
circuits is licensed under the MIT License.
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.
There is also a small community of circuits enthusiasts that you may find on the `circuits IRC Channel`_ and the `circuits Mailing List`_.
Implemented Component.init() support whereby one can define an alternative init() without needing to remember to call super(...) init() takes the same arguments as the normal __init__(...) constructor.
Example:
1 from circuits import Component 2 3 class App(Component): 4 5 def init(self, ...): 6 ...
No. This isn’t anything crazy bout restricting what you can do with components. This new feature allows you as a developer to restrict how many instances of any given component can be running in any given system.
Say you defined a Logger Component but you only wanted and designed for only one instance ever running in a single system. This is how you do it:
1 from circuits import Component 2 3 4 class App(Component): 5 6 singleton = True
All I/O Components now implement the value_changed Event Notification API allowing you to define read Event Handlers that simply return responses.
Example:
1 from circuits.net.sockets import TCPServer 2 3 4 class EchoServer(TCPServer): 5 6 def read(self, sock, data): 7 return data 8 9 10 EchoServer(8000).run()
In previous releases of circuits, a Component could only have a single __tick__ (Tick Function). This restriction is now gone and we’ve made it much simpler to define new Tick Functions by simply using the new @tick decorator.
Example:
1 from circuits import tick 2 3 class MyComponent(Component): 4 @tick 5 def my_tick(self): 6 print ‘time is passing’
In circuits-1.6 we introduced two new primitives.
- .callEvent(...)
- .waitEvent(...)
These two primitives introduced synchronous features to the circuits framework allowing you to pause the execution of an event handler and write almost synchronous-style code whilst remaining asynchronous in the background.
Here are the list of improvements and an example to go with.
1 class A(Component): 2 3 channel = “a” 4 5 def foo(self): 6 return “Hello” 7 8 9 class B(Component): 10 11 channel = “b” 12 13 def foo(self): 14 return “World!” 15 16 17 class App(Component): 18 19 def hello(self): 20 a = yield self.call(Event.create(“foo”), “a”) 21 b = yield self.call(Event.create(“foo”), “b”) 22 yield “{0} {1}”.format(a, b) 23 24 m = Manager() + Debugger() 25 A().register(m) 26 B().register(m) 27 App().register(m) 28 m.start()
For a full list of changes for this release see the Change Log.