Skip to content

Commit d48ee30

Browse files
committed
docs: Added examples to docs.
1 parent 73469f5 commit d48ee30

File tree

11 files changed

+201
-59
lines changed

11 files changed

+201
-59
lines changed

README.rst

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,63 @@ This client library implements QuestDB's variant of the
88
`InfluxDB Line Protocol <https://questdb.io/docs/reference/api/ilp/overview/>`_
99
(ILP) over TCP.
1010

11+
ILP provides the fastest way to insert data into QuestDB.
1112

12-
Status of the library
13-
=====================
13+
This implementation supports `authentication
14+
<https://questdb.io/docs/reference/api/ilp/authenticate/>`_ and full-connection
15+
encryption with TLS.
1416

15-
Work in progress: do not use yet.
16-
17-
There will be an announcement on our `slack <http://slack.questdb.io>`_ once
18-
it's ready for use.
19-
20-
21-
Installation
22-
=============
17+
Quickstart
18+
==========
2319

2420
The latest version of the library is 0.0.3.
2521

2622
::
2723

2824
python3 -m pip install questdb
2925

26+
.. code-block:: python
27+
28+
from questdb.ingress import Sender
29+
30+
with qi.Sender('localhost', 9009) as sender:
31+
sender.row(
32+
'sensors',
33+
symbols={'id': 'toronto1'},
34+
columns={'temperature': 20.0, 'humidity': 0.5})
35+
sender.flush()
36+
3037
3138
Docs
3239
====
3340

34-
https://py-questdb-client.readthedocs.io/
41+
https://py-questdb-client.readthedocs.io/
3542

3643

3744
Code
3845
====
3946

40-
https://github.com/questdb/py-questdb-client
47+
https://github.com/questdb/py-questdb-client
4148

4249

4350
Package on PyPI
4451
===============
4552

46-
https://pypi.org/project/questdb/
53+
https://pypi.org/project/questdb/
54+
55+
56+
Community
57+
=========
58+
59+
If you need help, have additional questions or want to provide feedback, you
60+
may find us on `Slack <https://slack.questdb.io>`_.
61+
62+
You can also `sign up to our mailing list <https://questdb.io/community/>`_
63+
to get notified of new releases.
64+
65+
66+
License
67+
=======
4768

69+
The code is released under the `Apache License 2.0
70+
<https://github.com/questdb/py-questdb-client/blob/main/LICENSE.txt>`_.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
'sphinx.ext.ifconfig',
1313
'sphinx.ext.napoleon',
1414
'sphinx.ext.todo',
15-
'sphinx.ext.viewcode',
15+
'sphinx.ext.viewcode'
1616
]
1717
source_suffix = '.rst'
1818
master_doc = 'index'

docs/examples.rst

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
========
2+
Examples
3+
========
4+
5+
Basics
6+
======
7+
8+
The following example connects to the database and sends two rows (lines).
9+
10+
The connection is unauthenticated and the data is sent at the end of the
11+
``with`` block.
12+
13+
Here the :class:`questdb.ingress.Sender` is constructed with just ``host`` and
14+
``port``.
15+
16+
.. literalinclude:: ../examples/basic.py
17+
:language: python
18+
19+
20+
Authentication and TLS
21+
======================
22+
23+
Continuing from the previous example, the connection is authenticated
24+
and also uses TLS.
25+
26+
Here the :class:`questdb.ingress.Sender` is also constructed with the ``auth``
27+
and ``tls`` arguments.
28+
29+
.. literalinclude:: ../examples/auth_and_tls.py
30+
:language: python
31+
32+
33+
Explicit Buffers
34+
================
35+
36+
For more advanced use cases where the same messages need to be sent to multiple
37+
questdb instances or you want to decouple serialization and sending (as may be
38+
in a multi-threaded application) construct :class:``questdb.ingress.Buffer``
39+
objects explicitly, then pass them to the :func:``questdb.ingress.Sender.flush``
40+
method.
41+
42+
Note that this bypasses ``auto-flush`` logic
43+
(see :class:`questdb.ingress.Sender`) and you are fully responsible for ensuring
44+
all data is sent.
45+
46+
.. literalinclude:: ../examples/buffer.py
47+
:language: python
48+

docs/index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ Contents
1212
:maxdepth: 2
1313

1414
installation
15-
usage
15+
examples
1616
api
17+
troubleshooting
1718
contributing
1819
changelog
1920

docs/troubleshooting.rst

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
===============
2+
Troubleshooting
3+
===============
4+
5+
Common issues
6+
=============
7+
8+
You may be experiencing one of the issues below.
9+
10+
Production-optimized QuestDB configuration
11+
------------------------------------------
12+
13+
If you can't initially see your data through a ``select`` SQL query straight
14+
away, this is normal: by default the database will only commit data it receives
15+
though the line protocol periodically to maximize throughput.
16+
17+
For dev/testing you may want to tune the following database configuration
18+
parameters as so::
19+
20+
# server.conf
21+
cairo.max.uncommitted.rows=1
22+
line.tcp.maintenance.job.interval=100
23+
24+
25+
The default QuestDB configuration is more applicable for a production
26+
environment.
27+
28+
For these and more configuration parameters refer to `database configuration
29+
<https://questdb.io/docs/reference/configuration/>`_ documentation.
30+
31+
32+
Infrequent Flushing
33+
-------------------
34+
35+
You may not see data appear in a timely manner because you're not calling
36+
:func:`questdb.ingress.Sender.flush` often enough.
37+
38+
The :class:`questdb.ingress.Sender` class only provides auto-flushing based on
39+
a buffer size and *not on a timer*.
40+
41+
42+
Inspecting and debugging errors
43+
===============================
44+
45+
Both the :class:`questdb.ingress.Sender` and :class:`questdb.ingress.Buffer`
46+
types support ``__len__`` and ``__str__`` methods to inspect the buffer that is
47+
about to be flushed.
48+
49+
Note that the ILP protocol does not send errors back to the client.
50+
51+
On error, the QuestDB server will disconnect and any error messages will be
52+
present in the `server logs
53+
<https://questdb.io/docs/concept/root-directory-structure#log-directory>`_.
54+
55+
56+
Asking for help
57+
===============
58+
59+
The best way to get help is through `Slack <https://slack.questdb.io>`_.

docs/usage.rst

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

examples/auth_and_tls.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from questdb.ingress import Sender
2+
3+
4+
def example():
5+
# See: https://questdb.io/docs/reference/api/ilp/authenticate
6+
auth = (
7+
"testUser1", # kid
8+
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48", # d
9+
"fLKYEaoEb9lrn3nkwLDA-M_xnuFOdSt9y0Z7_vWSHLU", # x
10+
"Dt5tbS1dEDMSYfym3fgMv0B99szno-dFc1rYF9t0aac") # y
11+
with Sender('localhost', 9009, auth=auth, tls=True) as sender:
12+
sender.row(
13+
'line_sender_example',
14+
symbols={'id': 'OMEGA'},
15+
columns={'price': 111222233333, 'qty': 3.5})
16+
sender.row(
17+
'line_sender_example',
18+
symbols={'id': 'ZHETA'},
19+
columns={'price': 111222233330, 'qty': 2.5})
20+
sender.flush()
21+
22+
23+
if __name__ == '__main__':
24+
example()

examples/basic.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from questdb.ingress import Sender
2+
3+
4+
def example():
5+
with Sender('localhost', 9009) as sender:
6+
sender.row(
7+
'line_sender_example',
8+
symbols={'id': 'OMEGA'},
9+
columns={'price': 111222233333, 'qty': 3.5})
10+
sender.row(
11+
'line_sender_example',
12+
symbols={'id': 'ZHETA'},
13+
columns={'price': 111222233330, 'qty': 2.5})
14+
sender.flush()
15+
16+
17+
if __name__ == '__main__':
18+
example()
Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
from questdb.ingress import Sender, Buffer, TimestampNanos
1+
from questdb.ingress import Sender, TimestampNanos
22

3-
if __name__ == '__main__':
3+
4+
def example():
45
with Sender('localhost', 9009) as sender:
56
buffer = sender.new_buffer()
67
buffer.row(
78
'line_sender_buffer_example',
89
symbols={'id': 'Hola'},
9-
columns={'price': '111222233333i', 'qty': 3.5},
10-
at=TimestampNanos(111222233333)
11-
)
10+
columns={'price': 111222233333, 'qty': 3.5},
11+
at=TimestampNanos(111222233333))
1212
buffer.row(
1313
'line_sender_example',
1414
symbols={'id': 'Adios'},
15-
columns={'price': '111222233343i', 'qty': 2.5},
16-
at=TimestampNanos(111222233343)
17-
)
18-
# last line is not flushed
15+
columns={'price': 111222233343, 'qty': 2.5},
16+
at=TimestampNanos(111222233343))
1917
sender.flush(buffer)
18+
19+
20+
if __name__ == '__main__':
21+
example()

examples/line_sender_example.py

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

0 commit comments

Comments
 (0)