METADATA 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. Metadata-Version: 2.4
  2. Name: websocket-client
  3. Version: 1.9.0
  4. Summary: WebSocket client for Python with low level API options
  5. Home-page: https://github.com/websocket-client/websocket-client.git
  6. Download-URL: https://github.com/websocket-client/websocket-client/releases
  7. Author: liris
  8. Author-email: liris.pp@gmail.com
  9. Maintainer: engn33r
  10. Maintainer-email: websocket.client@proton.me
  11. License: Apache-2.0
  12. Project-URL: Documentation, https://websocket-client.readthedocs.io/
  13. Project-URL: Source, https://github.com/websocket-client/websocket-client/
  14. Keywords: websockets client
  15. Classifier: Development Status :: 4 - Beta
  16. Classifier: License :: OSI Approved :: Apache Software License
  17. Classifier: Programming Language :: Python :: 3
  18. Classifier: Programming Language :: Python :: 3.9
  19. Classifier: Programming Language :: Python :: 3.10
  20. Classifier: Programming Language :: Python :: 3.11
  21. Classifier: Programming Language :: Python :: 3.12
  22. Classifier: Programming Language :: Python :: 3.13
  23. Classifier: Operating System :: MacOS :: MacOS X
  24. Classifier: Operating System :: POSIX
  25. Classifier: Operating System :: Microsoft :: Windows
  26. Classifier: Topic :: Internet
  27. Classifier: Topic :: Software Development :: Libraries :: Python Modules
  28. Classifier: Intended Audience :: Developers
  29. Requires-Python: >=3.9
  30. Description-Content-Type: text/markdown
  31. License-File: LICENSE
  32. Provides-Extra: test
  33. Requires-Dist: pytest; extra == "test"
  34. Requires-Dist: websockets; extra == "test"
  35. Provides-Extra: optional
  36. Requires-Dist: python-socks; extra == "optional"
  37. Requires-Dist: wsaccel; extra == "optional"
  38. Provides-Extra: docs
  39. Requires-Dist: Sphinx>=6.0; extra == "docs"
  40. Requires-Dist: sphinx_rtd_theme>=1.1.0; extra == "docs"
  41. Requires-Dist: myst-parser>=2.0.0; extra == "docs"
  42. Dynamic: author
  43. Dynamic: author-email
  44. Dynamic: classifier
  45. Dynamic: description
  46. Dynamic: description-content-type
  47. Dynamic: download-url
  48. Dynamic: home-page
  49. Dynamic: keywords
  50. Dynamic: license
  51. Dynamic: license-file
  52. Dynamic: maintainer
  53. Dynamic: maintainer-email
  54. Dynamic: project-url
  55. Dynamic: provides-extra
  56. Dynamic: requires-python
  57. Dynamic: summary
  58. [![docs](https://readthedocs.org/projects/websocket-client/badge/?style=flat)](https://websocket-client.readthedocs.io/)
  59. [![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)
  60. [![codecov](https://codecov.io/gh/websocket-client/websocket-client/branch/master/graph/badge.svg?token=pcXhUQwiL3)](https://codecov.io/gh/websocket-client/websocket-client)
  61. [![PyPI Downloads](https://pepy.tech/badge/websocket-client)](https://pepy.tech/project/websocket-client)
  62. [![PyPI version](https://img.shields.io/pypi/v/websocket_client)](https://pypi.org/project/websocket_client/)
  63. [![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
  64. [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
  65. # websocket-client
  66. websocket-client is a WebSocket client for Python. It provides access
  67. to low level APIs for WebSockets. websocket-client implements version
  68. [hybi-13](https://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-13)
  69. of the WebSocket protocol. This client does not currently support the
  70. permessage-deflate extension from
  71. [RFC 7692](https://tools.ietf.org/html/rfc7692).
  72. ## Documentation
  73. This project's documentation can be found at
  74. [https://websocket-client.readthedocs.io/](https://websocket-client.readthedocs.io/)
  75. ## Contributing
  76. Please see the [contribution guidelines](https://github.com/websocket-client/websocket-client/blob/master/CONTRIBUTING.md)
  77. ## Installation
  78. You can use `pip install websocket-client` to install, or `pip install -e .`
  79. to install from a local copy of the code. This module is tested on Python 3.9+.
  80. There are several optional dependencies that can be installed to enable
  81. specific websocket-client features.
  82. - To install `python-socks` for proxy usage and `wsaccel` for a minor performance boost, use:
  83. `pip install websocket-client[optional]`
  84. - To install `websockets` to run unit tests using the local echo server, use:
  85. `pip install websocket-client[test]`
  86. - To install `Sphinx` and `sphinx_rtd_theme` to build project documentation, use:
  87. `pip install websocket-client[docs]`
  88. While not a strict dependency, [rel](https://github.com/bubbleboy14/registeredeventlistener)
  89. is useful when using `run_forever` with automatic reconnect. Install rel with `pip install rel`.
  90. Footnote: Some shells, such as zsh, require you to escape the `[` and `]` characters with a `\`.
  91. ## Usage Tips
  92. Check out the documentation's FAQ for additional guidelines:
  93. [https://websocket-client.readthedocs.io/en/latest/faq.html](https://websocket-client.readthedocs.io/en/latest/faq.html)
  94. Known issues with this library include lack of WebSocket Compression
  95. support (RFC 7692) and [minimal threading documentation/support](https://websocket-client.readthedocs.io/en/latest/threading.html).
  96. ## Performance
  97. The `send` and `validate_utf8` methods can sometimes be bottleneck.
  98. You can disable UTF8 validation in this library (and receive a
  99. performance enhancement) with the `skip_utf8_validation` parameter.
  100. If you want to get better performance, install wsaccel. While
  101. websocket-client does not depend on wsaccel, it will be used if
  102. available. wsaccel doubles the speed of UTF8 validation and
  103. offers a very minor 10% performance boost when masking the
  104. payload data as part of the `send` process. Numpy used to
  105. be a suggested performance enhancement alternative, but
  106. [issue #687](https://github.com/websocket-client/websocket-client/issues/687)
  107. found it didn't help.
  108. ## Examples
  109. Many more examples are found in the
  110. [examples documentation](https://websocket-client.readthedocs.io/en/latest/examples.html).
  111. ### Long-lived Connection
  112. Most real-world WebSockets situations involve longer-lived connections.
  113. The WebSocketApp `run_forever` loop will automatically try to reconnect
  114. to an open WebSocket connection when a network
  115. connection is lost if it is provided with:
  116. - a `dispatcher` argument (async dispatcher like rel or pyevent)
  117. - a non-zero `reconnect` argument (delay between disconnection and attempted reconnection)
  118. `run_forever` provides a variety of event-based connection controls
  119. using callbacks like `on_message` and `on_error`.
  120. `run_forever` **does not automatically reconnect** if the server
  121. closes the WebSocket gracefully (returning
  122. [a standard websocket close code](https://www.rfc-editor.org/rfc/rfc6455.html#section-7.4.1)).
  123. [This is the logic](https://github.com/websocket-client/websocket-client/pull/838#issuecomment-1228454826) behind the decision.
  124. Customizing behavior when the server closes
  125. the WebSocket should be handled in the `on_close` callback.
  126. This example uses [rel](https://github.com/bubbleboy14/registeredeventlistener)
  127. for the dispatcher to provide automatic reconnection.
  128. ```python
  129. import websocket
  130. import _thread
  131. import time
  132. import rel
  133. def on_message(ws, message):
  134. print(message)
  135. def on_error(ws, error):
  136. print(error)
  137. def on_close(ws, close_status_code, close_msg):
  138. print("### closed ###")
  139. def on_open(ws):
  140. print("Opened connection")
  141. if __name__ == "__main__":
  142. websocket.enableTrace(True)
  143. ws = websocket.WebSocketApp("wss://api.gemini.com/v1/marketdata/BTCUSD",
  144. on_open=on_open,
  145. on_message=on_message,
  146. on_error=on_error,
  147. on_close=on_close)
  148. ws.run_forever(dispatcher=rel, reconnect=5) # Set dispatcher to automatic reconnection, 5 second reconnect delay if connection closed unexpectedly
  149. rel.signal(2, rel.abort) # Keyboard Interrupt
  150. rel.dispatch()
  151. ```
  152. ### Short-lived Connection
  153. This is if you want to communicate a short message and disconnect
  154. immediately when done. For example, if you want to confirm that a WebSocket
  155. server is running and responds properly to a specific request.
  156. ```python
  157. from websocket import create_connection
  158. ws = create_connection("ws://echo.websocket.events/")
  159. print(ws.recv())
  160. print("Sending 'Hello, World'...")
  161. ws.send("Hello, World")
  162. print("Sent")
  163. print("Receiving...")
  164. result = ws.recv()
  165. print("Received '%s'" % result)
  166. ws.close()
  167. ```