Debian Codegraph @

third_party/python/aiohttp/README.rst

raw
1 ==================================
2 Async http client/server framework
3 ==================================
4
5 .. image:: https://raw.githubusercontent.com/aio-libs/aiohttp/master/docs/aiohttp-plain.svg
6 :height: 64px
7 :width: 64px
8 :alt: aiohttp logo
9
10 |
11
12 .. image:: https://github.com/aio-libs/aiohttp/workflows/CI/badge.svg
13 :target: https://github.com/aio-libs/aiohttp/actions?query=workflow%3ACI
14 :alt: GitHub Actions status for master branch
15
16 .. image:: https://codecov.io/gh/aio-libs/aiohttp/branch/master/graph/badge.svg
17 :target: https://codecov.io/gh/aio-libs/aiohttp
18 :alt: codecov.io status for master branch
19
20 .. image:: https://img.shields.io/endpoint?url=https://codspeed.io/badge.json
21 :target: https://codspeed.io/aio-libs/aiohttp
22 :alt: Codspeed.io status for aiohttp
23
24 .. image:: https://badge.fury.io/py/aiohttp.svg
25 :target: https://pypi.org/project/aiohttp
26 :alt: Latest PyPI package version
27
28 .. image:: https://readthedocs.org/projects/aiohttp/badge/?version=latest
29 :target: https://docs.aiohttp.org/
30 :alt: Latest Read The Docs
31
32 .. image:: https://img.shields.io/matrix/aio-libs:matrix.org?label=Discuss%20on%20Matrix%20at%20%23aio-libs%3Amatrix.org&logo=matrix&server_fqdn=matrix.org&style=flat
33 :target: https://matrix.to/#/%23aio-libs:matrix.org
34 :alt: Matrix Room — #aio-libs:matrix.org
35
36 .. image:: https://img.shields.io/matrix/aio-libs-space:matrix.org?label=Discuss%20on%20Matrix%20at%20%23aio-libs-space%3Amatrix.org&logo=matrix&server_fqdn=matrix.org&style=flat
37 :target: https://matrix.to/#/%23aio-libs-space:matrix.org
38 :alt: Matrix Space — #aio-libs-space:matrix.org
39
40
41 Key Features
42 ============
43
44 - Supports both client and server side of HTTP protocol.
45 - Supports both client and server Web-Sockets out-of-the-box and avoids
46 Callback Hell.
47 - Provides Web-server with middleware and pluggable routing.
48
49
50 Getting started
51 ===============
52
53 Client
54 ------
55
56 To get something from the web:
57
58 .. code-block:: python
59
60 import aiohttp
61 import asyncio
62
63 async def main():
64
65 async with aiohttp.ClientSession() as session:
66 async with session.get('http://python.org') as response:
67
68 print("Status:", response.status)
69 print("Content-type:", response.headers['content-type'])
70
71 html = await response.text()
72 print("Body:", html[:15], "...")
73
74 asyncio.run(main())
75
76 This prints:
77
78 .. code-block::
79
80 Status: 200
81 Content-type: text/html; charset=utf-8
82 Body: <!doctype html> ...
83
84 Coming from `requests <https://requests.readthedocs.io/>`_ ? Read `why we need so many lines <https://aiohttp.readthedocs.io/en/latest/http_request_lifecycle.html>`_.
85
86 Server
87 ------
88
89 An example using a simple server:
90
91 .. code-block:: python
92
93 # examples/server_simple.py
94 from aiohttp import web
95
96 async def handle(request):
97 name = request.match_info.get('name', "Anonymous")
98 text = "Hello, " + name
99 return web.Response(text=text)
100
101 async def wshandle(request):
102 ws = web.WebSocketResponse()
103 await ws.prepare(request)
104
105 async for msg in ws:
106 if msg.type == web.WSMsgType.text:
107 await ws.send_str("Hello, {}".format(msg.data))
108 elif msg.type == web.WSMsgType.binary:
109 await ws.send_bytes(msg.data)
110 elif msg.type == web.WSMsgType.close:
111 break
112
113 return ws
114
115
116 app = web.Application()
117 app.add_routes([web.get('/', handle),
118 web.get('/echo', wshandle),
119 web.get('/{name}', handle)])
120
121 if __name__ == '__main__':
122 web.run_app(app)
123
124
125 Documentation
126 =============
127
128 https://aiohttp.readthedocs.io/
129
130
131 Demos
132 =====
133
134 https://github.com/aio-libs/aiohttp-demos
135
136
137 External links
138 ==============
139
140 * `Third party libraries
141 <http://aiohttp.readthedocs.io/en/latest/third_party.html>`_
142 * `Built with aiohttp
143 <http://aiohttp.readthedocs.io/en/latest/built_with.html>`_
144 * `Powered by aiohttp
145 <http://aiohttp.readthedocs.io/en/latest/powered_by.html>`_
146
147 Feel free to make a Pull Request for adding your link to these pages!
148
149
150 Communication channels
151 ======================
152
153 *aio-libs Discussions*: https://github.com/aio-libs/aiohttp/discussions
154
155 *Matrix*: `#aio-libs:matrix.org <https://matrix.to/#/#aio-libs:matrix.org>`_
156
157 We support `Stack Overflow
158 <https://stackoverflow.com/questions/tagged/aiohttp>`_.
159 Please add *aiohttp* tag to your question there.
160
161 Requirements
162 ============
163
164 - attrs_
165 - multidict_
166 - yarl_
167 - frozenlist_
168
169 Optionally you may install the aiodns_ library (highly recommended for sake of speed).
170
171 .. _aiodns: https://pypi.python.org/pypi/aiodns
172 .. _attrs: https://github.com/python-attrs/attrs
173 .. _multidict: https://pypi.python.org/pypi/multidict
174 .. _frozenlist: https://pypi.org/project/frozenlist/
175 .. _yarl: https://pypi.python.org/pypi/yarl
176 .. _async-timeout: https://pypi.python.org/pypi/async_timeout
177
178 License
179 =======
180
181 ``aiohttp`` is offered under the Apache 2 license.
182
183
184 Keepsafe
185 ========
186
187 The aiohttp community would like to thank Keepsafe
188 (https://www.getkeepsafe.com) for its support in the early days of
189 the project.
190
191
192 Source code
193 ===========
194
195 The latest developer version is available in a GitHub repository:
196 https://github.com/aio-libs/aiohttp
197
198 Benchmarks
199 ==========
200
201 If you are interested in efficiency, the AsyncIO community maintains a
202 list of benchmarks on the official wiki:
203 https://github.com/python/asyncio/wiki/Benchmarks