Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mokei-0.2.3.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mokei-0.2.3-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file mokei-0.2.3.tar.gz.

File metadata

  • Download URL: mokei-0.2.3.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for mokei-0.2.3.tar.gz
Algorithm Hash digest
SHA256 9978be26576975b26eb5045f170cdbfff1394144e2d8a4638b8e2c3bccdecf27
MD5 4369dfee189ceb4acda88d086eba197d
BLAKE2b-256 f73e305dbbc97c2d202db8c62d9a4c5a9827ba328708275f36c005db3bc396ca

See more details on using hashes here.

File details

Details for the file mokei-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: mokei-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.3

File hashes

Hashes for mokei-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0b613551fd9998fcdc5559afc9d7c17c27389a1df9b58151763b0fd589133d08
MD5 b3510d85440bb940a86eab1b6e953b9a
BLAKE2b-256 068b7d687e706aca138753b03ad5fbb86281568d306fe506913514f92809851a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page