openlca-ipc 0.1.0__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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ernest Boakye Danquah
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,480 @@
1
+ Metadata-Version: 2.4
2
+ Name: openlca-ipc
3
+ Version: 0.1.0
4
+ Summary: A Python library for interacting with openLCA desktop application through the IPC protocol for life cycle assessment (LCA) workflows.
5
+ Home-page: https://github.com/dernestbank/openlca-ipc
6
+ Author: Ernest Boakye Danquah
7
+ Author-email: Ernest Boakye Danquah <dernestbanksch@gmail.com>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/dernestbank/openlca-ipc
10
+ Project-URL: Documentation, https://github.com/dernestbank/openlca-ipc/tree/main/docs
11
+ Project-URL: Repository, https://github.com/dernestbank/openlca-ipc
12
+ Project-URL: Issues, https://github.com/dernestbank/openlca-ipc/issues
13
+ Keywords: openlca,lca,life-cycle-assessment,ipc,environmental-impact,iso-14040,iso-14044
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Topic :: Scientific/Engineering
17
+ Classifier: License :: OSI Approved :: MIT License
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: olca-ipc>=2.4.0
27
+ Requires-Dist: olca-schema>=2.4.0
28
+ Requires-Dist: numpy>=1.24.0
29
+ Provides-Extra: full
30
+ Requires-Dist: matplotlib>=3.7.0; extra == "full"
31
+ Requires-Dist: pandas>=2.0.0; extra == "full"
32
+ Requires-Dist: scipy>=1.10.0; extra == "full"
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
35
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
36
+ Requires-Dist: black>=23.0.0; extra == "dev"
37
+ Requires-Dist: flake8>=6.0.0; extra == "dev"
38
+ Requires-Dist: mypy>=1.0.0; extra == "dev"
39
+ Provides-Extra: viz
40
+ Requires-Dist: matplotlib>=3.7.0; extra == "viz"
41
+ Requires-Dist: seaborn>=0.12.0; extra == "viz"
42
+ Provides-Extra: export
43
+ Requires-Dist: pandas>=2.0.0; extra == "export"
44
+ Requires-Dist: openpyxl>=3.1.0; extra == "export"
45
+ Dynamic: author
46
+ Dynamic: home-page
47
+ Dynamic: license-file
48
+ Dynamic: requires-python
49
+
50
+ # openLCA IPC Python Library
51
+
52
+ A comprehensive Python library for interacting with openLCA desktop application through the IPC (Inter-Process Communication) protocol. Built for life cycle assessment (LCA) workflows based on ISO-14040/14044 standards.
53
+
54
+ [![Python Version](https://img.shields.io/badge/python-3.10%2B-blue.svg)](https://www.python.org/downloads/)
55
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
56
+ [![openLCA](https://img.shields.io/badge/openLCA-2.x-orange.svg)](https://www.openlca.org/)
57
+
58
+ ## Features
59
+
60
+ - **Simple, Pythonic API** - High-level utilities that abstract complex IPC operations
61
+ - **Comprehensive LCA Workflow** - Search, create, calculate, and analyze in one package
62
+ - **Contribution Analysis** - Identify key contributors to environmental impacts
63
+ - **Uncertainty Analysis** - Monte Carlo simulations with statistical summaries
64
+ - **Scenario Analysis** - Parameter sensitivity and scenario comparison
65
+ - **Export Utilities** - CSV and Excel export for results
66
+ - **AI Agent Friendly** - Clear documentation and structured outputs for automation
67
+ - **ISO Compliant** - Follows ISO-14040/14044 LCA standards
68
+
69
+ ## Installation
70
+
71
+ ### Prerequisites
72
+
73
+ - Python 3.10 or higher
74
+ - openLCA desktop application (version 2.x)
75
+ - openLCA IPC server running (Tools → Developer Tools → IPC Server)
76
+
77
+ ### Install from PyPI (Coming Soon)
78
+
79
+ ```bash
80
+ pip install openlca-ipc
81
+ ```
82
+
83
+ ### Install from Source
84
+
85
+ ```bash
86
+ # Clone the repository
87
+ git clone https://github.com/dernestbank/openlca-ipc.git
88
+ cd openlca-ipc
89
+
90
+ # Install in editable mode
91
+ pip install -e .
92
+
93
+ # Or install with optional dependencies
94
+ pip install -e ".[full]"
95
+ ```
96
+
97
+ ### Install Dependencies
98
+
99
+ ```bash
100
+ # Core dependencies only
101
+ pip install -r requirements.txt
102
+
103
+ # Development dependencies
104
+ pip install -r requirements-dev.txt
105
+ ```
106
+
107
+ ## Quick Start
108
+
109
+ ### 1. Start openLCA IPC Server
110
+
111
+ Before using the library, start the IPC server in openLCA:
112
+
113
+ 1. Open openLCA desktop application
114
+ 2. Go to **Tools → Developer Tools → IPC Server**
115
+ 3. Click **Start** (default port: 8080)
116
+
117
+ ### 2. Basic Usage
118
+
119
+ ```python
120
+ from openlca_ipc import OLCAClient
121
+
122
+ # Connect to openLCA
123
+ with OLCAClient(port=8080) as client:
124
+ # Test connection
125
+ if client.test_connection():
126
+ print("Connected to openLCA!")
127
+
128
+ # Search for a material
129
+ steel_flow = client.search.find_flow(['steel', 'production'])
130
+ print(f"Found: {steel_flow.name}")
131
+
132
+ # Find provider process
133
+ provider = client.search.find_best_provider(steel_flow)
134
+ print(f"Provider: {provider.name if provider else 'None'}")
135
+ ```
136
+
137
+ ## Usage Examples
138
+
139
+ ### Example 1: Complete LCA Workflow
140
+
141
+ ```python
142
+ from openlca_ipc import OLCAClient
143
+
144
+ with OLCAClient(port=8080) as client:
145
+ # 1. Search for materials
146
+ steel = client.search.find_flow(['steel'])
147
+ steel_provider = client.search.find_best_provider(steel)
148
+
149
+ # 2. Create a new process
150
+ product = client.data.create_product_flow("Steel plate")
151
+ exchanges = [
152
+ client.data.create_exchange(product, 1.0, is_input=False, is_quantitative_reference=True),
153
+ client.data.create_exchange(steel, 1.0, is_input=True, provider=steel_provider)
154
+ ]
155
+ process = client.data.create_process("Plate production", exchanges=exchanges)
156
+
157
+ # 3. Create product system
158
+ system = client.systems.create_product_system(process)
159
+
160
+ # 4. Select impact method
161
+ method = client.search.find_impact_method(['TRACI'])
162
+
163
+ # 5. Calculate impacts
164
+ result = client.calculate.simple_calculation(system, method)
165
+
166
+ # 6. Get results
167
+ impacts = client.results.get_total_impacts(result)
168
+ for impact in impacts:
169
+ print(f"{impact['name']}: {impact['amount']:.4e} {impact['unit']}")
170
+
171
+ # 7. Clean up
172
+ result.dispose()
173
+ ```
174
+
175
+ ### Example 2: Contribution Analysis
176
+
177
+ ```python
178
+ from openlca_ipc import OLCAClient
179
+
180
+ client = OLCAClient(port=8080)
181
+
182
+ # Run calculation with contribution analysis
183
+ result = client.calculate.contribution_analysis(system, method)
184
+
185
+ # Get all impacts
186
+ impacts = client.results.get_total_impacts(result)
187
+
188
+ # Analyze top contributors for each impact
189
+ for impact in impacts:
190
+ print(f"\n{impact['name']}:")
191
+
192
+ # Get top 5 contributors
193
+ contributors = client.contributions.get_top_contributors(
194
+ result,
195
+ impact['category'],
196
+ n=5,
197
+ min_share=0.01 # Minimum 1% contribution
198
+ )
199
+
200
+ for i, contrib in enumerate(contributors, 1):
201
+ print(f" {i}. {contrib.name}: {contrib.share*100:.1f}% ({contrib.amount:.4e})")
202
+
203
+ result.dispose()
204
+ ```
205
+
206
+ ### Example 3: Monte Carlo Uncertainty Analysis
207
+
208
+ ```python
209
+ from openlca_ipc import OLCAClient
210
+ import matplotlib.pyplot as plt
211
+
212
+ client = OLCAClient(port=8080)
213
+
214
+ # Run Monte Carlo simulation
215
+ results = client.uncertainty.run_monte_carlo(
216
+ system=my_system,
217
+ impact_method=traci_method,
218
+ iterations=1000,
219
+ progress_callback=lambda i, total: print(f"Progress: {i}/{total}")
220
+ )
221
+
222
+ # Analyze global warming potential
223
+ gwp_key = next(k for k in results.keys() if 'warming' in k.lower())
224
+ gwp_result = results[gwp_key]
225
+
226
+ print(f"Mean: {gwp_result.mean:.4e}")
227
+ print(f"Std Dev: {gwp_result.std:.4e}")
228
+ print(f"CV: {gwp_result.cv:.2%}")
229
+ print(f"95% CI: [{gwp_result.percentile_5:.4e}, {gwp_result.percentile_95:.4e}]")
230
+
231
+ # Plot distribution
232
+ plt.figure(figsize=(10, 6))
233
+ plt.hist(gwp_result.values, bins=50, edgecolor='black', alpha=0.7)
234
+ plt.axvline(gwp_result.mean, color='red', linestyle='--', label='Mean')
235
+ plt.xlabel('Global Warming Potential')
236
+ plt.ylabel('Frequency')
237
+ plt.title('Monte Carlo Simulation Results')
238
+ plt.legend()
239
+ plt.savefig('gwp_distribution.png')
240
+ ```
241
+
242
+ ### Example 4: Scenario Analysis
243
+
244
+ ```python
245
+ from openlca_ipc import OLCAClient
246
+ import pandas as pd
247
+
248
+ client = OLCAClient(port=8080)
249
+
250
+ # Analyze how transport distance affects impacts
251
+ scenarios = client.parameters.run_scenario_analysis(
252
+ system=transport_system,
253
+ impact_method=traci_method,
254
+ parameter_name='transport_distance',
255
+ values=[100, 200, 500, 1000, 2000, 5000]
256
+ )
257
+
258
+ # Create comparison DataFrame
259
+ data = []
260
+ for distance, impacts in scenarios.items():
261
+ row = {'Distance (km)': distance}
262
+ for impact in impacts:
263
+ row[impact['name']] = impact['amount']
264
+ data.append(row)
265
+
266
+ df = pd.DataFrame(data)
267
+ print(df)
268
+
269
+ # Export to CSV
270
+ client.export.export_comparison_to_csv(scenarios, 'scenario_results.csv')
271
+ ```
272
+
273
+ ## Module Overview
274
+
275
+ The library is organized into specialized modules:
276
+
277
+ - **`OLCAClient`** - Main client for connecting to openLCA IPC server
278
+ - **`search`** - Search and discovery utilities for flows, processes, and impact methods
279
+ - **`data`** - Create and modify flows, exchanges, and processes
280
+ - **`systems`** - Build and configure product systems
281
+ - **`calculate`** - Run LCA calculations with various configurations
282
+ - **`results`** - Extract and format calculation results
283
+ - **`contributions`** - Analyze contributions by process or flow
284
+ - **`uncertainty`** - Monte Carlo simulations and statistical analysis
285
+ - **`parameters`** - Parameter scenarios and sensitivity analysis
286
+ - **`export`** - Export results to CSV, Excel, and other formats
287
+
288
+ ## Best Practices
289
+
290
+ ### 1. Always Dispose Results
291
+
292
+ ```python
293
+ # Good - automatic cleanup with context manager
294
+ with OLCAClient(port=8080) as client:
295
+ result = client.calculate.simple_calculation(system, method)
296
+ impacts = client.results.get_total_impacts(result)
297
+ result.dispose() # Always dispose!
298
+
299
+ # Also good - explicit cleanup
300
+ client = OLCAClient(port=8080)
301
+ try:
302
+ result = client.calculate.simple_calculation(system, method)
303
+ # Process results
304
+ finally:
305
+ result.dispose()
306
+ ```
307
+
308
+ ### 2. Handle Missing Data
309
+
310
+ ```python
311
+ # Always check search results
312
+ pet_flow = client.search.find_flow(['polyethylene', 'terephthalate'])
313
+
314
+ if not pet_flow:
315
+ # Try alternative keywords
316
+ pet_flow = client.search.find_flow(['PET'])
317
+
318
+ if not pet_flow:
319
+ print("Material not found in database")
320
+ return
321
+
322
+ # Proceed safely
323
+ provider = client.search.find_best_provider(pet_flow)
324
+ ```
325
+
326
+ ### 3. Use Logging
327
+
328
+ ```python
329
+ import logging
330
+
331
+ # Enable logging to see what's happening
332
+ logging.basicConfig(
333
+ level=logging.INFO,
334
+ format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
335
+ )
336
+
337
+ # Library modules will log automatically
338
+ client = OLCAClient(port=8080)
339
+ # Output: "INFO - Connected to openLCA IPC server on port 8080"
340
+ ```
341
+
342
+ ## Documentation
343
+
344
+ - **[Setup Guide](docs/setup.md)** - Detailed installation and configuration
345
+ - **[Examples](examples/)** - Working example scripts and Jupyter notebooks
346
+ - **[API Reference](openlca_ipc/about.md)** - Module structure and API details
347
+
348
+ ## Requirements
349
+
350
+ ### Core Dependencies
351
+
352
+ - `olca-ipc>=2.4.0` - openLCA IPC protocol implementation
353
+ - `olca-schema>=2.4.0` - openLCA data schema
354
+ - `numpy>=1.24.0` - Numerical operations
355
+
356
+ ### Optional Dependencies
357
+
358
+ Install with `pip install openlca-ipc[full]`:
359
+
360
+ - `scipy>=1.10.0` - Statistical analysis for uncertainty
361
+ - `matplotlib>=3.7.0` - Visualization
362
+ - `pandas>=2.0.0` - Data export and analysis
363
+
364
+ ## Development
365
+
366
+ ### Setting Up Development Environment
367
+
368
+ ```bash
369
+ # Clone repository
370
+ git clone https://github.com/dernestbank/openlca-ipc.git
371
+ cd openlca-ipc
372
+
373
+ # Create conda environment (if using conda)
374
+ conda create -n openlca_dev python=3.11
375
+ conda activate openlca_dev
376
+
377
+ # Install in editable mode with dev dependencies
378
+ pip install -e ".[full]"
379
+ pip install -r requirements-dev.txt
380
+ ```
381
+
382
+ ### Running Tests
383
+
384
+ ```bash
385
+ # Install test dependencies
386
+ pip install pytest pytest-cov
387
+
388
+ # Run tests
389
+ pytest tests/
390
+
391
+ # Run with coverage
392
+ pytest --cov=openlca_ipc tests/
393
+ ```
394
+
395
+ ### Code Quality
396
+
397
+ ```bash
398
+ # Format code
399
+ black openlca_ipc/
400
+
401
+ # Lint code
402
+ flake8 openlca_ipc/
403
+
404
+ # Type checking
405
+ mypy openlca_ipc/
406
+ ```
407
+
408
+ ## Contributing
409
+
410
+ Contributions are welcome! Please feel free to submit a Pull Request.
411
+
412
+ 1. Fork the repository
413
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
414
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
415
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
416
+ 5. Open a Pull Request
417
+
418
+ ## Troubleshooting
419
+
420
+ ### Connection Refused Error
421
+
422
+ **Problem**: Cannot connect to openLCA IPC server
423
+
424
+ **Solution**:
425
+ 1. Ensure openLCA desktop application is running
426
+ 2. Start IPC server: Tools → Developer Tools → IPC Server
427
+ 3. Check port number (default: 8080)
428
+ 4. Verify firewall settings
429
+
430
+ ### Material Not Found
431
+
432
+ **Problem**: Search returns `None` for materials
433
+
434
+ **Solution**:
435
+ 1. Check if the material exists in your openLCA database
436
+ 2. Try different search keywords
437
+ 3. Use partial matching: `client.search.find_flows(['steel'])` instead of exact names
438
+
439
+ ### Zero Impact Values
440
+
441
+ **Problem**: All impact values are zero or very small
442
+
443
+ **Solution**:
444
+ 1. Verify that input exchanges have providers linked
445
+ 2. Check that the product system was created correctly
446
+ 3. Ensure the impact method is appropriate for your flows
447
+ 4. Verify that your database has characterization factors
448
+
449
+ ## License
450
+
451
+ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
452
+
453
+ ## Citation
454
+
455
+ If you use this library in your research, please cite:
456
+
457
+ ```bibtex
458
+ @software{openlca_ipc,
459
+ author = {Danquah, Ernest Boakye},
460
+ title = {openLCA IPC Python Library},
461
+ year = {2025},
462
+ url = {https://github.com/dernestbank/openlca-ipc}
463
+ }
464
+ ```
465
+
466
+ ## Acknowledgments
467
+
468
+ - Built on top of [olca-ipc](https://github.com/GreenDelta/olca-ipc.py) and [olca-schema](https://github.com/GreenDelta/olca-schema)
469
+ - Follows [ISO 14040](https://www.iso.org/standard/37456.html) and [ISO 14044](https://www.iso.org/standard/38498.html) standards
470
+ - Inspired by the openLCA community and LCA practitioners worldwide
471
+
472
+ ## Support
473
+
474
+ - **Issues**: [GitHub Issues](https://github.com/dernestbank/openlca-ipc/issues)
475
+ - **Documentation**: [Read the Docs](https://github.com/dernestbank/openlca-ipc/tree/main/docs)
476
+ - **Email**: dernestbanksch@gmail.com
477
+
478
+ ---
479
+
480
+ **Made with ❤️ for the LCA Community**