Skip to content

Commit b88dfd7

Browse files
authored
docs(ilp): add ILP auth example (#17)
1 parent cf00547 commit b88dfd7

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

examples.manifest.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@
88
```
99
python3 -m pip install questdb
1010
```
11+
- name: ilp-auth
12+
lang: python
13+
path: examples/auth.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
1129
- name: ilp-auth-tls
1230
lang: python
1331
path: examples/auth_and_tls.py

examples/auth.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
from questdb.ingress import Sender, IngressError
2+
import sys
3+
import datetime
4+
5+
6+
def example(host: str = 'localhost', port: int = 9009):
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) 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 client 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')
51+
52+
53+
if __name__ == '__main__':
54+
example()

examples/auth_and_tls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def example(host: str = 'localhost', port: int = 9009):
4141
# or simply be left out.
4242

4343
# We recommend flushing periodically, for example every few seconds.
44-
# If you don't flush explicitly, the server will flush automatically
44+
# If you don't flush explicitly, the client will flush automatically
4545
# once the buffer is reaches 63KiB and just before the connection
4646
# is closed.
4747
sender.flush()

examples/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def example(host: str = 'localhost', port: int = 9009):
3535
# or simply be left out.
3636

3737
# We recommend flushing periodically, for example every few seconds.
38-
# If you don't flush explicitly, the server will flush automatically
38+
# If you don't flush explicitly, the client will flush automatically
3939
# once the buffer is reaches 63KiB and just before the connection
4040
# is closed.
4141
sender.flush()

0 commit comments

Comments
 (0)