Skip to content

Commit 49ae9f3

Browse files
author
divyabhushan
committed
close scanner
1 parent b17e535 commit 49ae9f3

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

products/ai-runtime-security/api/pythonsdkasynciousage.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ ai_profile = AiProfile(profile_name=AI_PROFILE_NAME)
4545
# Create a Scanner
4646
scanner = Scanner()
4747

48-
4948
async def main():
5049
scan_response = await scanner.sync_scan(
5150
ai_profile=ai_profile,
@@ -93,7 +92,7 @@ if __name__ == "__main__":
9392

9493
</details>
9594

96-
## Asyncio async scan
95+
## Asyncio Async Scan
9796

9897
The following asyncio Python code snippet runs an asynchronous scan with prompts for different threat detections. Ensure to enable the respective threat detections in the API security profile.
9998

@@ -185,7 +184,6 @@ async def main():
185184
# Important: close the connection pool after use to avoid leaking threads
186185
await scanner.close()
187186

188-
189187
if __name__ == "__main__":
190188
asyncio.run(main())
191189
```
@@ -322,7 +320,6 @@ aisecurity.init()
322320

323321
scanner = Scanner()
324322

325-
326323
async def main():
327324
# See API documentation for response structur
328325
# https://pan.dev/ai-runtime-security/api/get-threat-scan-reports/

products/ai-runtime-security/api/pythonsdkusage.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,25 +28,20 @@ from pprint import pprint
2828
import json
2929
import aisecurity
3030

31-
3231
from aisecurity.generated_openapi_client.models.ai_profile import AiProfile
3332
# IMPORTANT: For traditional (non-asyncio), import Scanner from aisecurity.scan.inline.scanner
3433
from aisecurity.scan.inline.scanner import Scanner
3534
from aisecurity.scan.models.content import Content
3635

37-
3836
AI_PROFILE_NAME = "ai-sec-security"
3937
API_KEY = os.getenv("PANW_AI_SEC_API_KEY")
4038

41-
4239
# Initialize the SDK with your API Key
4340
aisecurity.init(api_key=API_KEY)
4441

45-
4642
# Configure an AI Profile
4743
ai_profile = AiProfile(profile_name=AI_PROFILE_NAME)
4844

49-
5045
# Create a Scanner
5146
scanner = Scanner()
5247
scan_response = scanner.sync_scan(
@@ -60,6 +55,7 @@ scan_response = scanner.sync_scan(
6055
# https://pan.dev/ai-runtime-security/api/scan-sync-request/
6156
# Convert the scan_response to a dictionary and then to a JSON string
6257
print(json.dumps(scan_response.to_dict()))
58+
await scanner.close()
6359
```
6460

6561
</details>
@@ -184,6 +180,7 @@ pprint({
184180
"scan_id": response.scan_id,
185181
"report_id": response.report_id,
186182
})
183+
await scanner.close()
187184
```
188185

189186
</details>
@@ -221,6 +218,7 @@ scanner = Scanner()
221218
example_scan_id = "00000000-0000-0000-0000-000000000000" # Replace with actual scan ID from the async_scan output.
222219
scan_by_ids_response = scanner.query_by_scan_ids(scan_ids=[example_scan_id])
223220
print(scan_by_ids_response)
221+
await scanner.close()
224222
```
225223

226224
</details>
@@ -330,6 +328,7 @@ scanner = Scanner()
330328
example_report_id = "R" + "YOUR_REPORT_ID" # Replace it with your actual report ID from the scan result. Its a UUID and starts with a letter R.
331329
threat_scan_reports = scanner.query_by_report_ids(report_ids=[example_report_id])
332330
print(threat_scan_reports)
331+
await scanner.close()
333332
```
334333

335334
</details>

0 commit comments

Comments
 (0)