Giter VIP home page Giter VIP logo

cow's Introduction

cow framework

Build Status PyPi version PyPi downloads Coverage Status

introduction

cow is a web framework in the sense that it allows users to create tornado applications with configuration, templates and static files very easily without being a different beast.

cow automates most of the boring parts of tornado, allowing users to write only the part that actually matters: the handlers.

installing

Installing cow is as easy as:

pip install cow-framework

how to start a new app

Just create a server.py file that looks like this:

from cow.server import Server
from cow.plugins.motorengine_plugin import MotorEnginePlugin


def main():
    AppServer.run()


class AppServer(Server):
    def get_handlers(self):
        return (
            # Add your handlers here
            # ('/', TestHandler),
        )

    def get_plugins(self):
        # add whatever plug-ins you want to use here
        return [
            MotorEnginePlugin,
        ]

if __name__ == '__main__':
    AppServer.run()

To run your app, just use python server.py, or add the main method to your setup.py file as a command.

how do I add my own handlers

If you open server.py, you'll see that it has a method called get_handlers that should return a list of handlers that will be passed to tornado. This is where you can put your own handlers.

Suppose we have a HelloWorldHandler that writes Hello World to our users, like the following:

from tornado.web import RequestHandler

class HelloWorldHandler(RequestHandler):
    def get(self):
        self.write("Hello World!")

Then in our server.py Server class, we need to add it to a route, like this:

from cow.server import Server as CowServer
from myproject.handlers.hello_world import HelloWorldHandler

class Server(CowServer):
    def get_handlers(self):
        return (
            ('/', HelloWorldHandler),
        )

Now if you run server.py and access http://localhost:4444/ you should see the string Hello World.

how do I test my code

It's really simple. You can use cow's CowTestCase, like this:

from cow.testing import CowTestCase
from myproject.server import Server  # the same server as in the above code

class TestHelloWorld(CowTestCase):
    def get_config(self):
        return {}  # add whatever configuration your app requires

    def get_server(self):
        cfg = Config(**self.get_config())
        return Server(cfg)

    def test_hello_world(self):
        response = self.fetch('/')
        assert response.code == 200
        assert response.body == 'Hello World'

cow's People

Contributors

guilhermef avatar heynemann avatar rfloriano avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.