forked from boxlite-ai/boxlite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse_env_config.py
More file actions
60 lines (45 loc) · 1.59 KB
/
Copy pathuse_env_config.py
File metadata and controls
60 lines (45 loc) · 1.59 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
#!/usr/bin/env python3
"""
Load REST connection config from environment variables.
Demonstrates:
- BoxliteRestOptions.from_env() for environment-based configuration
- API-key authentication via BOXLITE_API_KEY
- Useful for CI/CD pipelines and production deployments
Environment variables:
BOXLITE_REST_URL Server URL (required)
BOXLITE_API_KEY Long-lived API key
BOXLITE_REST_PREFIX API version prefix (default: v1)
Usage:
BOXLITE_REST_URL=http://localhost:8100 \
BOXLITE_API_KEY=your-api-key \
python use_env_config.py
Prerequisites:
make dev:python
boxlite serve --port 8100
"""
import asyncio
from boxlite import Boxlite, BoxliteRestOptions
async def main():
print("=" * 50)
print("REST API: Environment-Based Configuration")
print("=" * 50)
# Load connection config from environment variables. from_env() reads
# BOXLITE_REST_URL (required) and BOXLITE_API_KEY (wrapped in an
# ApiKeyCredential automatically when set).
try:
opts = BoxliteRestOptions.from_env()
except Exception as e:
print(f"\n Error: {e}")
print(" Set BOXLITE_REST_URL and BOXLITE_API_KEY:")
print(" BOXLITE_REST_URL=http://localhost:8100 \\")
print(" BOXLITE_API_KEY=your-api-key \\")
print(" python use_env_config.py")
return
print(f"\n Loaded config: {opts}")
rt = Boxlite.rest(opts)
# Quick smoke test: list boxes
boxes = await rt.list_info()
print(f" Boxes on server: {len(boxes)}")
print("\n Done")
if __name__ == "__main__":
asyncio.run(main())