Jupiter is an AIO Web framework based on AIOHTTP. Support (restful format, scan annotations, dependency injection, Jinja2 template engine, ORM framework).

Core Components


1. Jupiter_http (AIO Web Framework)

Introduction: Based on AIOHTTP, the extension of scan annotation, dependency injection, Jinja2 template engine, support a variety of requests. Use asynchronous event drivers to maximize CPU performance.

Installation:

pip install jupiter_http
Copy the code

Use scenario: Web project development, want to adopt the asynchronous event-driven model, do not want to use Django, flask based on Python multi-threaded web framework.

>>>>>> Performance comparison website

Sample code:

1. Return HTML (GET request)

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

2. Return the Jinja2 template, blogs1.html, with __user__ and blogs parameters injected into the template (get request)

@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}}]Copy the code

Redirect: You can redirect (get requests)

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

4, POST request, with file is a form request, without file is a JSON request (both supported, keyword file is the file extracted from the form)

@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'}Copy the code

5, jupiter_HTTP framework Demo (configure aioinit. py file, and then start this file can be)

>>>>>> jupiter_HTTP Demo


2. Jupiter_orm (AIO ORM framework)

Introduction: Based on AIOMysQL, extended ORM operation database mode.

Installation:

pip install jupiter_orm
Copy the code

Usage scenario: To operate on a database, you want to adopt an asynchronous event-driven model instead of blocking the database.

Sample code:

1. Create an entity class that inherits 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()Copy the code

2. Query the list

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

3. Query quantity

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

4. Query by primary key

user = await TestModelC.find('cd3dc2dab4b940a5b4dde8318a27a9d7')Copy the code

5, inserted

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

6, modify,

testModel.name = '23277732'
result = await testModel.update()Copy the code

7, delete,

testModel1 = TestModelC(id=testModel.id)
result = await testModel1.remove()Copy the code

8, Jupiter_ORm Demo (create jupiterormtest. SQL database, modify dbunit. py configuration, and then start this file can be)

> > > > > > jupiter_orm Demo


More Details

>>>>>>jupiter_http For details

>>>>>>jupiter_orm details

>>>>>>jupiter_config details

Jupiter address:

>>>>>>github

> > > > > > code cloud