• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

bench/H22-Nov-2020-5845

compliance/H22-Nov-2020-516404

docs/H22-Nov-2020-626435

example/H22-Nov-2020-232170

src/H22-Nov-2020-2,3301,693

test/H22-Nov-2020-2,6712,203

CHANGELOG.rstH A D22-Nov-20204.6 KiB137109

LICENSEH A D30-Jul-20171.1 KiB2117

MANIFEST.inH A D22-Nov-2020372 1413

PKG-INFOH A D22-Nov-20206.8 KiB180125

README.rstH A D30-Jul-20204.7 KiB157103

setup.cfgH A D22-Nov-20201 KiB5647

setup.pyH A D22-Nov-20201.9 KiB6351

tox.iniH A D22-Nov-20201.5 KiB7666

README.rst

1========================================================
2Pure Python, pure state-machine WebSocket implementation
3========================================================
4
5.. image:: https://github.com/python-hyper/wsproto/workflows/CI/badge.svg
6    :target: https://github.com/python-hyper/wsproto/actions
7    :alt: Build Status
8.. image:: https://codecov.io/gh/python-hyper/wsproto/branch/master/graph/badge.svg
9    :target: https://codecov.io/gh/python-hyper/wsproto
10    :alt: Code Coverage
11.. image:: https://readthedocs.org/projects/wsproto/badge/?version=latest
12    :target: https://wsproto.readthedocs.io/en/latest/
13    :alt: Documentation Status
14.. image:: https://codecov.io/gh/python-hyper/wsproto/branch/master/graph/badge.svg
15    :target: https://codecov.io/gh/python-hyper/wsproto
16    :alt: Code coverage
17.. image:: https://img.shields.io/badge/chat-join_now-brightgreen.svg
18    :target: https://gitter.im/python-hyper/community
19    :alt: Chat community
20
21
22This repository contains a pure-Python implementation of a WebSocket protocol
23stack. It's written from the ground up to be embeddable in whatever program you
24choose to use, ensuring that you can communicate via WebSockets, as defined in
25`RFC6455 <https://tools.ietf.org/html/rfc6455>`_, regardless of your programming
26paradigm.
27
28This repository does not provide a parsing layer, a network layer, or any rules
29about concurrency. Instead, it's a purely in-memory solution, defined in terms
30of data actions and WebSocket frames. RFC6455 and Compression Extensions for
31WebSocket via `RFC7692 <https://tools.ietf.org/html/rfc7692>`_ are fully
32supported.
33
34wsproto supports Python 3.6.1 or higher.
35
36To install it, just run:
37
38.. code-block:: console
39
40    $ pip install wsproto
41
42
43Usage
44=====
45
46Let's assume you have some form of network socket available. wsproto client
47connections automatically generate a HTTP request to initiate the WebSocket
48handshake. To create a WebSocket client connection:
49
50.. code-block:: python
51
52  from wsproto import WSConnection, ConnectionType
53  from wsproto.events import Request
54
55  ws = WSConnection(ConnectionType.CLIENT)
56  ws.send(Request(host='echo.websocket.org', target='/'))
57
58To create a WebSocket server connection:
59
60.. code-block:: python
61
62  from wsproto.connection import WSConnection, ConnectionType
63
64  ws = WSConnection(ConnectionType.SERVER)
65
66Every time you send a message, or call a ping, or simply if you receive incoming
67data, wsproto might respond with some outgoing data that you have to send:
68
69.. code-block:: python
70
71  some_socket.send(ws.bytes_to_send())
72
73Both connection types need to receive incoming data:
74
75.. code-block:: python
76
77  ws.receive_data(some_byte_string_of_data)
78
79And wsproto will issue events if the data contains any WebSocket messages or state changes:
80
81.. code-block:: python
82
83  for event in ws.events():
84      if isinstance(event, Request):
85          # only client connections get this event
86          ws.send(AcceptConnection())
87      elif isinstance(event, CloseConnection):
88          # guess nobody wants to talk to us any more...
89      elif isinstance(event, TextMessage):
90          print('We got text!', event.data)
91      elif isinstance(event, BytesMessage):
92          print('We got bytes!', event.data)
93
94Take a look at our docs for a `full list of events
95<https://wsproto.readthedocs.io/en/latest/api.html#events>`!
96
97Testing
98=======
99
100It passes the autobahn test suite completely and strictly in both client and
101server modes and using permessage-deflate.
102
103If you want to run the compliance tests, go into the compliance directory and
104then to test client mode, in one shell run the Autobahn test server:
105
106.. code-block:: console
107
108    $ wstest -m fuzzingserver -s ws-fuzzingserver.json
109
110And in another shell run the test client:
111
112.. code-block:: console
113
114    $ python test_client.py
115
116And to test server mode, run the test server:
117
118.. code-block:: console
119
120    $ python test_server.py
121
122And in another shell run the Autobahn test client:
123
124.. code-block:: console
125
126    $ wstest -m fuzzingclient -s ws-fuzzingclient.json
127
128
129Documentation
130=============
131
132Documentation is available at https://wsproto.readthedocs.io/en/latest/.
133
134Contributing
135============
136
137``wsproto`` welcomes contributions from anyone! Unlike many other projects we
138are happy to accept cosmetic contributions and small contributions, in addition
139to large feature requests and changes.
140
141Before you contribute (either by opening an issue or filing a pull request),
142please `read the contribution guidelines`_.
143
144.. _read the contribution guidelines: http://python-hyper.org/en/latest/contributing.html
145
146License
147=======
148
149``wsproto`` is made available under the MIT License. For more details, see the
150``LICENSE`` file in the repository.
151
152Authors
153=======
154
155``wsproto`` was created by @jeamland, and is maintained by the python-hyper
156community.
157