Welcome to pycommunicate

What is pycommunicate?

pycommunicate is a python web-server library designed to make server-heavy webapps easy!

In other words, this library is similar to others (in fact it wraps flask to work), but with one very amazing difference: you can modify the dom from the server

You can attach events to elements, change properties, and much more!

Want to get started? Well you’re in the right place, because this is the documentation! :)

Example

This is code from examples/hello.py found in the docs folder.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
"""
hello.py:

Using the pycommunicate framework to serve a static webpage, as well as show internal id numbers. It also shows off the
session variables.

Because the returned value does not load the js libs, the socketio connection is not started. This means that
none of the apis will work nor will load ever be called. Again, this is a very simple demo.

WARNING: DO NOT ACTUALLY SHOW THE USER ID TO A USER!!
"""

from pycommunicate.server.app.communicate import CommunicateApp
from pycommunicate.server.bases.controller import ControllerFactory
from pycommunicate.server.bases.views import View


class HelloView(View):
    def render(self):
        if 'count' in self.controller.user.session:
            self.controller.user.session['count'] += 1
        else:
            self.controller.user.session['count'] = 1
        return ("Hello World! My user id is {}, and my request id is {}. The session says you have requested this {}"
                " times").format(
            self.controller.user.id_,
            self.controller.user.request_id,
            self.controller.user.session['count'])


app = CommunicateApp()
controller = ControllerFactory().add_view(HelloView).set_default_view(HelloView)

app.add_controller("/", controller)

app.set_secret_key("secret!!!")
app.run()