Skip to content

Commit 67bdf5d

Browse files
committed
Documentation updates
1 parent bb292c7 commit 67bdf5d

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

docs/examples.rst

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
.. _asyncpg-examples:
2+
3+
4+
Usage Examples
5+
==============
6+
7+
Below is an example of how **asyncpg** can be used to implement a simple
8+
Web service that computes the requested power of two.
9+
10+
11+
.. code-block:: python
12+
13+
import asyncio
14+
import asyncpg
15+
from aiohttp import web
16+
17+
18+
async def handle(request):
19+
"""Handle incoming requests."""
20+
pool = request.app['pool']
21+
power = int(request.match_info.get('power', 10))
22+
23+
# Take a connection from the pool.
24+
async with pool.acquire() as connection:
25+
# Open a transaction.
26+
async with connection.transaction():
27+
# Run the query passing the request argument.
28+
result = await connection.fetchval('select 2 ^ $1', power)
29+
return web.Response(
30+
text="2 ^ {} is {}".format(power, result))
31+
32+
33+
async def init_app():
34+
"""Initialize the application server."""
35+
app = web.Application()
36+
# Create a database connection pool
37+
app['pool'] = await asyncpg.create_pool(database='postgres',
38+
user='postgres')
39+
# Configure service routes
40+
app.router.add_route('GET', '/{power:\d+}', handle)
41+
app.router.add_route('GET', '/', handle)
42+
return app
43+
44+
45+
loop = asyncio.get_event_loop()
46+
app = loop.run_until_complete(init_app())
47+
web.run_app(app)

docs/index.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
:target: https://pypi.python.org/pypi/asyncpg
66

77

8+
=======
89
asyncpg
910
=======
1011

@@ -13,11 +14,16 @@ PostgreSQL and Python/asyncio. asyncpg is an efficient, clean implementation
1314
of PostgreSQL server binary protocol for use with Python's ``asyncio``
1415
framework.
1516

17+
**asyncpg** is a C extension and it is only currently compatible with
18+
CPython 3.5.
19+
1620

1721
Contents
1822
--------
1923

2024
.. toctree::
2125
:maxdepth: 2
2226

27+
installation
28+
examples
2329
api/index

docs/installation.rst

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
.. _asyncpg-installation:
2+
3+
4+
Installation
5+
============
6+
7+
**asyncpg** has no external dependencies and the recommended way to
8+
install it is to use **pip**:
9+
10+
.. code-block:: bash
11+
12+
$ pip install asyncpg
13+
14+
15+
.. note::
16+
17+
It is recommended to use **pip** version **8.1** or later to take
18+
advantage of the precompiled wheel packages. Older versions of pip
19+
will ignore the wheel packages and install asyncpg from the source
20+
package. In that case a working C compiler is required.
21+
22+
23+
Building from source
24+
--------------------
25+
26+
If you want to build **asyncpg** from a Git checkout you will need:
27+
28+
* A working C compiler.
29+
* CPython header files. These can usually be obtained by installing
30+
the relevant Python development package: **python3-dev** on Debian/Ubuntu,
31+
**python3-devel** on RHEL/Fedora.
32+
* Cython version 0.24 or later. The easiest way to install it to use
33+
virtualenv and pip, however a system package should also suffice.
34+
* GNU make
35+
36+
Once the above requirements are satisfied, run:
37+
38+
.. code-block:: bash
39+
40+
$ make
41+
42+
At this point you can run the usual ``setup.py`` commands or
43+
``pip install -e .`` to install the newly built version.
44+
45+
.. note::
46+
47+
A debug build can be created by running ``make debug``.
48+
49+
50+
Running tests
51+
-------------
52+
53+
To execute the testsuite simply run:
54+
55+
.. code-block:: bash
56+
57+
$ make test

0 commit comments

Comments
 (0)