-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.py
More file actions
87 lines (75 loc) · 3 KB
/
Copy pathquickstart.py
File metadata and controls
87 lines (75 loc) · 3 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
"""
Surmado Python SDK - Quick Start Example
Run this to test your API key and see the SDK in action.
Usage:
export SURMADO_API_KEY=sur_live_xxx
python examples/quickstart.py
"""
from surmado import Surmado, SurmadoError, InsufficientCreditsError
def main():
# Initialize client (reads SURMADO_API_KEY from env)
client = Surmado()
print("Surmado client initialized")
# Example 1: Test your API key (free, no credits used)
print("\n--- Testing API Key ---")
try:
auth = client.test_auth()
print(f"Authenticated as org: {auth.get('org_id')}")
except SurmadoError as e:
print(f"Auth failed: {e}")
return
# Example 2: Run a Scan report
print("\n--- Creating Scan Report ---")
try:
scan_result = client.scan(
url="https://example.com",
brand_name="Example Brand",
email="you@example.com", # Replace with your email
)
print(f"Scan report created: {scan_result['report_id']}")
print(f" Status: {scan_result['status']}")
print(f" Credits used: {scan_result['credits_used']}")
except InsufficientCreditsError:
print("Not enough credits. Top up at surmado.com")
return
except SurmadoError as e:
print(f"Error: {e}")
return
# Example 3: Run a Signal report
print("\n--- Creating Signal Report ---")
try:
signal_result = client.signal(
url="https://example.com",
brand_name="Example Brand",
email="you@example.com", # Replace with your email
industry="Technology",
location="United States",
persona="Developers and technical decision makers",
pain_points="Finding reliable tools, integration complexity",
brand_details="Developer-focused platform for building modern apps",
direct_competitors="Vercel, Netlify, Heroku",
)
print(f"Signal report created: {signal_result['report_id']}")
except InsufficientCreditsError:
print("Not enough credits for Signal report")
except SurmadoError as e:
print(f"Error: {e}")
# Example 4: Check report status
print("\n--- Checking Report Status ---")
report = client.get_report(scan_result["report_id"])
print(f"Report {report['report_id']}:")
print(f" Status: {report['status']}")
print(f" Product: {report['product']}")
# Example 5: Wait for completion (optional - takes ~15 min)
# Uncomment to wait for the report to complete:
#
# print("\n--- Waiting for Report ---")
# completed = client.wait_for_report(scan_result["report_id"])
# print(f"Report completed!")
# print(f" PDF: {completed.get('download_url', 'N/A')}")
# print(f" Token (for Solutions): {completed.get('token', 'N/A')}")
print("\nDone! Reports are processing (~15 min).")
print(" Check status: client.get_report(report_id)")
print(" Or add webhook_url to receive POST when complete.")
if __name__ == "__main__":
main()