GithubHelp home page GithubHelp logo

jamim / aiohttp-sse Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aio-libs/aiohttp-sse

0.0 1.0 0.0 241 KB

Server-sent events support for aiohttp

License: Other

Python 96.58% Makefile 3.08% Gherkin 0.34%

aiohttp-sse's Introduction

aiohttp-sse

image

image

Updates

Chat on Gitter

The EventSource interface is used to receive server-sent events. It connects to a server over HTTP and receives events in text/event-stream format without closing the connection. aiohttp-sse provides support for server-sent events for aiohttp.

Installation

Installation process as simple as:

$ pip install aiohttp-sse

Example

import asyncio
from aiohttp import web
from aiohttp.web import Response
from aiohttp_sse import sse_response
from datetime import datetime


async def hello(request):
    async with sse_response(request) as resp:
        while True:
            data = 'Server Time : {}'.format(datetime.now())
            print(data)
            await resp.send(data)
            await asyncio.sleep(1)


async def index(request):
    d = """
        <html>
        <body>
            <script>
                var evtSource = new EventSource("/hello");
                evtSource.onmessage = function(e) {
                    document.getElementById('response').innerText = e.data
                }
            </script>
            <h1>Response from server:</h1>
            <div id="response"></div>
        </body>
    </html>
    """
    return Response(text=d, content_type='text/html')


app = web.Application()
app.router.add_route('GET', '/hello', hello)
app.router.add_route('GET', '/', index)
web.run_app(app, host='127.0.0.1', port=8080)

EventSource Protocol

Requirements

License

The aiohttp-sse is offered under Apache 2.0 license.

aiohttp-sse's People

Contributors

alefteris avatar asvetlov avatar blopker avatar d21d3q avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar dlech avatar dreamsorcerer avatar dtcooper avatar gardsted avatar jameshilliard avatar jamim avatar jettify avatar nkoshell avatar olegt0rr avatar pre-commit-ci[bot] avatar pwntester avatar pyup-bot avatar rightbraindev avatar rutsky avatar st0le avatar ticosax avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.