Skip to content

Commit 70bb1d9

Browse files
ivandaschisapego
authored andcommitted
IGNITE-14418 Add async client documentation, update examples
This closes #29
1 parent e48f4be commit 70bb1d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+1535
-692
lines changed

README.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,8 @@ Do not forget to install test requirements:
9999
$ pip install -r requirements/install.txt -r requirements/tests.txt
100100
```
101101

102-
Also, you'll need to have a binary release of Ignite with lib4j2 enabled and
103-
`IGNITE_HOME` properly set:
102+
Also, you'll need to have a binary release of Ignite with `log4j2` enabled and to set
103+
`IGNITE_HOME` environment variable:
104104
```bash
105105
$ cd <ignite_binary_release>
106106
$ export IGNITE_HOME=$(pwd)
@@ -114,14 +114,6 @@ $ pytest
114114
```bash
115115
$ pytest --examples
116116
```
117-
### Run with ssl and not encrypted key
118-
```bash
119-
$ pytest --use-ssl=True --ssl-certfile=./tests/ssl/client_full.pem
120-
```
121-
### Run with ssl and password-protected key
122-
```bash
123-
$ pytest --use-ssl=True --ssl-certfile=./tests/config/ssl/client_with_pass_full.pem --ssl-keyfile-password=654321
124-
```
125117

126118
If you need to change the connection parameters, see the documentation on
127119
[testing](https://apache-ignite-binary-protocol-client.readthedocs.io/en/latest/readme.html#testing).

docs/async_examples.rst

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
.. Licensed to the Apache Software Foundation (ASF) under one or more
2+
contributor license agreements. See the NOTICE file distributed with
3+
this work for additional information regarding copyright ownership.
4+
The ASF licenses this file to You under the Apache License, Version 2.0
5+
(the "License"); you may not use this file except in compliance with
6+
the License. You may obtain a copy of the License at
7+
8+
.. http://www.apache.org/licenses/LICENSE-2.0
9+
10+
.. Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
.. _async_examples_of_usage:
17+
18+
============================
19+
Asynchronous client examples
20+
============================
21+
File: `async_key_value.py`_.
22+
23+
Basic usage
24+
-----------
25+
Asynchronous client and cache (:py:class:`~pyignite.aio_client.AioClient` and :py:class:`~pyignite.aio_cache.AioCache`)
26+
has mostly the same API as synchronous ones (:py:class:`~pyignite.client.Client` and :py:class:`~pyignite.cache.Cache`).
27+
But there is some peculiarities.
28+
29+
Basic key-value
30+
===============
31+
Firstly, import dependencies.
32+
33+
.. literalinclude:: ../examples/async_key_value.py
34+
:language: python
35+
:lines: 18
36+
37+
Let's connect to cluster and perform key-value queries.
38+
39+
.. literalinclude:: ../examples/async_key_value.py
40+
:language: python
41+
:dedent: 4
42+
:lines: 23-38
43+
44+
Scan
45+
====
46+
The :py:meth:`~pyignite.aio_cache.AioСache.scan` method returns :py:class:`~pyignite.cursors.AioScanCursor`,
47+
that yields the resulting rows.
48+
49+
.. literalinclude:: ../examples/async_key_value.py
50+
:language: python
51+
:dedent: 4
52+
:lines: 39-50
53+
54+
55+
File: `async_sql.py`_.
56+
57+
SQL
58+
---
59+
60+
First let us establish a connection.
61+
62+
.. literalinclude:: ../examples/async_sql.py
63+
:language: python
64+
:dedent: 4
65+
:lines: 197-198
66+
67+
Then create tables. Begin with `Country` table, than proceed with related
68+
tables `City` and `CountryLanguage`.
69+
70+
.. literalinclude:: ../examples/async_sql.py
71+
:language: python
72+
:lines: 25-42, 51-59, 67-74
73+
74+
.. literalinclude:: ../examples/async_sql.py
75+
:language: python
76+
:dedent: 4
77+
:lines: 199-205
78+
79+
Create indexes.
80+
81+
.. literalinclude:: ../examples/async_sql.py
82+
:language: python
83+
:lines: 60-62, 75-77
84+
85+
.. literalinclude:: ../examples/async_sql.py
86+
:language: python
87+
:dedent: 8
88+
:lines: 207-209
89+
90+
Fill tables with data.
91+
92+
.. literalinclude:: ../examples/async_sql.py
93+
:language: python
94+
:lines: 43-50, 63-66, 78-81
95+
96+
.. literalinclude:: ../examples/async_sql.py
97+
:language: python
98+
:dedent: 8
99+
:lines: 212-223
100+
101+
Now let us answer some questions.
102+
103+
What are the 10 largest cities in our data sample (population-wise)?
104+
====================================================================
105+
106+
.. literalinclude:: ../examples/async_sql.py
107+
:language: python
108+
:dedent: 8
109+
:lines: 225-243
110+
111+
The :py:meth:`~pyignite.aio_client.AioClient.sql` method returns :py:class:`~pyignite.cursors.AioSqlFieldsCursor`,
112+
that yields the resulting rows.
113+
114+
What are the 10 most populated cities throughout the 3 chosen countries?
115+
========================================================================
116+
117+
If you set the `include_field_names` argument to `True`, the
118+
:py:meth:`~pyignite.client.Client.sql` method will generate a list of
119+
column names as a first yield. Unfortunately, there is no async equivalent of `next` but
120+
you can await :py:meth:`__anext__()`
121+
of :py:class:`~pyignite.cursors.AioSqlFieldsCursor`
122+
123+
.. literalinclude:: ../examples/async_sql.py
124+
:language: python
125+
:dedent: 8
126+
:lines: 246-271
127+
128+
Display all the information about a given city
129+
==============================================
130+
131+
.. literalinclude:: ../examples/async_sql.py
132+
:language: python
133+
:dedent: 8
134+
:lines: 273-288
135+
136+
Finally, delete the tables used in this example with the following queries:
137+
138+
.. literalinclude:: ../examples/async_sql.py
139+
:language: python
140+
:lines: 83
141+
142+
.. literalinclude:: ../examples/async_sql.py
143+
:language: python
144+
:dedent: 8
145+
:lines: 290-297
146+
147+
148+
149+
150+
.. _async_key_value.py: https://github.com/apache/ignite-python-thin-client/blob/master/examples/async_key_value.py
151+
.. _async_sql.py: https://github.com/apache/ignite-python-thin-client/blob/master/examples/async_sql.py

docs/conf.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
# -*- coding: utf-8 -*-
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
217
#
318
# Configuration file for the Sphinx documentation builder.
419
#
@@ -14,19 +29,16 @@
1429
#
1530
import os
1631
import sys
32+
33+
1734
sys.path.insert(0, os.path.abspath('../'))
1835

1936

2037
# -- Project information -----------------------------------------------------
2138

2239
project = 'Apache Ignite binary client Python API'
23-
copyright = '2018, Apache Software Foundation (ASF)'
24-
author = 'Dmitry Melnichuk'
25-
26-
# The short X.Y version
27-
version = ''
28-
# The full version, including alpha/beta/rc tags
29-
release = '0.1.0'
40+
copyright = '2021, Apache Software Foundation (ASF)'
41+
author = ''
3042

3143

3244
# -- General configuration ---------------------------------------------------

docs/datatypes/cache_props.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ matters.
3131
| name | value | type | |
3232
+=======================================+==========+==========+=======================================================+
3333
| Read/write cache properties, used to configure cache via :py:meth:`~pyignite.client.Client.create_cache` or |
34-
| :py:meth:`~pyignite.client.Client.get_or_create_cache` |
34+
| :py:meth:`~pyignite.client.Client.get_or_create_cache` of :py:class:`~pyignite.client.Client` |
35+
| (:py:meth:`~pyignite.aio_client.AioClient.create_cache` or |
36+
| :py:meth:`~pyignite.aio_client.AioClient.get_or_create_cache` of :py:class:`~pyignite.aio_client.AioClient`). |
3537
+---------------------------------------+----------+----------+-------------------------------------------------------+
3638
| PROP_NAME | 0 | str | Cache name. This is the only *required* property. |
3739
+---------------------------------------+----------+----------+-------------------------------------------------------+
@@ -96,10 +98,6 @@ matters.
9698
+---------------------------------------+----------+----------+-------------------------------------------------------+
9799
| PROP_STATISTICS_ENABLED | 406 | bool | Statistics enabled |
98100
+---------------------------------------+----------+----------+-------------------------------------------------------+
99-
| Read-only cache properties. Can not be set, but only retrieved via :py:meth:`~pyignite.cache.Cache.settings` |
100-
+---------------------------------------+----------+----------+-------------------------------------------------------+
101-
| PROP_INVALIDATE | -1 | bool | Invalidate |
102-
+---------------------------------------+----------+----------+-------------------------------------------------------+
103101

104102
Query entity
105103
------------

0 commit comments

Comments
 (0)