cuba

Modern web framework that uses brand new Python 3.x features


Keywords
web, framework, asyncio
License
MIT
Install
pip install cuba==0.0.1

Documentation

cuba Build Status Join the chat at https://gitter.im/dveselov/cuba

Modern web framework that uses brand new Python 3.x features

Features

Example

from cuba import Application, View
from cuba.types import ResponseType


class QuotesView(View):

    quotes = [
        "Aggression is simply another name for government",
        "Capitalism is at least tolerable, which cannot be said of Socialism or Communism",
        "The moment that justice must be paid for by the victim of injustice it becomes itself injustice",
    ]

    def index(self, request) -> ResponseType.JSON:
        # response converted to JSON (using json.dumps function)
        return self.quotes

    def get(self, request, index: int) -> ResponseType.JSON:
        # @index casted to int type, according to its type annotation
        return {
            "quote": self.quotes[index]
        }

if __name__ == "__main__":
    app = Application()

    view = QuotesView()
    view.register(app)

    app.run(("localhost", 8080))

$ curl -i http://localhost:8080/quotes/1/

HTTP/1.1 200 OK
CONTENT-TYPE: application/json; charset=utf-8
CONTENT-LENGTH: 93
CONNECTION: keep-alive
DATE: Tue, 10 Mar 2015 12:07:16 GMT
SERVER: Python/3.4 aiohttp/0.14.4

{"quote": "Capitalism is at least tolerable, which cannot be said of Socialism or Communism"}