namekox-websocket


Namenamekox-websocket JSON
Version 0.0.10 PyPI version JSON
download
home_pagehttps://forcemain.github.io/
Summarynamekox websocket
upload_time2021-01-14 02:35:18
maintainer
docs_urlNone
authorforcemain
requires_python
licenseApache License, Version 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Install
```shell script
pip install -U namekox-websocket
```

# Example
> ping.py
```python
#! -*- coding: utf-8 -*-

# author: forcemain@163.com


from namekox_websocket.core.message import WssMessage
from namekox_websocket.core.wsshub import WebSocketHub
from namekox_websocket.core.entrypoints.app.handler import WebSocketHandler
from namekox_webserver.core.entrypoints.app.handler import ApiServerHandler


app = type(__name__, (object,), {'api': ApiServerHandler.decorator, 'wss': WebSocketHandler.decorator})


class Ping(object):
    name = 'ping'
    websocket_hub = WebSocketHub()

    @app.api('/', methods=['GET'])
    def api_pong(self, request):
        message = WssMessage(data={'api_pong': True})
        self.websocket_hub.broadcast('ping', message)

    @app.wss('/', methods=['GET'])
    def wss_pong(self, request, sock_id, data):
        self.websocket_hub.subscribe('ping', sock_id)
        return {'wss_pong': True}
```

# Running
> config.yaml
```yaml
WEBSERVER:
  host: 0.0.0.0
  port: 80
WEBSOCKET:
  host: 0.0.0.0
  port: 8000
```

> namekox run ping
```shell script
2021-01-13 09:45:58,424 DEBUG load container class from namekox_core.core.service.container:ServiceContainer
2021-01-13 09:45:58,425 DEBUG starting services ['ping']
2021-01-13 09:45:58,426 DEBUG starting service ping entrypoints [ping:namekox_webserver.core.entrypoints.app.server.WebServer:server, ping:namekox_websocket.core.entrypoints.app.server.WssServer:server, ping:namekox_webserver.core.entrypoints.app.handler.ApiServerHandler:api_pong, ping:namekox_websocket.core.entrypoints.app.handler.WebSocketHandler:wss_pong]
2021-01-13 09:45:58,428 DEBUG spawn manage thread handle ping:namekox_webserver.core.entrypoints.app.server:handle_connect(args=(), kwargs={}, tid=handle_connect)
2021-01-13 09:45:58,428 DEBUG spawn manage thread handle ping:namekox_webserver.core.entrypoints.app.server:handle_connect(args=(), kwargs={}, tid=handle_connect)
2021-01-13 09:45:58,429 DEBUG service ping entrypoints [ping:namekox_webserver.core.entrypoints.app.server.WebServer:server, ping:namekox_websocket.core.entrypoints.app.server.WssServer:server, ping:namekox_webserver.core.entrypoints.app.handler.ApiServerHandler:api_pong, ping:namekox_websocket.core.entrypoints.app.handler.WebSocketHandler:wss_pong] started
2021-01-13 09:45:58,429 DEBUG starting service ping dependencies []
2021-01-13 09:45:58,429 DEBUG service ping dependencies [] started
2021-01-13 09:45:58,429 DEBUG services ['ping'] started
2021-01-13 09:46:06,968 DEBUG spawn manage thread handle ping:namekox_webserver.core.entrypoints.app.server:handle_request(args=(<eventlet.greenio.base.GreenSocket object at 0x104e17cd0>, ('127.0.0.1', 54270)), kwargs={}, tid=handle_request)
2021-01-13 09:46:10,019 DEBUG spawn worker thread handle ping:wss_pong(args=(<Request 'http://127.0.0.1:8000/' [GET]>, '7ce2ea32-4d4e-471d-a6a5-89191ace6ea4', u'asdad'), kwargs={}, context={})
2021-01-13 09:46:13,838 DEBUG spawn manage thread handle ping:namekox_webserver.core.entrypoints.app.server:handle_request(args=(<eventlet.greenio.base.GreenSocket object at 0x104e17590>, ('127.0.0.1', 54293)), kwargs={}, tid=handle_request)
2021-01-13 09:46:13,843 DEBUG spawn worker thread handle ping:api_pong(args=(<Request 'http://127.0.0.1/' [GET]>,), kwargs={}, context={})
2021-01-13 09:46:13,844 DEBUG publish {"errs": "", "data": {"api_pong": true}} to channel ping succ
127.0.0.1 - - [13/Jan/2021 09:46:13] "GET / HTTP/1.1" 200 237 0.002497
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://forcemain.github.io/",
    "name": "namekox-websocket",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "forcemain",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/24/91/803f159bdf923c3df968da177bdbe600ec8b38b096a7a2d4e82aa64d37d5/namekox-websocket-0.0.10.tar.gz",
    "platform": "",
    "description": "# Install\n```shell script\npip install -U namekox-websocket\n```\n\n# Example\n> ping.py\n```python\n#! -*- coding: utf-8 -*-\n\n# author: forcemain@163.com\n\n\nfrom namekox_websocket.core.message import WssMessage\nfrom namekox_websocket.core.wsshub import WebSocketHub\nfrom namekox_websocket.core.entrypoints.app.handler import WebSocketHandler\nfrom namekox_webserver.core.entrypoints.app.handler import ApiServerHandler\n\n\napp = type(__name__, (object,), {'api': ApiServerHandler.decorator, 'wss': WebSocketHandler.decorator})\n\n\nclass Ping(object):\n    name = 'ping'\n    websocket_hub = WebSocketHub()\n\n    @app.api('/', methods=['GET'])\n    def api_pong(self, request):\n        message = WssMessage(data={'api_pong': True})\n        self.websocket_hub.broadcast('ping', message)\n\n    @app.wss('/', methods=['GET'])\n    def wss_pong(self, request, sock_id, data):\n        self.websocket_hub.subscribe('ping', sock_id)\n        return {'wss_pong': True}\n```\n\n# Running\n> config.yaml\n```yaml\nWEBSERVER:\n  host: 0.0.0.0\n  port: 80\nWEBSOCKET:\n  host: 0.0.0.0\n  port: 8000\n```\n\n> namekox run ping\n```shell script\n2021-01-13 09:45:58,424 DEBUG load container class from namekox_core.core.service.container:ServiceContainer\n2021-01-13 09:45:58,425 DEBUG starting services ['ping']\n2021-01-13 09:45:58,426 DEBUG starting service ping entrypoints [ping:namekox_webserver.core.entrypoints.app.server.WebServer:server, ping:namekox_websocket.core.entrypoints.app.server.WssServer:server, ping:namekox_webserver.core.entrypoints.app.handler.ApiServerHandler:api_pong, ping:namekox_websocket.core.entrypoints.app.handler.WebSocketHandler:wss_pong]\n2021-01-13 09:45:58,428 DEBUG spawn manage thread handle ping:namekox_webserver.core.entrypoints.app.server:handle_connect(args=(), kwargs={}, tid=handle_connect)\n2021-01-13 09:45:58,428 DEBUG spawn manage thread handle ping:namekox_webserver.core.entrypoints.app.server:handle_connect(args=(), kwargs={}, tid=handle_connect)\n2021-01-13 09:45:58,429 DEBUG service ping entrypoints [ping:namekox_webserver.core.entrypoints.app.server.WebServer:server, ping:namekox_websocket.core.entrypoints.app.server.WssServer:server, ping:namekox_webserver.core.entrypoints.app.handler.ApiServerHandler:api_pong, ping:namekox_websocket.core.entrypoints.app.handler.WebSocketHandler:wss_pong] started\n2021-01-13 09:45:58,429 DEBUG starting service ping dependencies []\n2021-01-13 09:45:58,429 DEBUG service ping dependencies [] started\n2021-01-13 09:45:58,429 DEBUG services ['ping'] started\n2021-01-13 09:46:06,968 DEBUG spawn manage thread handle ping:namekox_webserver.core.entrypoints.app.server:handle_request(args=(<eventlet.greenio.base.GreenSocket object at 0x104e17cd0>, ('127.0.0.1', 54270)), kwargs={}, tid=handle_request)\n2021-01-13 09:46:10,019 DEBUG spawn worker thread handle ping:wss_pong(args=(<Request 'http://127.0.0.1:8000/' [GET]>, '7ce2ea32-4d4e-471d-a6a5-89191ace6ea4', u'asdad'), kwargs={}, context={})\n2021-01-13 09:46:13,838 DEBUG spawn manage thread handle ping:namekox_webserver.core.entrypoints.app.server:handle_request(args=(<eventlet.greenio.base.GreenSocket object at 0x104e17590>, ('127.0.0.1', 54293)), kwargs={}, tid=handle_request)\n2021-01-13 09:46:13,843 DEBUG spawn worker thread handle ping:api_pong(args=(<Request 'http://127.0.0.1/' [GET]>,), kwargs={}, context={})\n2021-01-13 09:46:13,844 DEBUG publish {\"errs\": \"\", \"data\": {\"api_pong\": true}} to channel ping succ\n127.0.0.1 - - [13/Jan/2021 09:46:13] \"GET / HTTP/1.1\" 200 237 0.002497\n```\n\n\n",
    "bugtrack_url": null,
    "license": "Apache License, Version 2.0",
    "summary": "namekox websocket",
    "version": "0.0.10",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "9a6794be8178ca6b89c8cdf11c4a77f3",
                "sha256": "92b801b75ad353bf124f4a69acdec353e8011a8ad8b8bf2e290ee56a17eda785"
            },
            "downloads": -1,
            "filename": "namekox_websocket-0.0.10-py2-none-any.whl",
            "has_sig": false,
            "md5_digest": "9a6794be8178ca6b89c8cdf11c4a77f3",
            "packagetype": "bdist_wheel",
            "python_version": "py2",
            "requires_python": null,
            "size": 7699,
            "upload_time": "2021-01-14T02:35:17",
            "upload_time_iso_8601": "2021-01-14T02:35:17.586358Z",
            "url": "https://files.pythonhosted.org/packages/c9/ed/a6e8d0180c87767ba9b3707c0989497b3760637029aad61cce79e6737223/namekox_websocket-0.0.10-py2-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "778a2a9fa3e8259cba2615d41dfeacd8",
                "sha256": "37106607fda3e5671b0023a5004b7141335bc34c1a5d9b94b1f3824f11496a9a"
            },
            "downloads": -1,
            "filename": "namekox-websocket-0.0.10.tar.gz",
            "has_sig": false,
            "md5_digest": "778a2a9fa3e8259cba2615d41dfeacd8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 4895,
            "upload_time": "2021-01-14T02:35:18",
            "upload_time_iso_8601": "2021-01-14T02:35:18.746694Z",
            "url": "https://files.pythonhosted.org/packages/24/91/803f159bdf923c3df968da177bdbe600ec8b38b096a7a2d4e82aa64d37d5/namekox-websocket-0.0.10.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-01-14 02:35:18",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "namekox-websocket"
}
        
Elapsed time: 0.24721s