Silk /

Filename Size Date modified Message
141 B
1.5 KB
72 B
2.2 KB
25 B
429 B


Everyone expects you to invent your own framework, you might as well do it safely by using Silk. Silk is intended to provide a minimal set of tools that you can use to map HTTP requests and responses to the kind of code that fits your brain.

Also, silk is smooth.


Silk is pre-pre-Alpha. The code here might work, but it's mainly a playground for me to experiment with WSGI concepts. Maybe it will grow up some day, but for now, Caveat Emptor.


Writing a web app is centered around the idea of accepting a request, and returning a response. If that's all you want to do, then Silk tries to stay out of your way.:

from silk import Application, Response

def hello(request, config):
    return Response("Hello World")

handlers = {
    r'^/hi/$': hello,

if __name__ == "__main__":

Of course, if that's all you wanted your app to do, you would just use Apache and serve up a bog-standard HTML page. Let's turn our "page" into something that resembles an application.:

from silk import Application, Response

def hello(request, config, name="World"):
    return Response("Hello "+name)

handlers = {
    r'^/hi/(?P<name>.*?)/$': hello,

if __name__ == "__main__":

Now we've decided instead of plain text, we're interested in actually writing some HTML. The view() decorator will take a dict-returning controller and render a template with the appropriate context.

### views/hello.html <html>

<h1>Hello {{name}}</h1>


### apps/ from silk import WebApp

app = WebApp()

@app.view("hello.html") @app.mount("/hello", name=":word") def hello(request, name="World"):

return locals()
if __name__ == "__main__":

At this point, we've reached feature-parity with 90% of the web frameworks out there. We can accept requests, pick a controller function based on the URL, assemble some data and render it through a templating language. For an app of this size, there's a very high signal-to-noise ratio in the code.