METADATA 7.8 KB

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