METADATA 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. Metadata-Version: 2.1
  2. Name: websocket-client
  3. Version: 0.59.0
  4. Summary: WebSocket client for Python with low level API options
  5. Home-page: https://github.com/websocket-client/websocket-client.git
  6. Author: liris
  7. Author-email: liris.pp@gmail.com
  8. License: LGPL version 2.1
  9. Download-URL: https://github.com/websocket-client/websocket-client/releases
  10. Project-URL: Documentation, https://websocket-client.readthedocs.io/
  11. Project-URL: Source, https://github.com/websocket-client/websocket-client/
  12. Keywords: websockets client
  13. Platform: UNKNOWN
  14. Classifier: Development Status :: 4 - Beta
  15. Classifier: License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)
  16. Classifier: Programming Language :: Python
  17. Classifier: Programming Language :: Python :: 2
  18. Classifier: Programming Language :: Python :: 2.6
  19. Classifier: Programming Language :: Python :: 2.7
  20. Classifier: Programming Language :: Python :: 3
  21. Classifier: Programming Language :: Python :: 3.4
  22. Classifier: Programming Language :: Python :: 3.5
  23. Classifier: Programming Language :: Python :: 3.6
  24. Classifier: Programming Language :: Python :: 3.7
  25. Classifier: Programming Language :: Python :: 3.8
  26. Classifier: Programming Language :: Python :: 3.9
  27. Classifier: Operating System :: MacOS :: MacOS X
  28. Classifier: Operating System :: POSIX
  29. Classifier: Operating System :: Microsoft :: Windows
  30. Classifier: Topic :: Internet
  31. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  32. Classifier: Intended Audience :: Developers
  33. Requires-Python: >=2.6, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*
  34. Description-Content-Type: text/markdown
  35. Requires-Dist: six
  36. [![docs](https://readthedocs.org/projects/websocket-client/badge/?style=flat)](https://websocket-client.readthedocs.io/)
  37. [![Build Status](https://github.com/websocket-client/websocket-client/actions/workflows/build.yml/badge.svg)](https://github.com/websocket-client/websocket-client/actions/workflows/build.yml)
  38. [![codecov](https://codecov.io/gh/websocket-client/websocket-client/branch/master/graph/badge.svg?token=pcXhUQwiL3)](https://codecov.io/gh/websocket-client/websocket-client)
  39. [![PyPI Downloads](https://pepy.tech/badge/websocket-client)](https://pepy.tech/project/websocket-client)
  40. [![PyPI version](https://img.shields.io/pypi/v/websocket_client)](https://pypi.org/project/websocket_client/)
  41. # websocket-client
  42. websocket-client is a WebSocket client for Python. It provides access
  43. to low level APIs for WebSockets. websocket-client implements version
  44. [hybi-13](https://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-13)
  45. of the WebSocket procotol. This client does not currently support the
  46. permessage-deflate extension from
  47. [RFC 7692](https://tools.ietf.org/html/rfc7692).
  48. ## Documentation
  49. This project's documentation can be found at
  50. [https://websocket-client.readthedocs.io/](https://websocket-client.readthedocs.io/)
  51. ## Contributing
  52. Please see the [contribution guidelines](https://github.com/websocket-client/websocket-client/blob/master/CONTRIBUTING.md)
  53. ## Installation
  54. First, install the following dependencies:
  55. - six
  56. - backports.ssl\_match\_hostname for Python 2.x
  57. You can install the dependencies with the command `pip install six` and
  58. `pip install backports.ssl_match_hostname`
  59. You can use either `python setup.py install` or `pip install websocket-client`
  60. to install. This module is tested on Python 2.7 and Python 3.4+. Python 3
  61. support was first introduced in version 0.14.0, but is a work in progress.
  62. ## Usage Tips
  63. Check out the documentation's FAQ for additional guidelines:
  64. [https://websocket-client.readthedocs.io/en/latest/faq.html](https://websocket-client.readthedocs.io/en/latest/faq.html)
  65. Known issues with this library include lack of WebSocket Compression
  66. support (RFC 7692) and [minimal threading documentation/support](https://websocket-client.readthedocs.io/en/latest/threading.html).
  67. ## License
  68. - LGPL version 2.1
  69. ### Performance
  70. The `send` and `validate_utf8` methods are very slow in pure Python. You can
  71. disable UTF8 validation in this library (and receive a performance enhancement)
  72. with the `skip_utf8_validation` parameter. If you want to get better
  73. performance, please install both numpy and wsaccel, and import them into your
  74. project files - these other libraries will automatically be used when available.
  75. Note that wsaccel can sometimes cause other issues.
  76. ### Long-lived Connection
  77. Most real-world WebSockets situations involve longer-lived connections.
  78. The WebSocketApp `run_forever` loop automatically tries to reconnect when a
  79. connection is lost, and provides a variety of event-based connection controls.
  80. The project documentation has
  81. [additional examples](https://websocket-client.readthedocs.io/en/latest/examples.html)
  82. ```python
  83. import websocket
  84. try:
  85. import thread
  86. except ImportError:
  87. import _thread as thread
  88. import time
  89. def on_message(ws, message):
  90. print(message)
  91. def on_error(ws, error):
  92. print(error)
  93. def on_close(ws):
  94. print("### closed ###")
  95. def on_open(ws):
  96. def run(*args):
  97. for i in range(3):
  98. time.sleep(1)
  99. ws.send("Hello %d" % i)
  100. time.sleep(1)
  101. ws.close()
  102. print("thread terminating...")
  103. thread.start_new_thread(run, ())
  104. if __name__ == "__main__":
  105. websocket.enableTrace(True)
  106. ws = websocket.WebSocketApp("ws://echo.websocket.org/",
  107. on_open = on_open,
  108. on_message = on_message,
  109. on_error = on_error,
  110. on_close = on_close)
  111. ws.run_forever()
  112. ```
  113. ### Short-lived Connection
  114. This is if you want to communicate a short message and disconnect
  115. immediately when done. For example, if you want to confirm that a WebSocket
  116. server is running and responds properly to a specific request.
  117. The project documentation has
  118. [additional examples](https://websocket-client.readthedocs.io/en/latest/examples.html)
  119. ```python
  120. from websocket import create_connection
  121. ws = create_connection("ws://echo.websocket.org/")
  122. print("Sending 'Hello, World'...")
  123. ws.send("Hello, World")
  124. print("Sent")
  125. print("Receiving...")
  126. result = ws.recv()
  127. print("Received '%s'" % result)
  128. ws.close()
  129. ```
  130. If you want to customize socket options, set sockopt, as seen below:
  131. ```python
  132. from websocket import create_connection
  133. ws = create_connection("ws://echo.websocket.org/",
  134. sockopt=((socket.IPPROTO_TCP, socket.TCP_NODELAY),))
  135. ```
  136. ### Acknowledgements
  137. Thanks to @battlemidget and @ralphbean for helping migrate this project to
  138. Python 3.