A simple asynchronous Python web framework built on aiohttp.
Project description
Mokei
Mokei is a simple asynchronous Python web framework built on aiohttp.
Aiohttp contains a great async web server, with web framework built in, but can be complex when compared to other web frameworks.
Mokei makes setting up your routes as simple as using Flask or FastAPI. It also includes super easy websocket routes with support for text and binary messages, as well as SocketIO-style event handlers.
Quick Start
from mokei import Mokei
app = Mokei()
@app.get('/')
async def hello():
return 'Hello, World!'
if __name__ == '__main__':
app.run()
Return JSON data
When the return type from the handler is a dict
, the response is automatically converted to application/json
@app.get('/status')
async def status():
return {
'status': 'OK',
}
Adding Websocket support
Adding a websocket route is as simple as adding a normal get route.
Note that you may send websocket messages to a route or to a single websocket (compare websocket.send_text and data.send_text below)
app = Mokei()
data = app.websocketroute('/data')
@data.onconnect
async def send_welcome_text(websocket):
await websocket.send_text('Welcome!')
@data.ontext
async def relay_text(websocket, text):
# log incoming text and relay to all other websockets
logger.info('Received text %s', text)
await data.send_text(text, exclude=websocket)
SocketIO-style events are also supported. See js/mokei.js
for a Javascript handler for Mokei WebSockets.
app = Mokei()
data = app.websocketroute('/data')
@data.on('ping')
async def send_pong(websocket, data):
update_something(websocket)
await websocket.send_event('pong', {'timestamp': time.time()})
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file mokei-0.2.10.tar.gz
.
File metadata
- Download URL: mokei-0.2.10.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cdefb708e1561e191cea478070b5c5c95ca6ed581b27b32d50f9f76e1c4bf73 |
|
MD5 | 310e89634ef6340172c6696e384d280b |
|
BLAKE2b-256 | 448630536232735df25844ba620ebfa886d9a47f615dc124f1e88df13cf2e64f |
File details
Details for the file mokei-0.2.10-py3-none-any.whl
.
File metadata
- Download URL: mokei-0.2.10-py3-none-any.whl
- Upload date:
- Size: 14.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3b6b1a1d59252634d9f05190485a121cabf2c5fcc0c576f38f48fd3a6408b0ef |
|
MD5 | 9db0eb72e40eed178ac469b9267e4eb9 |
|
BLAKE2b-256 | fbc61ae63d2d49933bbede4062d32b2e94f1c0885384a31a7151e47647c4ed63 |