Package: cli-fastweb
Fastweb - 高速迭代 · 快速试错============================|build-status|依赖 ``Tornado`` ``Celery`` ``Thrift`` 开发的快速构建web应用的框架。Web层示例--------.. code-block:: ini;组件配置文件(component.ini);thrift rpc 组件配置[tftrpc:hello_service]host = localhostport = 8888thrift_module = gen-py-tornado.HelloService.HelloServicesize = 10;mysql组件配置[mysql:test_mysql]host = localhostport = 3306user = usernamepassword = passworddb = db_nametimeout = 5charset=utf8size=5awake = 300;mongo组件配置[mongo:test_mongo]host = localhostport = 27017timeout = 10;redis组件配置[redis:test_redis]host = localhostport = 6379db = 1;task组件配置[task:test_task]name = test_taskbroker = amqp://guest:guest@localhost:5672//backend = redis://localhost/0task_class = some_tasks.add.Addqueue = test_task_queueexchange = test_task_exchangerouting_key = test_task_routing_key.. code-block:: python"""handler（handler.test）"""from fastweb import Requestfrom fastweb.web import Api, Pagefrom fastweb.web import coroutine, run_on_executorclass Test(Api):@coroutine@checkArgument(name=str, sex=int)def get(self):# 加载handler级别线程池self.load_executor(5)# handler级别线程池示例r = yield self.test_executor()# mysql使用示例ret = yield self.test_mysql.query('select * from table limit 20;')print self.test_mysql.fetch()# RPC使用示例yield self.hello_service.sayHello()# Redis使用示例yield self.test_redis.call('set', 'name', 'jackson')# Http请求示例request = Request(method='GET', url='http://www.baidu.com')ret = yield self.http_request(request)# 任务调用示例yield self.test_task.call_async(args=(101, 2))x = yield self.test_task.call(args=(101, 2))# responseself.end('SUC', log=False, **{'name':0})# 在handler级别线程池中运行@run_on_executordef test_executor(self):time.sleep(10)return 1000"""服务加载组件和启动"""from fastweb.web import start_web_serverfrom fastweb.loader import appfrom fastweb.pattern import  SyncPattern, AsynPatternif __name__ == '__main__':options.parse_command_line()app.load_recorder('app.log', system_level='DEBUG')app.load_configuration(backend='ini', path='component.ini')app.load_errcode()app.load_component(pattern=AsynPattern, backend='ini', path=options.config)app.load_component(pattern=AsynPattern, backend='ini', path='task.ini')from handler.test import Testhandlers = [(r'/test', Test)]start_web_server(6666, handlers, debug=True, xheaders=False)Task层示例---------.. code-block:: ini;task配置文件(task.ini);task组件配置[task:test_task]name = test_taskbroker = amqp://guest:guest@localhost:5672//backend = redis://localhost/0task_class = some_tasks.add.Addqueue = test_task_queueexchange = test_task_exchangerouting_key = test_task_routing_key.. code-block:: pythonclass Add(object):"""任务"""def run(self, x, y):return x+yif __name__ == '__main__':app.load_recorder('task.log', system_level='DEBUG')app.load_component(pattern=AsynPattern, backend='ini', path='task.ini')start_task_worker()Service层示例------------请参考examples中示例。安装----``python setup install````pip install fastweb``适用场景-------Fastweb是一个快速构建web应用的框架，与Python的哲学相同，都是期望能够让使用者更快速的开发出满足需求的后端代码。高速迭代，快速试错，这是使用Fastweb最大的效益！抉择----关于为什么选择 ``Tornado`` ``Celery`` ``Thrift`` 作为Fastweb的工具集合中的重要成员。.. |build-status| image:: https://travis-ci.org/BSlience/fastweb.svg?branch=master:alt: Build status:target: https://travis-ci.org/BSlience/fastweb