Skip to content

Commit d82a7a9

Browse files
committed
Revamp API documentation.
1 parent fcb3a4c commit d82a7a9

File tree

13 files changed

+517
-275
lines changed

13 files changed

+517
-275
lines changed

docs/api.rst

Lines changed: 0 additions & 125 deletions
This file was deleted.

docs/api/client.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Client
2+
======
3+
4+
.. automodule:: websockets.legacy.client
5+
6+
Opening a connection
7+
--------------------
8+
9+
.. autofunction:: connect(uri, *, create_protocol=None, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16, loop=None, compression='deflate', origin=None, extensions=None, subprotocols=None, extra_headers=None, **kwds)
10+
:async:
11+
12+
.. autofunction:: unix_connect(path, uri="ws://localhost/", *, create_protocol=None, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16, loop=None, compression='deflate', origin=None, extensions=None, subprotocols=None, extra_headers=None, **kwds)
13+
:async:
14+
15+
Using a connection
16+
------------------
17+
18+
.. autoclass:: WebSocketClientProtocol(*, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16, loop=None, origin=None, extensions=None, subprotocols=None, extra_headers=None)
19+
20+
.. autoattribute:: local_address
21+
22+
.. autoattribute:: remote_address
23+
24+
.. autoattribute:: open
25+
26+
.. autoattribute:: closed
27+
28+
.. attribute:: path
29+
30+
Path of the HTTP request.
31+
32+
Available once the connection is open.
33+
34+
.. attribute:: request_headers
35+
36+
HTTP request headers as a :class:`~websockets.http.Headers` instance.
37+
38+
Available once the connection is open.
39+
40+
.. attribute:: response_headers
41+
42+
HTTP response headers as a :class:`~websockets.http.Headers` instance.
43+
44+
Available once the connection is open.
45+
46+
.. attribute:: subprotocol
47+
48+
Subprotocol, if one was negotiated.
49+
50+
Available once the connection is open.
51+
52+
.. attribute:: close_code
53+
54+
WebSocket close code.
55+
56+
Available once the connection is closed.
57+
58+
.. attribute:: close_reason
59+
60+
WebSocket close reason.
61+
62+
Available once the connection is closed.
63+
64+
.. automethod:: recv
65+
66+
.. automethod:: send
67+
68+
.. automethod:: ping
69+
70+
.. automethod:: pong
71+
72+
.. automethod:: close
73+
74+
.. automethod:: wait_closed

docs/api/extensions.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Extensions
2+
==========
3+
4+
Per-Message Deflate
5+
-------------------
6+
7+
.. automodule:: websockets.extensions.permessage_deflate
8+
9+
.. autoclass:: ClientPerMessageDeflateFactory
10+
11+
.. autoclass:: ServerPerMessageDeflateFactory
12+
13+
Abstract classes
14+
----------------
15+
16+
.. automodule:: websockets.extensions.base
17+
18+
.. autoclass:: Extension
19+
:members:
20+
21+
.. autoclass:: ClientExtensionFactory
22+
:members:
23+
24+
.. autoclass:: ServerExtensionFactory
25+
:members:
26+

docs/api/index.rst

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
API
2+
===
3+
4+
``websockets`` provides complete client and server implementations, as shown
5+
in the :doc:`getting started guide <../intro>`.
6+
7+
The process for opening and closing a WebSocket connection depends on which
8+
side you're implementing.
9+
10+
* On the client side, connecting to a server with :class:`~websockets.connect`
11+
yields a connection object that provides methods for interacting with the
12+
connection. Your code can open a connection, then send or receive messages.
13+
14+
If you use :class:`~websockets.connect` as an asynchronous context manager,
15+
then websockets closes the connection on exit. If not, then your code is
16+
responsible for closing the connection.
17+
18+
* On the server side, :class:`~websockets.serve` starts listening for client
19+
connections and yields an server object that supports closing the server.
20+
21+
Then, when clients connects, the server initializes a connection object and
22+
passes it to a handler coroutine, which is where your code can send or
23+
receive messages. This pattern is called `inversion of control`_. It's
24+
common in frameworks implementing servers.
25+
26+
When the handler coroutine terminates, websockets closes the connection. You
27+
may also close it in the handler coroutine if you'd like.
28+
29+
.. _inversion of control: https://en.wikipedia.org/wiki/Inversion_of_control
30+
31+
Once the connection is open, the WebSocket protocol is symmetrical, except for
32+
low-level details that websockets manages under the hood. The same methods are
33+
available on client connections created with :class:`~websockets.connect` and
34+
on server connections passed to the connection handler in the arguments.
35+
36+
At this point, websockets provides the same API — and uses the same code — for
37+
client and server connections. For convenience, common methods are documented
38+
both in the client API and server API.
39+
40+
.. toctree::
41+
:maxdepth: 2
42+
43+
client
44+
server
45+
extensions
46+
utilities
47+
48+
All public APIs can be imported from the :mod:`websockets` package, unless
49+
noted otherwise. Anything that isn't listed in this API documentation is a
50+
private API, with no guarantees of behavior or backwards-compatibility.

docs/api/server.rst

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Server
2+
======
3+
4+
.. automodule:: websockets.legacy.server
5+
6+
Starting a server
7+
-----------------
8+
9+
.. autofunction:: serve(ws_handler, host=None, port=None, *, create_protocol=None, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16, loop=None, compression='deflate', origins=None, extensions=None, subprotocols=None, extra_headers=None, process_request=None, select_subprotocol=None, **kwds)
10+
:async:
11+
12+
.. autofunction:: unix_serve(ws_handler, path, *, create_protocol=None, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16, loop=None, compression='deflate', origins=None, extensions=None, subprotocols=None, extra_headers=None, process_request=None, select_subprotocol=None, **kwds)
13+
:async:
14+
15+
Stopping a server
16+
-----------------
17+
18+
.. autoclass:: WebSocketServer
19+
20+
.. autoattribute:: sockets
21+
22+
.. automethod:: close
23+
.. automethod:: wait_closed
24+
25+
Using a connection
26+
------------------
27+
28+
.. autoclass:: WebSocketServerProtocol(ws_handler, ws_server, *, ping_interval=20, ping_timeout=20, close_timeout=10, max_size=2 ** 20, max_queue=2 ** 5, read_limit=2 ** 16, write_limit=2 ** 16, loop=None, origins=None, extensions=None, subprotocols=None, extra_headers=None, process_request=None, select_subprotocol=None)
29+
30+
.. autoattribute:: local_address
31+
32+
.. autoattribute:: remote_address
33+
34+
.. autoattribute:: open
35+
36+
.. autoattribute:: closed
37+
38+
.. attribute:: path
39+
40+
Path of the HTTP request.
41+
42+
Available once the connection is open.
43+
44+
.. attribute:: request_headers
45+
46+
HTTP request headers as a :class:`~websockets.http.Headers` instance.
47+
48+
Available once the connection is open.
49+
50+
.. attribute:: response_headers
51+
52+
HTTP response headers as a :class:`~websockets.http.Headers` instance.
53+
54+
Available once the connection is open.
55+
56+
.. attribute:: subprotocol
57+
58+
Subprotocol, if one was negotiated.
59+
60+
Available once the connection is open.
61+
62+
.. attribute:: close_code
63+
64+
WebSocket close code.
65+
66+
Available once the connection is closed.
67+
68+
.. attribute:: close_reason
69+
70+
WebSocket close reason.
71+
72+
Available once the connection is closed.
73+
74+
.. automethod:: process_request
75+
76+
.. automethod:: select_subprotocol
77+
78+
.. automethod:: recv
79+
80+
.. automethod:: send
81+
82+
.. automethod:: ping
83+
84+
.. automethod:: pong
85+
86+
.. automethod:: close
87+
88+
.. automethod:: wait_closed
89+
90+
Basic authentication
91+
--------------------
92+
93+
.. automodule:: websockets.legacy.auth
94+
95+
.. autofunction:: basic_auth_protocol_factory
96+
97+
.. autoclass:: BasicAuthWebSocketServerProtocol
98+
99+
.. automethod:: process_request
100+
101+
.. attribute:: username
102+
103+
Username of the authenticated user.
104+
105+

0 commit comments

Comments
 (0)