High performance web framework built with uvloop and httptools.
Project description
High performance web framework built with uvloop and httptools
In Xweb, everything is asynchronous.
Features
- High performance.
- Asynchronous.
- Small.
Requirements
- Python3.6+
Installation
pip install xweb
Get Started
Hello World
from xweb import App
app = App()
@app.use
async def response(ctx):
ctx.res.body = "Hello World"
if __name__ == '__main__':
app.listen(8000)
Example with middleware.
A middleware is an async function or an async callable object which looks like: async def logger(ctx, fn)
# app.py
import time
from xweb import App
app = App()
@app.use
async def logger(ctx, fn):
await fn()
rt = ctx['X-Response-Time']
print(rt)
@app.use
async def response_time(ctx, fn):
start = time.time()
await fn()
usage = (time.time() - start) * 1000_000
ctx['X-Response-Time'] = f'{usage:.0f}µs'
@app.use
async def response(ctx):
ctx.res.body = "Hello World"
if __name__ == '__main__':
app.listen(8000)
App
- app.use(fn)
- app.listen(host='127.0.0.1', port=8000, debug=True)
Context
- ctx.req
- ctx.res
- ctx.send
- ctx.abort(self, status, msg="", properties="")
- ctx.check(self, value, status=400, msg='', properties="")
Request
ctx.req is a Request object.
- ctx.req.headers dict
- ctx.req.method str
- ctx.req.url str
- ctx.req.raw bytes
- ctx.req.ip str
Response
ctx.res is a Request object.
- ctx.res.body str
- ctx.res.status int
- ctx.res.msg str
- ctx.res.headers dict
Benchmark
- Benchmark code in benchmarks/.
- environment:
iMac (Retina 4K, 21.5-inch, 2017),3 GHz Intel Core i5,8 GB 2400 MHz DDR4 - test command:
wrk http://127.0.0.1:8000/ -c 100 -t 10 -d 10 -T 10
| Frameworks | Requests/Sec | Version |
|---|---|---|
| xweb | 90000 | 0.1.0 |
| vibora | 90000 | 0.0.6 |
| meinheld + wsgi | 77000 | 0.6.1 |
| sanic | 50000 | 0.7.0 |
Deploy
gunicorn -w 4 -k xweb.XWebWorker app:app
Test
pip install -r requirement.txtpytest --cov xweb.py
Contributing
Build Middleware.
XWeb is inspired by koajs. I need some help for writing middleware as in koa. For example:
- Body parser. Convert the raw bytes body into dict or file.
- Data validator. Async data validator with high performance.
- Router. High performance router like koa-router.
- etc..
Open issue.
- Suggestion.
- Bug.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xweb-0.1.0.tar.gz.
File metadata
- Download URL: xweb-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3716d1604c83333c225017152683363af82dc190b394e1c79d0f7b7304dcd41b
|
|
| MD5 |
2190dd973144cc45064915c77e1274d5
|
|
| BLAKE2b-256 |
b894c5735610a779d9903c959501789ae836cb5bd5772a51205026405d3b5507
|
File details
Details for the file xweb-0.1.0-py3-none-any.whl.
File metadata
- Download URL: xweb-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.24.0 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97e08b395bd1d48ecdf1422265946e7a700afded705858a64ddc7c6bf6e202aa
|
|
| MD5 |
14174d3c9f9c3f81ec7095a94fa760d2
|
|
| BLAKE2b-256 |
5c4ff491160307a155a13e41caf059d7ebeb1182cdecbd92aa019de8e8cbec57
|