prisma-api 0.3.0__tar.gz → 0.3.2__tar.gz

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.
@@ -0,0 +1,377 @@
1
+ Metadata-Version: 2.4
2
+ Name: prisma_api
3
+ Version: 0.3.2
4
+ Summary: A package for interacting with PrISMa Platform APIs. PrISMa is a holistic system for numerical synthesis and assessment of Metal-Organic Frameworks and their applications, for Direct Air Capture of CO2. For more information, see: https://prisma.hw.ac.uk.
5
+ Author-email: RCCS-CaptureTeam <team@prisma-platform.org>
6
+ License: GNUv3
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: numpy>=1.21.0
11
+ Requires-Dist: pandas>=1.3.0
12
+ Requires-Dist: pyyaml>=6.0
13
+ Requires-Dist: platformdirs>=2.5.0
14
+ Requires-Dist: requests>=2.27.0
15
+ Provides-Extra: dev
16
+ Requires-Dist: pytest>=8.0; extra == "dev"
17
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
18
+ Requires-Dist: responses>=0.25; extra == "dev"
19
+ Dynamic: license-file
20
+
21
+ # PrISMa API
22
+
23
+ Python client for the PrISMa platform APIs.
24
+
25
+ This package provides:
26
+
27
+ - legacy v1 wrappers on the main `api` object
28
+ - a larger v2 REST client on `api.v2`
29
+ - local config-based API-key management
30
+
31
+ PrISMa is a platform for numerical synthesis and assessment of metal-organic frameworks and related carbon-capture workflows.
32
+
33
+ ## Installation
34
+
35
+ ### From PyPI
36
+
37
+ ```bash
38
+ pip install prisma_api
39
+ ```
40
+
41
+ ### Requirements
42
+
43
+ - Python 3.10+
44
+ - Runtime dependencies are installed automatically from `pyproject.toml`
45
+
46
+ ## Authentication and configuration
47
+
48
+ The client uses an API key stored in a local config file.
49
+
50
+ ### First-time setup
51
+
52
+ ```python
53
+ import prisma_api
54
+
55
+ api = prisma_api.init()
56
+ ```
57
+
58
+ On first use, the package creates a config file and prompts for an API key.
59
+
60
+ ### Upgrades
61
+
62
+ ```python
63
+ pip install --upgrade prisma_api
64
+ ```
65
+
66
+ ### Find the config path
67
+
68
+ ```python
69
+ from prisma_api.config import locate_config
70
+
71
+ print(locate_config())
72
+ ```
73
+
74
+ Typical locations:
75
+
76
+ - macOS/Linux: `~/.config/prisma_api/config.yaml`
77
+ - Windows: `%APPDATA%/prisma-api/prisma_api/config.yaml`
78
+
79
+ ### Create or update the config programmatically
80
+
81
+ ```python
82
+ from prisma_api.config import create_config_file
83
+
84
+ create_config_file(api_key="YOUR_API_KEY_HERE")
85
+ ```
86
+
87
+ ### Environment-variable mode
88
+
89
+ If you do not want to use the config file:
90
+
91
+ ```bash
92
+ export PRISMA_API_KEY="YOUR_API_KEY_HERE"
93
+ export PRISMA_API_DEV="False"
94
+ ```
95
+
96
+ ```python
97
+ from prisma_api.prisma_api import prisma_api
98
+
99
+ api = prisma_api(use_config_file=False)
100
+ ```
101
+
102
+ ## Quick start
103
+
104
+ ```python
105
+ import prisma_api
106
+
107
+ api = prisma_api.init()
108
+
109
+ # v2 list endpoints return JSON by default in the main client
110
+ materials = api.v2.list_materials(name="ABEX")
111
+ print(materials[:2])
112
+
113
+ # switch list endpoints to pandas DataFrames if preferred
114
+ api.set_return_format("dataframe")
115
+ materials_df = api.v2.list_materials(name="ABEX")
116
+ print(materials_df.head())
117
+ ```
118
+
119
+ ### Flowsheets
120
+
121
+ ```python
122
+ import prisma_api
123
+
124
+ api = prisma_api.init()
125
+
126
+ flowsheet = api.v2.get_flowsheet(name="dac_min")
127
+ ```
128
+
129
+
130
+ ## Return formats
131
+
132
+ All v2 list endpoints support two formats:
133
+
134
+ - `json`: returns `list[dict]`
135
+ - `dataframe`: returns `pandas.DataFrame`
136
+
137
+ Detail endpoints always return `dict`.
138
+
139
+ ```python
140
+ api.set_return_format("json")
141
+ records = api.v2.get_molecules()
142
+
143
+ api.set_return_format("dataframe")
144
+ df = api.v2.get_molecules()
145
+ ```
146
+
147
+ ## Main objects
148
+
149
+ - `prisma_api.init()`
150
+ Returns the main client object.
151
+ - `api`
152
+ Legacy v1 wrappers plus configuration helpers.
153
+ - `api.v2`
154
+ `PrismaAPIv2` instance with the v2 REST surface.
155
+
156
+ ## v1 wrappers
157
+
158
+ The main client exposes these v1 methods:
159
+
160
+ - `get_mofs(payload={})`
161
+ - `get_carbon_isotherms(payload={})`
162
+ - `get_carbon_data_nested(payload={}, safe_names=False)`
163
+ - `get_materials_data(payload={}, separate_experimental=True)`
164
+ - `update_adsorption_singlepoint(df)`
165
+ - `update_heat_capacity_all_tidy(df)`
166
+ - `update_isotherm_h2(df)`
167
+ - `update_mofchecker(df)`
168
+ - `update_zeopp_metrics(df)`
169
+
170
+ Configuration helpers on the main client:
171
+
172
+ - `set_return_format(fmt)`
173
+ - `update_dev_mode(dev)`
174
+
175
+ Module-level helpers exported from the package:
176
+
177
+ - `prisma_api.init`
178
+ - `prisma_api.PrismaAPIv2`
179
+ - `prisma_api.update_dev_mode`
180
+ - `prisma_api.update_dev_host_port`
181
+ - `prisma_api.locate_config`
182
+
183
+ ## v2 wrapper list
184
+
185
+ All methods below are available on `api.v2`.
186
+
187
+ ### Health and flowsheets
188
+
189
+ - `health()`
190
+ - `get_flowsheet(name="dac_min")`
191
+
192
+ ### Materials and bundles
193
+
194
+ - `list_materials(name=None, limit=10000)`
195
+ - `get_material(material_id)`
196
+ - `get_materials_psdi(name=None, limit=500, offset=0)`
197
+ - `get_material_psdi(material_id)`
198
+ - `get_material_property_bundle(mof, sim_or_exp=None, good_structure=None, limit=500, offset=0, query=None)`
199
+ - `preflight_material_check(name)`
200
+
201
+ ### Case bundles and pack builders
202
+
203
+ - `get_cases_bundle(name=None, source=None, sink=None, region=None, limit_cases=100, limit_props=2000)`
204
+ - `build_case_spec(case_id)`
205
+ - `build_scenario_spec(scenario_id)`
206
+ - `build_case_pack(case_id, scenario_id=None)`
207
+ - `list_case_packs(source=None, sink=None, region=None, study=None, include_scenarios=False, limit=100, offset=0)`
208
+
209
+ ### Catalog and reference data
210
+
211
+ - `get_molecules(name=None, limit=500, offset=0)`
212
+ - `get_molecule(molecule_id)`
213
+ - `get_elements(symbol=None, name=None, limit=500, offset=0)`
214
+ - `get_element(element_id)`
215
+ - `get_regions(code=None, name=None, limit=500, offset=0)`
216
+ - `get_region(region_id)`
217
+ - `get_sources(name=None, limit=500, offset=0)`
218
+ - `get_source(source_id)`
219
+ - `get_sinks(name=None, limit=500, offset=0)`
220
+ - `get_sink(sink_id)`
221
+ - `get_transport_scenarios(name=None, limit=500, offset=0)`
222
+ - `get_transport_scenario(ts_id)`
223
+ - `get_utilities(name=None, limit=500, offset=0)`
224
+ - `get_utility(utility_id)`
225
+ - `get_references(name=None, doi=None, limit=500, offset=0)`
226
+ - `get_reference(ref_id)`
227
+ - `get_transports(name=None, limit=500, offset=0)`
228
+ - `get_transport(transport_id)`
229
+ - `get_subsystems(name=None, type=None, limit=500, offset=0)`
230
+ - `get_subsystem(subsystem_id)`
231
+ - `get_properties(name=None, domain=None, category=None, object_id=None, limit=500, offset=0)`
232
+ - `get_property(property_id)`
233
+ - `get_equipment(name=None, group=None, limit=500, offset=0)`
234
+ - `get_equipment_item(equipment_id)`
235
+ - `get_equipment_costs(equipment_id=None, limit=500, offset=0)`
236
+ - `get_equipment_cost(cost_id)`
237
+ - `get_equipment_designs(equipment_id=None, key=None, limit=500, offset=0)`
238
+ - `get_equipment_design(design_id)`
239
+ - `get_process_conditions(name=None, type=None, limit=500, offset=0)`
240
+ - `get_process_condition(condition_id)`
241
+ - `get_process_configurations(name=None, type=None, limit=500, offset=0)`
242
+ - `get_process_configuration(config_id)`
243
+ - `get_contactor_configurations(name=None, type=None, limit=500, offset=0)`
244
+ - `get_contactor_configuration(config_id)`
245
+ - `get_cost_indices(year=None, limit=500, offset=0)`
246
+ - `get_cost_index(index_id)`
247
+ - `get_constants(param=None, limit=500, offset=0)`
248
+ - `get_constant(constant_id)`
249
+ - `get_mea_baselines(name=None, limit=500, offset=0)`
250
+ - `get_mea_baseline(mea_id)`
251
+ - `get_mea_kpis(name=None, category=None, limit=500, offset=0)`
252
+ - `get_mea_kpi(kpi_id)`
253
+
254
+ ### Science data
255
+
256
+ - `get_isotherm(mof=None, molecule=None, temperature_min=None, temperature_max=None, sim_or_exp=None, good_structure=None, limit=500, offset=0)`
257
+ - `get_water_kpis(mof=None, molecule=None, source=None, sim_or_exp=None, good_structure=None, limit=500, offset=0)`
258
+ - `get_carbon_zeopp(mof=None, good_structure=None, limit=500, offset=0)`
259
+ - `get_carbon_zeopp_item(item_id)`
260
+ - `get_carbon_zeopp_experimental(mof=None, limit=500, offset=0)`
261
+ - `get_carbon_zeopp_experimental_item(item_id)`
262
+
263
+ ### TEA, LCA, cases, and scenarios
264
+
265
+ - `get_output_kpis(scenario_id=None, mof=None, good_structure=None, limit=500, offset=0)`
266
+ - `get_output_kpi(kpi_id)`
267
+ - `upsert_output_kpis(df)`
268
+ - `get_region_costs(region=None, name=None, year=None, limit=500, offset=0)`
269
+ - `get_region_cost(rc_id)`
270
+ - `upsert_region_costs(df)`
271
+ - `get_ambient_parameters(name=None, limit=500, offset=0)`
272
+ - `get_ambient_parameter(ap_id)`
273
+ - `upsert_ambient_parameters(df)`
274
+ - `get_cases(source=None, sink=None, region=None, study=None, limit=500, offset=0)`
275
+ - `get_case(case_id)`
276
+ - `get_scenarios(case_id=None, name=None, type=None, limit=500, offset=0)`
277
+ - `get_scenario(scenario_id)`
278
+ - `get_screening_summaries(scenario_id=None, limit=500, offset=0)`
279
+ - `get_screening_summary(summary_id)`
280
+
281
+ ## Examples
282
+
283
+ ### Materials
284
+
285
+ ```python
286
+ import prisma_api
287
+
288
+ api = prisma_api.init()
289
+
290
+ materials = api.v2.list_materials(name="ABEX")
291
+ first = materials[0]
292
+ detail = api.v2.get_material(first["id"])
293
+ ```
294
+
295
+ ### PSDI detail
296
+
297
+ ```python
298
+ psdi = api.v2.get_materials_psdi(name="Lewatit")
299
+ first_psdi = psdi[0]
300
+ record = api.v2.get_material_psdi(first_psdi["id"])
301
+ ```
302
+
303
+ ### Flowsheet retrieval
304
+
305
+ ```python
306
+ flowsheet = api.v2.get_flowsheet(name="dac_min")
307
+ print(flowsheet["template_id"])
308
+ ```
309
+
310
+ ### Advanced property-bundle query
311
+
312
+ `get_material_property_bundle` supports a generic query dictionary for more complex endpoint-specific filtering.
313
+
314
+ Supported keys are:
315
+
316
+ - `common`
317
+ - `materials`
318
+ - `isotherms`
319
+ - `zeopp_simulated`
320
+ - `zeopp_experimental`
321
+ - `water_kpis`
322
+
323
+ Merge precedence is:
324
+
325
+ - defaults
326
+ - `common`
327
+ - endpoint-specific filters
328
+
329
+ ```python
330
+ bundle = api.v2.get_material_property_bundle(
331
+ "HKUST",
332
+ good_structure=True,
333
+ query={
334
+ "common": {"limit": 50},
335
+ "materials": {"limit": 20},
336
+ "isotherms": {
337
+ "molecule": "CO2",
338
+ "temperature_min": 273,
339
+ "temperature_max": 350,
340
+ },
341
+ "water_kpis": {"source": "DAC"},
342
+ },
343
+ )
344
+
345
+ print(bundle.keys())
346
+ ```
347
+
348
+ ### Cases and scenarios
349
+
350
+ ```python
351
+ cases = api.v2.get_cases(region="GB", limit=10)
352
+ case_id = cases[0]["id"]
353
+
354
+ case_detail = api.v2.get_case(case_id)
355
+ scenario_list = api.v2.get_scenarios(case_id=case_id)
356
+ case_pack = api.v2.build_case_pack(case_id)
357
+ ```
358
+
359
+ ## Testing
360
+
361
+ Run the test suite with:
362
+
363
+ ```bash
364
+ pytest tests/ -v --cov=prisma_api --cov-report=term-missing
365
+ ```
366
+
367
+ ## Additional documentation
368
+
369
+ - [API_REFERENCE.md](API_REFERENCE.md)
370
+ - [DEVELOPMENT_SUMMARY.md](DEVELOPMENT_SUMMARY.md)
371
+ - [User Guide.md](User%20Guide.md)
372
+
373
+ ## Notes
374
+
375
+ - Production v2 base URL: `https://prisma-platform.org/api/v2`
376
+ - Authentication header: `X-API-Key`
377
+ - Local development routing is controlled through config and `api.update_dev_mode(True)`