Skip to content

Commit d4b1df6

Browse files
authored
Merge pull request #293 from digital-asset/python-docs-fixes
python: Documentation fixes.
2 parents 03f9e44 + 4a30123 commit d4b1df6

File tree

2 files changed

+58
-23
lines changed

2 files changed

+58
-23
lines changed

docs/index.rst

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,43 @@
44
dazl: DA client library for Python
55
==================================
66

7-
*Version: |release|*
7+
Version |release|
88

99
Dependencies
1010
------------
1111

1212
You will need Python 3.6 or later and a Daml Ledger.
1313

14-
1514
Getting Started
1615
---------------
1716

1817
This section assumes that you already have a running ledger with the standard `daml new` model
1918
loaded, and have imported `dazl`.
2019

21-
Connect to the ledger and submit a single command::
22-
23-
import dazl
24-
25-
async with dazl.connect(url='http://localhost:6865', act_as='Alice') as conn:
26-
await conn.create('Main:Asset', {'issuer': 'Alice', 'owner': 'Alice', 'name': 'hello world!'})
20+
Connect to the ledger and submit a single command:
2721

28-
Connect to the ledger as a single party, print all contracts, and close::
22+
.. literalinclude:: ../python/tests/unit/test_docs.py
23+
:language: python
24+
:pyobject: test_send_single_command
25+
:lines: 2-
26+
:dedent: 4
2927

30-
import dazl
28+
Connect to the ledger as a single party, print all contracts, and close:
3129

32-
async with dazl.connect(url='http://localhost:6865', read_as='Alice') as conn:
33-
contracts = {}
34-
async for event in conn.query():
35-
contracts[event.cid] = event.cdata
36-
print(contracts)
30+
.. literalinclude:: ../python/tests/unit/test_docs.py
31+
:language: python
32+
:pyobject: test_read
33+
:lines: 2-
34+
:dedent: 4
3735

38-
Connect to the ledger using asynchronous callbacks::
36+
Connect to the ledger using asynchronous callbacks:
3937

40-
import dazl
38+
.. literalinclude:: ../python/tests/unit/test_docs.py
39+
:language: python
40+
:pyobject: test_read_using_callback
41+
:lines: 2-
42+
:dedent: 4
4143

42-
async with dazl.connect(url='http://localhost:6865', read_as='Alice') as conn:
43-
contracts = {}
44-
@conn.on_create
45-
def _(event):
46-
contracts[event.cid] = event.cdata
47-
print(contracts)
4844

4945
Code
5046
----

python/tests/unit/test_docs.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (c) 2017-2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Note: These tests are not currently run since they hardcode URLs for documentation purposes.
5+
# But at the very least, they _are_ typechecked.
6+
7+
8+
async def test_send_single_command() -> None:
9+
import dazl
10+
11+
async with dazl.connect(url="http://localhost:6865", act_as=dazl.Party("Alice")) as conn:
12+
payload = {"issuer": "Alice", "owner": "Alice", "name": "hello world!"}
13+
await conn.create("Main:Asset", payload)
14+
15+
16+
async def test_read() -> None:
17+
import dazl
18+
19+
async with dazl.connect(url="http://localhost:6865", read_as=dazl.Party("Alice")) as conn:
20+
contracts = {}
21+
async with conn.query("Main:Asset") as stream:
22+
async for event in stream.creates():
23+
contracts[event.contract_id] = event.payload
24+
print(contracts)
25+
26+
27+
async def test_read_using_callback() -> None:
28+
import dazl
29+
30+
async with dazl.connect(url="http://localhost:6865", read_as=dazl.Party("Alice")) as conn:
31+
contracts = {}
32+
async with conn.query("Main:Asset") as stream:
33+
34+
@stream.on_create
35+
def _(event):
36+
contracts[event.contract_id] = event.payload
37+
38+
await stream.run()
39+
print(contracts)

0 commit comments

Comments
 (0)