当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
34 Star 62 Fork 14

电霸儿 / jupiter
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

jupiter

Build Status Codacy Badge License

jupiter是一个aio web框架,基于aiohttp。支持(restful格式、扫描注解、依赖注入、jinja2模板引擎、ORM框架)等。

核心组件介绍


1、jupiter_http(aio web框架)

介绍:基于aiohttp,扩展了扫描注解依赖注入jinja2模板引擎,支持各种请求方式。采取异步事件驱动充分发挥CPU性能。

安装

pip install jupiter_http

使用场景:开发web项目,想采取异步事件驱动模型,不想使用django、flask这些基于Python多线程的web框架时可以使用。

>>>>>>性能比较网址

示例代码

1、返回html(get请求)

@get('/')
async def index():
    return '<h1>hello world</h1>'

2、返回jinja2模板,模板是blogs1.html并携带__user__与blogs参数注入模板(get请求)

@get('/templates')
async def getTemplates():
    return {
        '__template__': 'blogs1.html',
        '__user__': {
            'name': 'jupiter'
        },
        'blogs': [
            {
                'id': uuid.uuid4().hex,
                'name': 'jupiter',
                'summary': 200,
                'created_at': 1501006589.27344
            }
        ]
    }

3、跳转,携带关键字redirect:可以进行跳转(get请求)

@get('/redirect')
async def redirect():
    return 'redirect:http://www.baidu.com'

4、POST请求,携带文件是表单请求,不携带文件是json请求(都支持,关键字file是表单中提取的文件)

@post('/api/examples')
async def api_register_user(request, *, userEmail, userName, userPassword, file=None):
    logging.info('userEmail:%s,userName:%s,userPassword:%s,file:%s' 
	% (userEmail, userName, userPassword, file))
    return {'result': 'success'}

5、jupiter_http框架的Demo(配置AioInit.py文件,然后启动此文件即可)

>>>>>>jupiter_http框架的Demo


2、jupiter_orm(aio ORM框架)

介绍:基于aiomysql,扩展了ORM操作数据库方式。

安装

pip install jupiter_orm

使用场景:操作数据库,想采取异步事件驱动模型,而非阻塞式操作数据库。

示例代码

1、创建实体类,继承ModelC

class TestModelC(ModelC):
    __table__ = 'example'

    id = StringFieldC(primary_key=True, default=uuid.uuid4().hex, ddl='varchar(64)')
    name = StringFieldC(ddl='varchar(255)')
    create_time = DoubleFieldC(default=time.time)
    status = TinyIntFieldC()
    num = IntFieldC()
    price = BigIntFieldC()
    content = TextFieldC()

2、查询列表

rs = await TestModelC.findAll(where="name='name'", limit=(0, 5), orderBy='id')

3、查询数量

num = await TestModelC.findNumber('count(id)', where="name='name'")

4、根据主键查询

user = await TestModelC.find('cd3dc2dab4b940a5b4dde8318a27a9d7')

5、插入

testModel = TestModelC(id=uuid.uuid4().hex, name='name', status=2, num=123, price=111111111119,
					   content='xxxxxxx')
result = await testModel.save()

6、修改

testModel.name = '23277732'
result = await testModel.update()

7、删除

testModel1 = TestModelC(id=testModel.id)
result = await testModel1.remove()

8、jupiter_orm的Demo(创建jupiterormtest.sql数据库,修改DBUnit.py配置,然后启动此文件即可)

>>>>>>jupiter_orm的Demo


更多详细介绍

>>>>>>jupiter_http详细介绍

>>>>>>jupiter_orm详细介绍

>>>>>>jupiter_config详细介绍

jupiter地址:

>>>>>>github

>>>>>>码云

MIT License Copyright (c) 2017 电霸儿 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

jupiter是一个aio web框架,基于aiohttp。支持(restful格式、扫描注解、依赖注入、jinja2模板引擎、ORM框架)等。 展开 收起
Python
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/dianbaer/firstaio.git
git@gitee.com:dianbaer/firstaio.git
dianbaer
firstaio
jupiter
master

搜索帮助

14c37bed 8189591 565d56ea 8189591