-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathasync_event_example.py
More file actions
51 lines (38 loc) · 1.35 KB
/
Copy pathasync_event_example.py
File metadata and controls
51 lines (38 loc) · 1.35 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
#!/usr/bin/env python3
"""
FlexPrice Python SDK example – async client, ingest events.
Default base URL: https://us.api.flexprice.io/v1
Override with FLEXPRICE_API_HOST (full URL). Set FLEXPRICE_API_KEY in .env or environment.
"""
import asyncio
import logging
import os
from dotenv import load_dotenv
load_dotenv()
from flexprice import Flexprice
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)
async def main():
api_key = os.getenv("FLEXPRICE_API_KEY")
server_url = os.getenv(
"FLEXPRICE_API_HOST", "https://us.api.flexprice.io/v1"
)
if not api_key:
raise SystemExit("Set FLEXPRICE_API_KEY in .env or environment")
logger.info("Using async FlexPrice client")
async with Flexprice(
server_url=server_url,
api_key_auth=api_key,
) as flexprice:
result = await flexprice.events.ingest_event_async(
request={
"event_name": "Sample Event",
"external_customer_id": "customer-async-123",
"properties": {"source": "python_async", "environment": "test"},
"source": "python_async",
}
)
logger.info("Event ingested: %s", result)
logger.info("Async example complete!")
if __name__ == "__main__":
asyncio.run(main())