{"id":31920979,"url":"https://github.com/ramazanpolat/socketcc","last_synced_at":"2025-10-13T22:06:50.465Z","repository":{"id":57469097,"uuid":"123348214","full_name":"ramazanpolat/socketcc","owner":"ramazanpolat","description":"Socket Cluster Client for Python","archived":false,"fork":false,"pushed_at":"2023-01-30T07:16:11.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-09-22T21:58:42.016Z","etag":null,"topics":["pubsub","python3","socketcluster-client"],"latest_commit_sha":null,"homepage":"http://socketcluster.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ramazanpolat.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2018-02-28T22:08:00.000Z","updated_at":"2023-01-30T07:16:16.000Z","dependencies_parsed_at":"2023-02-16T05:01:27.415Z","dependency_job_id":null,"html_url":"https://github.com/ramazanpolat/socketcc","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ramazanpolat/socketcc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramazanpolat%2Fsocketcc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramazanpolat%2Fsocketcc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramazanpolat%2Fsocketcc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramazanpolat%2Fsocketcc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ramazanpolat","download_url":"https://codeload.github.com/ramazanpolat/socketcc/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ramazanpolat%2Fsocketcc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017151,"owners_count":26085983,"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","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["pubsub","python3","socketcluster-client"],"created_at":"2025-10-13T22:06:48.286Z","updated_at":"2025-10-13T22:06:50.458Z","avatar_url":"https://github.com/ramazanpolat.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# socketcc\nSocket Cluster Client for Python\n\nThis is a refined fork of [https://github.com/sacOO7/socketcluster-client-python](https://github.com/sacOO7/socketcluster-client-python).\n\n# Why fork?\nThe original work of [sacOO7](https://github.com/sacOO7/socketcluster-client-python) was great except the code styling.\nSo I refined it to conform [PEP 8 -- Style Guide for Python Code](https://www.python.org/dev/peps/pep-0008/ \"Style Guide for Python Code\")\n\n    \nOverview\n--------\nThis client provides following functionality\n\n- Easy to setup and use\n- Can be used for extensive unit-testing of all server side functions\n- Support for emitting and listening to remote events\n- Automatic reconnection\n- Pub/sub\n- Authentication (JWT)\n- Needs python 3.6+\n\nTo install use\n```python\n    sudo pip install socketcc\n```\n\nDescription\n-----------\nCreate instance of `SocketCC` class by passing url of socketcluster-server end-point \n\n```python\n    //Create a socket instance\n    socket = SocketCC(\"ws://localhost:8000/socketcluster/\") \n    \n```\n**Important Note** : Default url to socketcluster end-point is always *ws://somedomainname.com/socketcluster/*.\n\n#### Registering basic listeners\n \nDifferent functions are given as an argument to register listeners\n\n```python\ndef your_code_starts_here(socket: SocketCC):\n   pass\n\ndef on_connect(socket: SocketCC):\n    logging.info(f\"Connected to {socket.url}\")\n\ndef on_disconnect(socket: SocketCC):\n    logging.info(f\"Disconnected from {socket.url}\")\n\ndef on_connection_error(socket: SocketCC, error):\n    logging.error(f\"Connection error:{error}\")\n\ndef on_set_auth(socket: SocketCC, token):\n    logging.info(f\"Received auth token:{token}\")\n    socket.set_auth_token(token)\n\ndef on_auth(socket: SocketCC, is_authenticated):\n    logging.info(\"Authenticated is \" + str(is_authenticated))\n\n    def after_authenticated(eventname, error, data):\n        print(\"token is \" + json.dumps(data, sort_keys=True))\n        your_code_starts_here(socket)\n\n    socket.emit(\"auth\", api_credentials, after_authenticated)\n\nif __name__ == \"__main__\":\n    scc = SocketCC(SC_ENDPOINT)\n    scc.set_basic_listener(on_connect, on_disconnect, on_connection_error)\n    scc.set_auth_listener(on_set_auth, on_auth)\n    scc.set_reconnection(False)\n    scc.connect()\n```\n\n#### Connecting to server\n\n- For connecting to server:\n\n```python\n    //This will send websocket handshake request to socketcluster-server\n    socket.connect();\n```\n\n- By default reconnection to server is enabled , to configure delay for connection\n\n```python\n    //This will set automatic-reconnection to server with delay of 2 seconds and repeating it for infinitely\n    socket.setdelay(2)\n    socket.connect();\n```\n\n- To disable reconnection :\n\n```python\n   socket.set_reconnection(False)\n```\n\nEmitting and listening to events\n--------------------------------\n#### Event emitter\n\n- eventname is name of event and message can be String, boolean, int or JSON-object\n\n```python\n\n    socket.emit(eventname, message);\n        \n    # socket.emit(\"chat\", \"Hi\")\n```\n\n- To send event with acknowledgement, provide an extra parameter for Ack callback\n\n```python\n\n    socket.emit(\"chat\", \"Hi\", ack)  \n        \n    def ack(event_name, error, object):\n        print \"Got ack data \" + object + \" and error \" + error + \" and event_name is \" + eventname\n```\n\n#### Event Listener\n\n- For listening to events :\n\nThe object received can be String, Boolean, Long or JSONObject.\n\n```python\n     # Receiver code without sending acknowledgement back\n     socket.on(\"ping\", message)\n     \n     def message(eventname, object):\n         print \"Got data \" + object + \" from eventname \" + eventname\n```\n\n- To send acknowledgement back to server\n\n```python\n    # Receiver code with ack\n    socket.on_ack(\"ping\", messsage_ack)\n    \n    def messsage_ack(eventname, object, ack_message):\n        print \"Got data \" + object + \" from eventname \" + eventname\n        ackmessage(\"this is error\", \"this is data\")\n        \n```\n\nImplementing Pub-Sub via channels\n---------------------------------\n\n#### Creating channel\n\n- For creating and subscribing to channels:\n\n```python\n    \n    # without acknowledgement\n    socket.subscribe('yell')\n    \n    #with acknowledgement\n    socket.subscribe('yell', suback)\n    \n    def suback(channel, error, object):\n        if error is '':\n            print \"Subscribed successfully to channel \" + channel\n```\n\n- For getting list of created channels :\n \n```python\n        channels = socket.channels\n\n``` \n\n\n#### Publishing event on channel\n\n- For publishing event :\n\n```python\n\n       # without acknowledgement\n       socket.publish('yell', 'Hi dudies')\n       \n       #with acknowledgement\n       socket.publish('yell', 'Hi dudies', pub_ack)\n       \n       def pub_ack(channel, error, object):\n           if error is '':\n               print \"Publish sent successfully to channel \" + channel\n``` \n \n#### Listening to channel\n\n- For listening to channel event :\n\n```python\n        \n        socket.on_channel('yell', print_channel_message)\n    \n        def print_channel_message(key, object):\n            print \"Got data \" + object + \" from key \" + key\n    \n``` \n     \n#### Un-subscribing to channel\n\n```python\n         # without acknowledgement\n         socket.unsubscribe('yell')\n         \n         # with acknowledgement\n         socket.unsubscribe('yell', unsub_ack) \n         \n         def unsub_ack(channel, error, object):\n              if error is '':\n                   print \"Unsubscribed to channel \" + channel \n```\n      \n#### Disable SSL Certificate Verification\n\n```python\n        socket = SocketCC(\"wss://localhost:8000/socketcluster/\")\n        socket.connect(sslopt={\"cert_reqs\": ssl.CERT_NONE})\n```\n\n#### HTTP proxy\n\nSupport websocket access via http proxy. The proxy server must allow \"CONNECT\" method to websocket port. Default squid setting is \"ALLOWED TO CONNECT ONLY HTTPS PORT\".\n\n```python\n        socket = SocketCC(\"wss://localhost:8000/socketcluster/\")\n        socket.connect(http_proxy_host=\"proxy_host_name\", http_proxy_port=3128)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framazanpolat%2Fsocketcc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Framazanpolat%2Fsocketcc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Framazanpolat%2Fsocketcc/lists"}