Skip to main content

Async http client/server framework (asyncio)

Project description

This project is a branch of aiohttp on QPython.

Async http client/server framework (asyncio)

Project description:

  • Supports both client and server side of HTTP protocol.

  • Supports both client and server Web-Sockets out-of-the-box and avoids Callback Hell.

  • Provides Web-server with middleware and pluggable routing.

Getting started

Client

To get something from the web:

import aiohttp
import asyncio

async def main():

    async with aiohttp.ClientSession() as session:
        async with session.get('http://python.org') as response:

            print("Status:", response.status)
            print("Content-type:", response.headers['content-type'])

            html = await response.text()
            print("Body:", html[:15], "...")

asyncio.run(main())

Server

An example using a simple server:

# examples/server_simple.py
from aiohttp import web

async def handle(request):
    name = request.match_info.get('name', "Anonymous")
    text = "Hello, " + name
    return web.Response(text=text)

async def wshandle(request):
    ws = web.WebSocketResponse()
    await ws.prepare(request)

    async for msg in ws:
        if msg.type == web.WSMsgType.text:
            await ws.send_str("Hello, {}".format(msg.data))
        elif msg.type == web.WSMsgType.binary:
            await ws.send_bytes(msg.data)
        elif msg.type == web.WSMsgType.close:
            break

    return ws


app = web.Application()
app.add_routes([web.get('/', handle),
                web.get('/echo', wshandle),
                web.get('/{name}', handle)])

if __name__ == '__main__':
    web.run_app(app)

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

aiohttp_qpython-3.10.10.1.tar.gz (918.9 kB view details)

Uploaded Source

Built Distribution

aiohttp_qpython-3.10.10.1-py3-none-any.whl (945.1 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_qpython-3.10.10.1.tar.gz.

File metadata

  • Download URL: aiohttp_qpython-3.10.10.1.tar.gz
  • Upload date:
  • Size: 918.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.7

File hashes

Hashes for aiohttp_qpython-3.10.10.1.tar.gz
Algorithm Hash digest
SHA256 dfaf21d52a21d447294aa0f27e71e046d7f8476b03b7c3439604c9d026340048
MD5 62add0421ade0c1fe7284d2ad34c9f59
BLAKE2b-256 e0389b54b340379a6151ab33ebb301d481eedd9f1fd66c98d9ad83b173a5dfa1

See more details on using hashes here.

File details

Details for the file aiohttp_qpython-3.10.10.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_qpython-3.10.10.1-py3-none-any.whl
Algorithm Hash digest
SHA256 632fa670c6765161eb7b211fb3694f09594d6f09df105bb28dcaa84887e9fdd1
MD5 5983042e4f255aa4df55055777224691
BLAKE2b-256 29e43618e2c4711aa79acb45444ed949df8a29bedb48b32ee10f202f2e0e8fe1

See more details on using hashes here.

Supported by

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