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)
Middleware
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 | 100000 | 0.1.1 |
| vibora | 90000 | 0.0.6 |
| meinheld + wsgi | 77000 | 0.6.1 |
| sanic | 50000 | 0.7.0 |
Deploy and Run
python app.py.
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.
Metadata
Release files for xweb 3.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xweb-3.0.1.tar.gz | 4.8 kB | Without provenance | Details for xweb-3.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xweb-3.0.1-py3-none-any.whl | Python 3 | none | any | Details for xweb-3.0.1-py3-none-any.whl |
Total release size: 10.2 kB
Release files / xweb-3.0.1.tar.gz
| Download URL | xweb-3.0.1.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a2e72496996d526bade4a734d4877bba9d0850b700e59542c16e92fc01cacb6e
|
|
BLAKE2b-256 checksum How to use checksums |
1579c75201fc28e377e850f0d16a5934fdc86109b98c4ac9e0f8af49d361eee1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3
|
Release files / xweb-3.0.1-py3-none-any.whl
| Download URL | xweb-3.0.1-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8a7eeb0616cc07c48801a97fc6107082554cc5cfac7ff1e80d09c4248bbacb3d
|
|
BLAKE2b-256 checksum How to use checksums |
1ebff2e7433df95e6293657baff988925ef3208afb5ff59fee7b301c9decb911
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.3
|
Security for xweb 3.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.