-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic_example.py
More file actions
74 lines (62 loc) · 2.44 KB
/
basic_example.py
File metadata and controls
74 lines (62 loc) · 2.44 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
#!/usr/bin/env python3
"""
Basic example of using the Replicated Python SDK.
This script initializes the replicated package, creates a customer and instance.
"""
import argparse
from replicated import ReplicatedClient
def main():
parser = argparse.ArgumentParser(description="Basic Replicated SDK example")
parser.add_argument(
"--base-url",
default="https://replicated.app",
help="Base URL for the Replicated API (default: https://replicated.app)",
)
parser.add_argument(
"--publishable-key",
required=True,
help="Your Replicated publishable key (required)",
)
parser.add_argument(
"--app-slug", required=True, help="Your application slug (required)"
)
parser.add_argument(
"--customer-email",
default="user@example.com",
help="Customer email address (default: user@example.com)",
)
parser.add_argument("--channel", help="Channel for the customer (optional)")
parser.add_argument("--customer-name", help="Customer name (optional)")
args = parser.parse_args()
print("Initializing Replicated client...")
print(f"Base URL: {args.base_url}")
print(f"App Slug: {args.app_slug}")
# Initialize the client
with ReplicatedClient(
publishable_key=args.publishable_key,
app_slug=args.app_slug,
base_url=args.base_url,
) as client:
print("✓ Replicated client initialized successfully")
# Create or get customer
channel_info = f" (channel: {args.channel})" if args.channel else ""
name_info = f" (name: {args.customer_name})" if args.customer_name else ""
print(
f"\nCreating/getting customer with email: "
f"{args.customer_email}{channel_info}{name_info}"
)
customer = client.customer.get_or_create(
email_address=args.customer_email,
channel=args.channel,
name=args.customer_name,
)
print(f"✓ Customer created/retrieved - ID: {customer.customer_id}")
# Create or get instance
print("\nCreating/getting instance for customer...")
instance = customer.get_or_create_instance()
print(f"✓ Instance created/retrieved - ID: {instance.instance_id}")
print("\n🎉 Basic example completed successfully!")
print(f"Customer ID: {customer.customer_id}")
print(f"Instance ID: {instance.instance_id}")
if __name__ == "__main__":
main()