Skip to content

Commit 42f6984

Browse files
authored
Examples manifest (#12)
* chore: Added examples manifest file. * chore: Added 'addr' section to example. * docs: Example improvements.
1 parent 0c2ae2c commit 42f6984

File tree

3 files changed

+116
-28
lines changed

3 files changed

+116
-28
lines changed

examples.manifest.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
- name: ilp
2+
lang: python
3+
path: examples/basic.py
4+
header: |-
5+
Python client library [docs](https://py-questdb-client.readthedocs.io/en/latest/)
6+
and [repo](https://github.com/questdb/py-questdb-client).
7+
8+
```
9+
python3 -m pip install questdb
10+
```
11+
- name: ilp-auth-tls
12+
lang: python
13+
path: examples/auth_and_tls.py
14+
header: |-
15+
Python client library [docs](https://py-questdb-client.readthedocs.io/en/latest/)
16+
and [repo](https://github.com/questdb/py-questdb-client).
17+
18+
```
19+
python3 -m pip install questdb
20+
```
21+
auth:
22+
kid: testUser1
23+
d: 5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48
24+
x: fLKYEaoEb9lrn3nkwLDA-M_xnuFOdSt9y0Z7_vWSHLU
25+
y: Dt5tbS1dEDMSYfym3fgMv0B99szno-dFc1rYF9t0aac
26+
addr:
27+
host: localhost
28+
port: 9009

examples/auth_and_tls.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,53 @@
1-
from questdb.ingress import Sender
1+
from questdb.ingress import Sender, IngressError
2+
import sys
3+
import datetime
24

35

46
def example(host: str = 'localhost', port: int = 9009):
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(host, port, 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()
7+
try:
8+
# See: https://questdb.io/docs/reference/api/ilp/authenticate
9+
auth = (
10+
"testUser1", # kid
11+
"5UjEMuA0Pj5pjK8a-fa24dyIf-Es5mYny3oE_Wmus48", # d
12+
"fLKYEaoEb9lrn3nkwLDA-M_xnuFOdSt9y0Z7_vWSHLU", # x
13+
"Dt5tbS1dEDMSYfym3fgMv0B99szno-dFc1rYF9t0aac") # y
14+
with Sender(host, port, auth=auth, tls=True) as sender:
15+
# Record with provided designated timestamp (using the 'at' param)
16+
# Notice the designated timestamp is expected in Nanoseconds,
17+
# but timestamps in other columns are expected in Microseconds.
18+
# The API provides convenient functions
19+
sender.row(
20+
'trades',
21+
symbols={
22+
'pair': 'USDGBP',
23+
'type': 'buy'},
24+
columns={
25+
'traded_price': 0.83,
26+
'limit_price': 0.84,
27+
'qty': 100,
28+
'traded_ts': datetime.datetime(
29+
2022, 8, 6, 7, 35, 23, 189062,
30+
tzinfo=datetime.timezone.utc)},
31+
at=datetime.datetime.utcnow())
32+
33+
# If no 'at' param is passed, the server will use its own timestamp.
34+
sender.row(
35+
'trades',
36+
symbols={'pair': 'EURJPY'},
37+
columns={
38+
'traded_price': 135.97,
39+
'qty': 400,
40+
'limit_price': None}) # NULL columns can be passed as None,
41+
# or simply be left out.
42+
43+
# We recommend flushing periodically, for example every few seconds.
44+
# If you don't flush explicitly, the server will flush automatically
45+
# once the buffer is reaches 63KiB and just before the connection
46+
# is closed.
47+
sender.flush()
48+
49+
except IngressError as e:
50+
sys.stderr.write(f'Got error: {e}\n')
2151

2252

2353
if __name__ == '__main__':

examples/basic.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,47 @@
1-
from questdb.ingress import Sender
1+
from questdb.ingress import Sender, IngressError
2+
import sys
3+
import datetime
24

35

46
def example(host: str = 'localhost', port: int = 9009):
5-
with Sender(host, port) 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()
7+
try:
8+
with Sender(host, port) as sender:
9+
# Record with provided designated timestamp (using the 'at' param)
10+
# Notice the designated timestamp is expected in Nanoseconds,
11+
# but timestamps in other columns are expected in Microseconds.
12+
# The API provides convenient functions
13+
sender.row(
14+
'trades',
15+
symbols={
16+
'pair': 'USDGBP',
17+
'type': 'buy'},
18+
columns={
19+
'traded_price': 0.83,
20+
'limit_price': 0.84,
21+
'qty': 100,
22+
'traded_ts': datetime.datetime(
23+
2022, 8, 6, 7, 35, 23, 189062,
24+
tzinfo=datetime.timezone.utc)},
25+
at=datetime.datetime.utcnow())
26+
27+
# If no 'at' param is passed, the server will use its own timestamp.
28+
sender.row(
29+
'trades',
30+
symbols={'pair': 'EURJPY'},
31+
columns={
32+
'traded_price': 135.97,
33+
'qty': 400,
34+
'limit_price': None}) # NULL columns can be passed as None,
35+
# or simply be left out.
36+
37+
# We recommend flushing periodically, for example every few seconds.
38+
# If you don't flush explicitly, the server will flush automatically
39+
# once the buffer is reaches 63KiB and just before the connection
40+
# is closed.
41+
sender.flush()
42+
43+
except IngressError as e:
44+
sys.stderr.write(f'Got error: {e}\n')
1545

1646

1747
if __name__ == '__main__':

0 commit comments

Comments
 (0)