prisma-api 0.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- prisma_api/__init__.py +6 -0
- prisma_api/config.py +182 -0
- prisma_api/prisma_api.py +539 -0
- prisma_api/prisma_api_v2.py +1533 -0
- prisma_api-0.3.0.dist-info/METADATA +245 -0
- prisma_api-0.3.0.dist-info/RECORD +9 -0
- prisma_api-0.3.0.dist-info/WHEEL +5 -0
- prisma_api-0.3.0.dist-info/licenses/LICENSE +674 -0
- prisma_api-0.3.0.dist-info/top_level.txt +1 -0
prisma_api/__init__.py
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
__version__ = "0.3.0"
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
from prisma_api.prisma_api import prisma_api as init # Main prisma_api class for initialisation
|
|
5
|
+
from prisma_api.prisma_api_v2 import PrismaAPIv2 # v2 API client (also accessible as api.v2)
|
|
6
|
+
from prisma_api.config import update_dev_mode, update_dev_host_port, locate_config # Config utility functions
|
prisma_api/config.py
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import yaml
|
|
4
|
+
import platformdirs
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Helper functions for config management
|
|
9
|
+
|
|
10
|
+
# Internal function to get user config directory
|
|
11
|
+
def _user_config_dir() -> Path:
|
|
12
|
+
"""Return cross-platform user config directory Path."""
|
|
13
|
+
if platformdirs is not None:
|
|
14
|
+
return Path(platformdirs.user_config_dir("prisma_api", "prisma-api"))
|
|
15
|
+
return Path.home() / ".prisma_api"
|
|
16
|
+
|
|
17
|
+
# Internal function to get path to config.yaml
|
|
18
|
+
def get_config_path() -> Path:
|
|
19
|
+
"""Get the path to the config.yaml file (ensuring parent exists)."""
|
|
20
|
+
cfg_dir = _user_config_dir()
|
|
21
|
+
cfg_dir.mkdir(parents=True, exist_ok=True)
|
|
22
|
+
return cfg_dir / "config.yaml"
|
|
23
|
+
|
|
24
|
+
# Public function to get config.yaml path as string
|
|
25
|
+
def locate_config() -> str:
|
|
26
|
+
"""Return the config.yaml path as a string (ensuring parent exists)."""
|
|
27
|
+
return str(get_config_path())
|
|
28
|
+
|
|
29
|
+
# Internal function to load config from config.yaml
|
|
30
|
+
def load_config():
|
|
31
|
+
"""Load configuration from config.yaml if it exists; return dict or None."""
|
|
32
|
+
cfg_file = get_config_path()
|
|
33
|
+
if not cfg_file.exists():
|
|
34
|
+
return None
|
|
35
|
+
if yaml is None:
|
|
36
|
+
raise ImportError("PyYAML is required. Install with: pip install pyyaml")
|
|
37
|
+
with open(cfg_file, "r") as f:
|
|
38
|
+
cfg = yaml.safe_load(f) or {}
|
|
39
|
+
|
|
40
|
+
return cfg
|
|
41
|
+
|
|
42
|
+
# Internal function to create config.yaml
|
|
43
|
+
def create_config_file(api_key: str = None):
|
|
44
|
+
"""
|
|
45
|
+
Create config.yaml. If api_key is None, prompt via CLI.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
api_key: PrISMa API key.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
dict: The config that was written.
|
|
52
|
+
"""
|
|
53
|
+
if yaml is None:
|
|
54
|
+
raise ImportError("PyYAML is required. Install with: pip install pyyaml")
|
|
55
|
+
|
|
56
|
+
if not api_key:
|
|
57
|
+
val = input("Enter your PrISMa API key: ").strip()
|
|
58
|
+
api_key = val
|
|
59
|
+
|
|
60
|
+
cfg = {
|
|
61
|
+
"api_key": api_key,
|
|
62
|
+
"created": pd.Timestamp.now().isoformat(),
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
cfg_file = get_config_path()
|
|
66
|
+
with open(cfg_file, "w") as f:
|
|
67
|
+
yaml.safe_dump(cfg, f, sort_keys=False)
|
|
68
|
+
return cfg
|
|
69
|
+
|
|
70
|
+
# Get or create config - intended use by initialisation of main prisma_api class
|
|
71
|
+
def get_or_create_config():
|
|
72
|
+
"""Return existing config or create it interactively if missing."""
|
|
73
|
+
cfg = load_config()
|
|
74
|
+
if cfg is not None:
|
|
75
|
+
return cfg
|
|
76
|
+
return create_config_file()
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
# Update dev flag in config.yaml - functional tool for user
|
|
80
|
+
def update_dev_mode(dev: bool):
|
|
81
|
+
"""
|
|
82
|
+
Update the dev flag in config.yaml.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
dev: Boolean flag to enable/disable dev mode.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
dict: Updated config.
|
|
89
|
+
"""
|
|
90
|
+
if yaml is None:
|
|
91
|
+
raise ImportError("PyYAML is required. Install with: pip install pyyaml")
|
|
92
|
+
|
|
93
|
+
cfg = load_config()
|
|
94
|
+
if cfg is None:
|
|
95
|
+
cfg = {}
|
|
96
|
+
cfg["dev"] = dev
|
|
97
|
+
cfg["modified"] = pd.Timestamp.now().isoformat()
|
|
98
|
+
|
|
99
|
+
cfg_file = get_config_path()
|
|
100
|
+
with open(cfg_file, "w") as f:
|
|
101
|
+
yaml.safe_dump(cfg, f, sort_keys=False)
|
|
102
|
+
return cfg
|
|
103
|
+
|
|
104
|
+
# Update dev host in config.yaml - functional tool for user
|
|
105
|
+
def update_dev_host_port(dev_host_port: str):
|
|
106
|
+
"""
|
|
107
|
+
Update the dev host in config.yaml.
|
|
108
|
+
|
|
109
|
+
Args:
|
|
110
|
+
dev_host_port: Hostname or base URL for dev API.
|
|
111
|
+
|
|
112
|
+
Returns:
|
|
113
|
+
dict: Updated config.
|
|
114
|
+
"""
|
|
115
|
+
if yaml is None:
|
|
116
|
+
raise ImportError("PyYAML is required. Install with: pip install pyyaml")
|
|
117
|
+
|
|
118
|
+
cfg = load_config()
|
|
119
|
+
if cfg is None:
|
|
120
|
+
cfg = {}
|
|
121
|
+
|
|
122
|
+
cfg["dev_host_port"] = dev_host_port
|
|
123
|
+
cfg["modified"] = pd.Timestamp.now().isoformat()
|
|
124
|
+
|
|
125
|
+
cfg_file = get_config_path()
|
|
126
|
+
with open(cfg_file, "w") as f:
|
|
127
|
+
yaml.safe_dump(cfg, f, sort_keys=False)
|
|
128
|
+
return cfg
|
|
129
|
+
|
|
130
|
+
# Update API key in config.yaml - functional tool for user
|
|
131
|
+
def update_api_key(api_key: str):
|
|
132
|
+
"""
|
|
133
|
+
Update the API key in config.yaml.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
api_key: New PrISMa API key.
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
dict: Updated config.
|
|
140
|
+
"""
|
|
141
|
+
if yaml is None:
|
|
142
|
+
raise ImportError("PyYAML is required. Install with: pip install pyyaml")
|
|
143
|
+
|
|
144
|
+
cfg = load_config()
|
|
145
|
+
if cfg is None:
|
|
146
|
+
cfg = {}
|
|
147
|
+
|
|
148
|
+
cfg["api_key"] = api_key
|
|
149
|
+
cfg["modified"] = pd.Timestamp.now().isoformat()
|
|
150
|
+
|
|
151
|
+
cfg_file = get_config_path()
|
|
152
|
+
with open(cfg_file, "w") as f:
|
|
153
|
+
yaml.safe_dump(cfg, f, sort_keys=False)
|
|
154
|
+
return cfg
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
# Update API key in config.yaml - functional tool for user
|
|
158
|
+
def update_dev_api_key(dev_api_key: str):
|
|
159
|
+
"""
|
|
160
|
+
Update the API key in config.yaml.
|
|
161
|
+
|
|
162
|
+
Args:
|
|
163
|
+
dev_api_key: New PrISMa API key.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
dict: Updated config.
|
|
167
|
+
"""
|
|
168
|
+
if yaml is None:
|
|
169
|
+
raise ImportError("PyYAML is required. Install with: pip install pyyaml")
|
|
170
|
+
|
|
171
|
+
cfg = load_config()
|
|
172
|
+
if cfg is None:
|
|
173
|
+
cfg = {}
|
|
174
|
+
|
|
175
|
+
cfg["dev_api_key"] = dev_api_key
|
|
176
|
+
cfg["modified"] = pd.Timestamp.now().isoformat()
|
|
177
|
+
|
|
178
|
+
cfg_file = get_config_path()
|
|
179
|
+
with open(cfg_file, "w") as f:
|
|
180
|
+
yaml.safe_dump(cfg, f, sort_keys=False)
|
|
181
|
+
return cfg
|
|
182
|
+
|