{"id":16700146,"url":"https://github.com/guyzmo/event-source-library","last_synced_at":"2025-03-21T19:32:56.720Z","repository":{"id":3405468,"uuid":"4455548","full_name":"guyzmo/event-source-library","owner":"guyzmo","description":"Python Event Source Library","archived":false,"fork":false,"pushed_at":"2016-12-07T10:54:55.000Z","size":71,"stargazers_count":34,"open_issues_count":4,"forks_count":9,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-03-18T04:35:27.776Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guyzmo.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGES","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-05-26T14:48:00.000Z","updated_at":"2025-03-17T14:12:10.000Z","dependencies_parsed_at":"2022-09-06T09:22:37.349Z","dependency_job_id":null,"html_url":"https://github.com/guyzmo/event-source-library","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guyzmo%2Fevent-source-library","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guyzmo%2Fevent-source-library/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guyzmo%2Fevent-source-library/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guyzmo%2Fevent-source-library/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guyzmo","download_url":"https://codeload.github.com/guyzmo/event-source-library/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244855688,"owners_count":20521680,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T18:09:32.622Z","updated_at":"2025-03-21T19:32:56.398Z","avatar_url":"https://github.com/guyzmo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"README: Event Source Library for Python\n=======================================\n\nThis library implements W3C Draft's on event-source:\n\n* http://dev.w3.org/html5/eventsource/\n\nIt enables a halfduplex communication from server to client, but initiated\nby the client, through standard HTTP(S) communication.\n\nDependances\n-----------\n\n* Fairly recent python (tested with 2.7)\n* Fairly recent tornado (tested with 2.2.1)\n\nUsage\n-----\n\n1. Launch the server::\n    \n    eventsource-server -P 8888 -i -k 50000\n\n2. Launch the client::\n\n    eventsource-client 42:42:42:42:42:42 -r 5000 -P 8888\n\n3. Send requests::\n\n    eventsource-request 42:42:42:42:42:42 ping \"42\"\n    eventsource-request 42:42:42:42:42:42 close\n\nCommand Line arguments\n----------------------\n\n* `eventsource/listener.py` or `eventsource-server`::\n\n    usage: eventsource/listener.py [-h] [-H HOST] [-P PORT] [-d]\n                                                [-j] [-k KEEPALIVE] [-i]\n\n    Event Source Listener\n\n    optional arguments:\n    -h, --help            show this help message and exit\n    -H HOST, --host HOST  Host to bind on\n    -P PORT, --port PORT  Port to bind on\n    -d, --debug           enables debug output\n    -j, --json            to enable JSON Event\n    -k KEEPALIVE, --keepalive KEEPALIVE\n                            Keepalive timeout, in milliseconds\n    -i, --id              to generate identifiers\n\n* `eventsource/client.py` or `eventsource-client`::\n\n    usage: eventsource/client.py [-h] [-H HOST] [-P PORT] [-d]\n                                            [-r RETRY]\n                                            token\n\n    Event Source Client\n\n    positional arguments:\n    token                 Token to be used for connection\n\n    optional arguments:\n    -h, --help            show this help message and exit\n    -H HOST, --host HOST  Host to connect to\n    -P PORT, --port PORT  Port to be used connection\n    -d, --debug           enables debug output\n    -r RETRY, --retry RETRY\n                            Reconnection timeout\n\n* `eventsource/send_request.py` or `eventsource-request`::\n\n    usage: eventsource/send_request.py [-h] [-H HOST] [-P PORT] [-j]\n                                        token action [data]\n\n    Generates event for Event Source Library\n\n    positional arguments:\n    token                 Token to be used for connection\n    action                Action to send\n    data                  Data to be sent\n\n    optional arguments:\n    -h, --help            show this help message and exit\n    -H HOST, --host HOST  Host to connect to\n    -P PORT, --port PORT  Port to be used connection\n    -j, --json            Treat data as JSON\n\nInstall\n-------\n\nYou can install it by getting it from pypi::\n\n    pip install event-source-library\n\nor by getting this repository and install it manually::\n\n    python setup.py install\n\nDevelopment\n-----------\n\nTo develop, you can use buildout::\n\n    pip install zc.buildout # if you haven't got it\n    buildout\n    ls bin/\n\nOr you can do:\n\n    python setup.py develop\n\nwhich will deploy the commands globally like an install, but still linked to\nthe current sources.\n\nIntegrate\n---------\n\nOn the server side, basically all you have to do is to add the following to your code::\n\n    from eventsource import listener\n\n    application = tornado.web.Application([\n        (r\"/(.*)/(.*)\", listener.EventSourceHandler, \n                                          dict(event_class=EVENT,\n                                               keepalive=KEEPALIVE)),\n    ])\n\n    application.listen(PORT)\n    tornado.ioloop.IOLoop.instance().start()\n\nwhere:\n\n* ``PORT`` is an integer for the port to bind to\n\n* ``KEEPALIVE`` is an integer for the timeout between two keepalive messages (to protect from disconnections), in milliseconds\n\n* ``EVENT`` is a eventsource.listener.Event based class, either one you made or \n\n  * ``eventsource.listener.StringEvent`` : Each event gets and resends multiline strings\n\n  * ``eventsource.listener.StringIdEvent`` : Each event gets and resends multiline strings, with an unique id for each event\n\n  * ``eventsource.listener.JSONEvent`` : Each event gets and resends JSON valid strings\n\n  * ``eventsource.listener.JSONIdEvent`` : Each event gets and resends JSON valid string, with an unique id for each event\n\nSee http://www.tornadoweb.org/en/stable/web.html#application-configuration for more details.\n\nExtend\n------\n\nTo extend the behaviour of the event source library, without breaking eventsource\ndefinition, the Event based classes implements all processing elements that shall\nbe done on events. \n\nThere is two abstract classes that defines Event:\n* ``eventsource.listener.Event`` : defines the constructor of an Event\n* ``eventsource.listener.EventId`` : defines an always incrementing id handler\n\nhere is an example to create a new Event that takes multiline data and join it in a one\nline string seperated with semi-colons.\n\n::\n\n    class OneLineEvent(Event):\n        ACTIONS = [\"ping\",Event.FINISH]\n\n        \"\"\"Property to enable multiline output of the value\"\"\"\n        def get_value(self):\n            # replace carriage returns by semi-colons\n            # this method shall always return a list (even if one value)\n            return [\";\".join([line for line in self._value.split('\\n')])]\n\n        value = property(get_value,set_value)\n\nAnd now, I want to add basic id support to OneLineEvent, in OneLineEventId, \nnothing is easier ::\n\n    class OneLineEventId(OneLineEvent,EventId):\n        id = property(EventId.get_value)\n\nOr if I want the id to be a timestamp::\n\n    import time\n    class OneLineTimeStampEvent(OneLineEvent):\n        id = property(lambda s: \"%f\" % (time.time(),))\n\nYou can change the behaviour of a few things in a Event-based class:\n\n* ``Event.LISTEN`` contains the ``GET`` action to open a connection (per default \"poll\")\n* ``Event.FINISH`` contains the ``POST`` action to close a connection (per default \"close\")\n* ``Event.RETRY`` contains the ``POST`` action to define the timeout after reconnecting on network disconnection (per default \"0\", which means disabled)\n* in the ``Event.ACTIONS`` list, you define what POST actions are allowed, per default,  only Event.FINISH is allowed. \n* ``Event.content_type`` contains the \"content_type\" that will be asked for every form (it is not enforced).\n\nTo change the way events are generated, you can directly call ``EventSourceHandler.buffer_event()``\nto create a new event to be sent. But the post action is best, at least while WSGI can't handle\ncorrectly long polling connections.\n\nLicensing\n---------\n\n::\n\n    Python Event Source Library\n\n    (c) 2012 Bernard Pratz\n    Patches by Ian Whyman, Коренберг Марк and Max Suraev\n\n    This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 3 of the License.\n    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n    You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.\n\n    EOF\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguyzmo%2Fevent-source-library","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguyzmo%2Fevent-source-library","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguyzmo%2Fevent-source-library/lists"}