-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync_example.py
More file actions
48 lines (37 loc) · 1.12 KB
/
async_example.py
File metadata and controls
48 lines (37 loc) · 1.12 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
"""
Async conversion example
"""
import asyncio
from conversiontools import ConversionToolsClient
async def main():
# Initialize client
client = ConversionToolsClient({
'api_token': 'your-api-token'
})
# Convert XML to Excel (async)
print("Converting XML to Excel (async)...")
await client.convert_async(
'convert.xml_to_excel',
'test.xml',
'result.xlsx'
)
print("Conversion complete! Result saved to result.xlsx")
# Advanced: Manual control with async
print("\nManual control example...")
# Upload file
file_id = await client.files.upload_async('data.json')
print(f"File uploaded: {file_id}")
# Create task
task = await client.create_task_async(
'convert.json_to_excel',
{'file_id': file_id}
)
print(f"Task created: {task.id}")
# Wait for completion
await task.wait_async()
print(f"Task completed with status: {task.status}")
# Download result
output_path = await task.download_to_async('result.xlsx')
print(f"Result downloaded to: {output_path}")
if __name__ == '__main__':
asyncio.run(main())