-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathasync_example.py
More file actions
50 lines (37 loc) · 1.59 KB
/
async_example.py
File metadata and controls
50 lines (37 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Basic async usage example for the Dataverse SDK."""
import asyncio
# Use an async Azure Identity credential
# Install: pip install azure-identity
from azure.identity.aio import InteractiveBrowserCredential
from PowerPlatform.Dataverse.async_client import AsyncDataverseClient
async def main() -> None:
credential = InteractiveBrowserCredential()
async with AsyncDataverseClient("https://org.crm.dynamics.com", credential) as client:
# Create a single record
guid = await client.records.create("account", {"name": "Contoso"})
print(f"[OK] Created account: {guid}")
# Fetch the record back
record = await client.records.get("account", guid, select=["name"])
print(f"[OK] Name: {record['name']}")
# Update the record
await client.records.update("account", guid, {"telephone1": "555-0100"})
print("[OK] Updated telephone")
# Delete the record
await client.records.delete("account", guid)
print("[OK] Deleted account")
# SQL query (async)
rows = await client.query.sql("SELECT TOP 5 name FROM account ORDER BY name")
for row in rows:
print(f" account: {row['name']}")
# Multi-record fetch with async pagination
print("[INFO] Paging through active accounts:")
async for page in await client.records.get(
"account",
filter="statecode eq 0",
select=["name"],
page_size=20,
):
for rec in page:
print(f" {rec['name']}")
if __name__ == "__main__":
asyncio.run(main())