Package: tao1
[![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=plastic)](http://opensource.org/licenses/MIT)[![PyPI version](https://badge.fury.io/py/tao1.svg)](https://badge.fury.io/py/tao1)# Introduction.This asynchronous framework with a modular structure like Django. But with mongodb, jinja2, websocket out of the box,and more than a simple barrier to entry.Built on the basis of asyncio and aiohttp. In the framework, have batteries. The prototype of the game framework as a component.###RequirementsPython >= 3.5.1aiohttp == 0.20.2aiohttp_jinja2aiohttp_sessionaiohttp_debugtoolbaraiomcachepymongo###Installation Python 3.5 for ubuntu```bashsudo add-apt-repository ppa:fkrull/deadsnakessudo apt-get updatesudo apt-get install python3.5 python3.5-dev```#Framework Installation```bash$ pip install tao1```##Getting StartedCreate a project anywhere:```bashutils.py -p name```Create an application in the folder of the project apps:```bashutils.py -a name```Run server:```bashpython3 index.py```##LicenseIt's *MIT* licensed and freely available.##DeployWhen you develop enough to run the file `python3 index.py`.For production to run `index.py`, is better to use the `supervisor` and `nginx`.Settings supervisor in `/etc`:```python[program:name]command=python3 index.pydirectory=/path/to/your/projectuser=nobodyautorestart=trueredirect_stderr=true```Settings nginx in `/etc` together with proxy websocket::```nginxserver {server_name        aio.dev;location / {proxy_pass http://127.0.0.1:8080;}location /ws {proxy_pass http://127.0.0.1:8080;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "upgrade";}}```###RoutesExample route in file `routes.py`::```pythonfrom libs.game.game import  *from core.union import routeroute('GET', '/ws',  ws,	'ws' )```###TemplatesIn framework integrated `jinja2`. Templates are always in the `templ` folder.To call the template function `templ` and pass it the template name. If the template is in some sort of module,the call looks like this `libs.modul_name.templ_name`.If the template is in the root of the project in the templ folder, then simply write his name.Example:```pythondef page(request):return templ('index', request, {'key':'val'} )```###WebsocketsThe websocket to create games and chat very easy to use.The first is the need to call route with the template to draw the route and chat with the handler for chat:```pythonroute('GET', '/ws',   ws,    'ws' )route('GET', '/wsh',  ws_handler, 'ws_handler' )```These routes work you can see an example.The second is the functions themselves.Function for render chat page:```pythonasync def ws(request):return templ('libs.app:chat', request, {} )```Function handler chat:```pythonasync def ws_handler(request):ws = web.WebSocketResponse()await ws.prepare(request)async for msg in ws:if msg.tp == aiohttp.MsgType.text:if msg.data == 'close':await ws.close()else:ws.send_str(msg.data + '/answer')elif msg.tp == aiohttp.MsgType.error:print('ws connection closed with exception %s' % ws.exception())print('websocket connection closed')return ws```###DatabaseTo write the database query you need to `request.db`and then as usual.```pythonasync def test_db(request):# save docrequest.db.doc.save({"_id":"test", "status":"success"})# find docval = request.db.doc.find_one({"_id":"test"})return templ('apps.app:db_test', request, {'key':val})```###Static filesStatic files it is better to entrust `nginx` but `tao1` able return files.All files must be located in the folder static.If they are the root of the project then the path will be like this `/static/file_name.pg`.If the files are in a certain module, then the path like this `/static/module_name/file_name.jpg`.###CachingCreate cache for function 5 second, the first parameter - name::```python@cache("main_page", expire=5)async def page(request):return templ('index', request, {'key':'val'} )```#GameIn this case, the game framework is a battery, the basic framework. The game is a 3D multiplayer shooting.Prototype game framework have  multiplayer mode, the mini-map, rooms, bot, several typical models of tanks.The client side is written in the framework `WEBGL` babylon.js.###Game startGame start is located on the route `/pregame`.![Image alt](https://github.com/alikzao/tao1/raw/master/docs/_static/game.jpg)###More detail documentation about game.<http://tao1.readthedocs.org/en/latest/game.html>###More detailed documentation about base framework<http://tao1.readthedocs.org/en/latest/>