A Python library that lets you communicate through JavaScript WebSocket client
Project description
PyJSSocket
This is a Python library that lets you communicate through JavaScript WebSocket client.
Installation
To install this library run pip install pyjssocket in your terminal.
Example
Here is an example of a server that can handle multiple calls from a different JS clients
import json
import jsserver
import socketserver
import threading
import time
class MyJsRequestHandler(jsserver.JSBaseRequestHandler):
def on_handshake(self, host: str, url: str, seqKey: str):
def target():
while True:
self.send_response(json.dumps({'success': True, 'time': time.time()}))
time.sleep(1)
super().on_handshake(host, url, seqKey)
thread = threading.Thread(target=target, daemon=True)
thread.start()
def on_message(self, data: bytes):
self.send_response(json.dumps({'success': True, 'time': time.time()}))
def on_error(self, value: str):
self.send_response(json.dumps({'success': False, 'message': value}))
if __name__ == '__main__':
with socketserver.ThreadingTCPServer(('0.0.0.0', 451), MyJsRequestHandler) as tcpServer:
tcpServer.serve_forever()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyjssocket-1.0.5.tar.gz.
File metadata
- Download URL: pyjssocket-1.0.5.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c825a2bc3d38ea29e9874c4bbc26a330f47ce5179734b0d9b409e74e314f813
|
|
| MD5 |
12d4c26ed32ca3ae16d119c8473ea71f
|
|
| BLAKE2b-256 |
47cc0c468ca49a1060cb94b884eea942ef6f3e73a01848114c9c66fe294593b9
|
File details
Details for the file pyjssocket-1.0.5-py3-none-any.whl.
File metadata
- Download URL: pyjssocket-1.0.5-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da50630b5d817f3a16bbd9487c516da75bccf0a93d07a05a1d497918a3010f83
|
|
| MD5 |
be5067bf20609c5c637d5f0572e16d35
|
|
| BLAKE2b-256 |
99f3087571ad007d947c694eea090e7b433e95784ecedcaddc84aebe6a9575a8
|