server-sent-events | Python library for Server-Sent-Events | Pub Sub library

 by   boppreh Python Version: Current License: MIT

kandi X-RAY | server-sent-events Summary

kandi X-RAY | server-sent-events Summary

server-sent-events is a Python library typically used in Messaging, Pub Sub, Arduino applications. server-sent-events has no vulnerabilities, it has a Permissive License and it has high support. However server-sent-events has 1 bugs and it build file is not available. You can download it from GitHub.

This small modules implements a Publisher class to handle events in the HTTP Server-Sent-Events protocol. It allows a number of subscribers to get notifications when events happen in certain feed channels. The common use case is for a Javascript client to subscribe to these feed using an EventSource instance, and the events be sent by a Python server like Flask. You can run the module as a Python script to start an example chat, available at .
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              server-sent-events has a highly active ecosystem.
              It has 29 star(s) with 7 fork(s). There are 2 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 1 open issues and 1 have been closed. There are no pull requests.
              It has a positive sentiment in the developer community.
              The latest version of server-sent-events is current.

            kandi-Quality Quality

              server-sent-events has 1 bugs (0 blocker, 0 critical, 1 major, 0 minor) and 5 code smells.

            kandi-Security Security

              server-sent-events has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              server-sent-events code analysis shows 0 unresolved vulnerabilities.
              There are 2 security hotspots that need review.

            kandi-License License

              server-sent-events is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              server-sent-events releases are not available. You will need to build from source code and install.
              server-sent-events has no build file. You will be need to create the build yourself to build the component from source.
              Installation instructions are not available. Examples and code snippets are available.
              server-sent-events saves you 100 person hours of effort in developing the same functionality from scratch.
              It has 274 lines of code, 23 functions and 5 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed server-sent-events and discovered the below as its top functions. This is intended to give you an instant insight into server-sent-events implemented functionality, and help decide if they suit your requirements.
            • Display a root page
            • Publish data to all subscribers
            • Get all subscribers of a channel
            • Publish data to queue
            • Get subscribers list for a channel
            • Return the event stream
            • Subscribe to a channel
            • Create a generator from the queue
            Get all kandi verified functions for this library.

            server-sent-events Key Features

            No Key Features are available at this moment for server-sent-events.

            server-sent-events Examples and Code Snippets

            No Code Snippets are available at this moment for server-sent-events.

            Community Discussions

            QUESTION

            Server Sent Event; `EventSource.onmessage` not firing
            Asked 2021-Dec-21 at 09:06

            I'm trying to use the following example of Server Sent Events. Seems like the server is emitting the data, but the event is not firing and no data is recorded in the event stream (through the developer tools).

            Angular code (service):

            ...

            ANSWER

            Answered 2021-Dec-21 at 09:06

            I just realized, thanks to this answer, that events must be formatted in a specific way. I changed the value of res.write accordingly:

            Source https://stackoverflow.com/questions/70432625

            QUESTION

            Disable logging for server-sent-events errors in RESTEasy
            Asked 2021-Jun-22 at 15:58

            I'm currently working with server-sent-events using RESTEasy in Wildfly. So far everything is working, except that sometimes the SSE implementation doesn't somehow recognize that the client(s) listening to events is/are already closed (also the close() method of the SseEventSourceon the client-side was called). In aspect of the program logic this isn't a problem at all.

            But unfortunately org.jboss.resteasy.plugins.providers.sse.SseEventOutputImpl class which is used to send the events, does - in addition to reporting the exception back to org.jboss.resteasy.plugins.providers.sse.SseBroadcasterImpl - not only report the exception, but also logs it using the failedToWriteSseEvent(String, Throwable) method of the org.jboss.resteasy.resteasy_jaxrs.i18n.LogMessages (later class is based on the JBoss logging). So I get every now and then an unnecessary log messages on level ERROR telling me that the connection was closed by the client. And it get that entry in the log in addition to the onClose event I get from the SseBroadcaster.

            Configuring the JBoss logging seems impossible as the log name is org.jboss.resteasy.resteasy_jaxrs.i18n which is also used for logging other errors (Means just configuring the logger in the log4j.xml of the deployment won't work / also turn off other errors).

            ...

            ANSWER

            Answered 2021-Jun-22 at 15:58

            You might be hitting RESTEASY-1986. You can filter these out with a log filter though. In CLI something like:

            Source https://stackoverflow.com/questions/68084547

            QUESTION

            what to to with array that grows and grows using server sent events
            Asked 2021-Jun-21 at 07:35

            I'm new to server sent events,
            I red trough many tutorials and watched many helpful videos and I still don't understand "what to do with the data that keep growing on every user request" ??.

            I use NodeJS so I started here..
            How To Use Server-Sent Events in Node.js to Build a Realtime App

            this following example was taken from the above link..

            ...

            ANSWER

            Answered 2021-Jun-21 at 07:35

            what to do with the data that keep growing on every user request?

            Currently the demo stores all facts, and sends them all out as the starter history for a client. As it is a demo they've not gone into the messy details of how to scale it for running forever.

            In a real app you are likely to want to add an id (or timestamp) to each fact. Then you could use this with last-event-id on reconnect, to just get the facts they missed.

            You are also likely to want to store the facts in a SQL DB of some kind, and maybe offer a separate web service to access the history. A client would first request as much history as they need, then start the event source request.

            By the way, I'd make this history request service a separate web service if you wanted to scale. With event source the limiting factor for scaling is the number of simultaneous connections, whereas for storing history the limit is the disk space.

            Another approach would be to only keep the most recent 100 or so facts, and not worry about a full history. You could do this by having addFact() first do facts = facts.slice(-99) before doing the push (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice if that syntax is unfamiliar).

            Source https://stackoverflow.com/questions/68058132

            QUESTION

            Replace part of an object with another
            Asked 2021-May-21 at 14:56

            I have a list of objects where each object has many properties (key-value pairs).

            We will have many occasions where different API calls, or server-sent-events (via websockets) will return data to update some objects in the list. The difficult thing is that each different call will return only the part of the data for each object, not the full data.

            The question is about the most efficient way to replace only the bits that have changed - noting that this data is used in a React application, so we need to also consider immutable consequences.

            My idea was simply to match the id in the original data to the new data, then I would have to loop through the incoming data to find the keys, then replace the original data with that key. It seems like there might be a more efficient way to do this.

            ...

            ANSWER

            Answered 2021-May-21 at 14:17

            You could take an object with the references to the objects with the same id without iterating the array.

            Source https://stackoverflow.com/questions/67638504

            QUESTION

            Nestjs @Sse : return result of a promise in rxjs observable
            Asked 2021-Apr-27 at 13:25

            I am trying to go a simple step beyond the nest doc example in implementing @Sse() in a controller but I never used rxjs untill now so Im a bit confused.

            The flow is :

            1. client send a POST request with a file payload
            2. server (hopefully) sends back the newly created project with a prop status:UPLOADED
            3. client subscribe to sse route described below passing as param the projectId it just received from server
            4. in the meantime server is doingSomeStuff that could take from 10sec to a min. When doingSomeStuff is done, project status is updated in db from UPLOADED to PARSED

            My need is for the @Sse decorated function to execute at x interval of time a "status-check" and return project.status (that may or may not have been updated at the time)

            My present code :

            ...

            ANSWER

            Answered 2021-Apr-27 at 13:11

            This is a two-step process.

            1. We create an observable out of the promise generated by this.service.findById() using the from operator in rxjs. We also use the map operator to set the format of the object we need when someone subscribes to this observable.

            2. We want to return this observable every x seconds. interval(x) creates an observable that emits a value after every x milliseconds. Hence, we use this and then switchMap to the projId$ whenever the interval emits a value. The switchMap operator switches to the inner observable whenever the outer observable emits a value.

            Please note: Since your server may take 10 sec, to min for doing the operation, you should set the intervalValue accordingly. In the code snippet below, I've set it to 10,000 milli seconds which is 10 seconds.

            Source https://stackoverflow.com/questions/67279127

            QUESTION

            Can we use server sent events in nestjs without using interval?
            Asked 2021-Apr-21 at 19:54

            I'm creating few microservices using nestjs.

            For instance I have x, y & z services all interconnected by grpc but I want service x to send updates to a webapp on a particular entity change so I have considered server-sent-events [open to any other better solution].

            Following the nestjs documentation, they have a function running at n interval for sse route, seems to be resource exhaustive. Is there a way to actually sent events when there's a update.

            Lets say I have another api call in the same service that is triggered by a button click on another webapp, how do I trigger the event to fire only when the button is clicked and not continuously keep sending events. Also if you know any idiomatic way to achieve this which getting hacky would be appreciated, want it to be last resort.

            [BONUS Question]

            I also considered MQTT to send events. But I get a feeling that it isn't possible for a single service to have MQTT and gRPC. I'm skeptical of using MQTT because of its latency and how it will affect internal message passing. If I could limit to external clients it would be great (i.e, x service to use gRPC for internal connections and MQTT for webapp just need one route to be exposed by mqtt). (PS I'm new to microservices so please be comprehensive about your solutions :p)

            Thanks in advance for reading till end! ...

            ANSWER

            Answered 2021-Apr-21 at 19:54

            You can. The important thing is that in NestJS SSE is implemented with Observables, so as long as you have an observable you can add to, you can use it to send back SSE events. The easiest way to work with this is with Subjects. I used to have an example of this somewhere, but generally, it would look something like this

            Source https://stackoverflow.com/questions/67202527

            QUESTION

            Server Sent Events not being sent on Google App Engine but work fine locally. How to send multiple messages from sever?
            Asked 2021-Apr-16 at 17:54
            Goal

            I need my backend to push several answers to my client and I need puppeteer to run backend-side. Puppeteer needs some time to work, but has regular intermediate results and should send updates to the client regulary (in total, one request-responses-cycle takes less than 60secs which seems to be the upper limit for GAE).

            Underlying GAE Problem: Main Problem

            As a consequence, I re-implemented my code to use server sent events (which is based on http). I expected that to work in standard. It works fine locally. It does not work on production. It will eventually answer the client but only when I close the connection server side and then send everything in one go. It does not regularly update the client. This only happens on GAE, not locally.

            What have I tried?

            I do flush the sse-response, as otherwise the compression nodejs library leads to a similar behaviour

            I also set these headers, esp. X-Accel-Buffering, taken from here:

            ...

            ANSWER

            Answered 2021-Apr-16 at 17:54
            1. Your local GAE [standard] environment is not an exact replica or simulation of GAE production. This is especially true if you are using GAE Python2 standard. You should keep that in mind going forward. I know this because I have also experienced this issue with Server Sent Events. This means something that works in dev environment might not work in production so be very careful to first confirm what works and doesn't in GAE documentation.

            2. GAE standard does not support streaming which is essentially what SSEs are. In addition, App Engine standard has a deadline of 1 minute for each request i.e. each call to App Engine as part of your standard app has to return within a minute

            3. I don't believe GAE Flexible have these restrictions so you should try it. See this link which talks about differences between standard and flexible. When I had this issue years ago (trying to do SSE on Python), I ended up switching to Compute Engine and doing PubSub but there were other reasons for going that route instead of trying GAE Flexible

            Source https://stackoverflow.com/questions/67117233

            QUESTION

            JS SSE callback isn't working with EventListener
            Asked 2021-Jan-26 at 09:28

            I'm using a JS library to stream server-sent-events on my html page:

            ...

            ANSWER

            Answered 2021-Jan-26 at 09:28

            When your script calls source.stream();, it is doing an XMLHttpRequest.send() operation, which is async by default.

            So, what is happening:

            1. user clicks, and post() is called
            2. SSE object and its event listener is set up
            3. source.stream() is called, which sends the request to the server.
            4. callback() (i.e. clip()) is called
            5. Server sends back a response
            6. Your message event handler is called
            7. textArea.value is set

            Luckily the fix is simple: you only want callback() to be called when a message is received. So move callback() to be at the end of the message event handler, not at the end of post().

            It will do this after every message event that is received. If you only wanted it to happen after the first event, you will need to implement some logic to keep track of how many events have been received. (And if there will only be one message event, you should be using an Ajax call, not an SSE/EventSource call.)

            UPDATE: Discussion in the comments are starting to get out of scope of your original question (where the answer is, simply put, "it is async, not sync"). But I think it is worth pointing out here that you set up a new SSE object every time the user clicks the button. Each SSE object will have its own dedicated TCP/IP socket and its own listener function. This is (generally) not a good idea: instead create the SSE connection once at the start of your web app.

            And, though your SSE polyfill library allows using POST, the standard SSE does not. If you only want the app to poll the server when the user presses the button, consider switching from using SSE to normal AJAX.

            Source https://stackoverflow.com/questions/65862490

            QUESTION

            SSE event data gets cut off when using Nginx
            Asked 2020-Nov-23 at 13:49

            I am implementing a web interface using React and Flask. One component of this interface is a server sent event that is used to update data in the front end whenever it is updated in a database. This data is quite large and one event could contain over 16000 characters.

            The React front end uses a reverse proxy to the flask back end in order to forward API requests to it. When accessing this back end directly, this works fine with the SSEs and the data is pushed as expected. However, when using Nginx to serve the reverse proxy, something weird happens. It seems like nginx buffers and chunks the event stream and does not send the results until it has filled around 16000 characters. If the data from the event is smaller than this, it means the front end will have to wait until more events are sent. If the data from the event is larger, it means the new-lines that tell the EventSource that a message has been received aren't part of the event. This results in the front end receiving event X when event X+1 is sent (that is, when the new-lines actually appear in the stream).

            This is the response header when using nginx:

            ...

            ANSWER

            Answered 2020-Nov-23 at 13:49

            The above mentioned configuration actually did work. However, the server I was using contained another nginx configuration that was overriding my configuration. When the configuration parameters specific for SSEs were added to that configuration as well, things started working as expected. So this question was correct all along.

            Source https://stackoverflow.com/questions/64912788

            QUESTION

            React eventsource is not closed
            Asked 2020-Oct-05 at 07:20

            I'm quite new to web development and server-sent-events in particular so probably I'm missing something obvious. I'm trying to display a logger on a React page with server-sent-events, which works fine, but I cannot close the eventSource. The server continuously receives requests after eventSource.close() was called.

            ...

            ANSWER

            Answered 2020-Oct-05 at 07:20

            Finally, I found a workaround (I still don't understand why the initial approach did not work, though). Instead of using a hook to store the eventListener, I handled everything in the useEffect hook that is called on mount using addEventListener():

            Source https://stackoverflow.com/questions/64168907

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install server-sent-events

            You can download it from GitHub.
            You can use server-sent-events like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/boppreh/server-sent-events.git

          • CLI

            gh repo clone boppreh/server-sent-events

          • sshUrl

            git@github.com:boppreh/server-sent-events.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Pub Sub Libraries

            EventBus

            by greenrobot

            kafka

            by apache

            celery

            by celery

            rocketmq

            by apache

            pulsar

            by apache

            Try Top Libraries by boppreh

            keyboard

            by bopprehPython

            mouse

            by bopprehPython

            steamgrid

            by bopprehGo

            maze

            by bopprehPython

            bayesian

            by bopprehPython