A JavaScript/TypeScript library for accessing ecoinvent Life Cycle Assessment (LCA) data. Works in both Node.js and browser environments.
Note: This is an unofficial library. It is not affiliated with or endorsed by ecoinvent.
npm install ecoinvent-interfaceOr with yarn:
yarn add ecoinvent-interfaceimport { Settings, EcoinventRelease } from 'ecoinvent-interface';
// 1. Set up credentials
const settings = new Settings({
username: 'your-ecoinvent-username',
password: 'your-ecoinvent-password'
});
// 2. Create interface
const ei = new EcoinventRelease(settings);
// 3. Login and fetch data
await ei.login();
const versions = await ei.listVersions();
console.log('Available versions:', versions);
// Output: ['3.10', '3.9.1', '3.9', '3.8', ...]That's it! You're now connected to ecoinvent.
You must have:
- A valid ecoinvent account from ecoinvent.org
- Accepted the license agreement on their website
- Your username and password
import { Settings, EcoinventRelease } from 'ecoinvent-interface';
const ei = new EcoinventRelease(new Settings({
username: 'your-username',
password: 'your-password'
}));
await ei.login();
const versions = await ei.listVersions();
console.log(versions);import { EcoinventRelease, ReleaseType } from 'ecoinvent-interface';
const ei = new EcoinventRelease(settings);
await ei.login();
// Download the matrix format for version 3.9.1, cutoff system model
const path = await ei.getRelease('3.9.1', 'cutoff', ReleaseType.MATRIX);
console.log('Downloaded to:', path);import { EcoinventProcess, ProcessFileType } from 'ecoinvent-interface';
const process = new EcoinventProcess(settings);
await process.login();
// Select version and process
await process.setRelease('3.9.1', 'cutoff');
process.selectProcess('12345'); // dataset ID
// Get information
const info = await process.getBasicInfo();
const docs = await process.getDocumentation();
// Download process file
const pdfPath = await process.getFile(ProcessFileType.PDF, '/path/to/save');const ei = new EcoinventRelease(settings);
await ei.login();
// List all reports
const reports = await ei.listReportFiles();
console.log(Object.keys(reports));
// Download a specific report
const reportPath = await ei.getReport('implementation_report.pdf');const settings = new Settings({
username: 'your-username',
password: 'your-password'
});export EI_USERNAME=your-username
export EI_PASSWORD=your-passwordconst settings = new Settings(); // Reads from environment automaticallyimport { permanentSetting } from 'ecoinvent-interface';
// Store once
permanentSetting('username', 'your-username');
permanentSetting('password', 'your-password');
// Use anywhere
const settings = new Settings(); // Reads from storage automaticallyimport { ReleaseType } from 'ecoinvent-interface';
// Choose your format:
ReleaseType.ECOSPOLD // Unit process XML files
ReleaseType.MATRIX // Universal matrix export (recommended)
ReleaseType.LCI // Life cycle inventory XML
ReleaseType.LCIA // Impact assessment XML
ReleaseType.CUMULATIVE_LCI // Cumulative LCI (Excel)
ReleaseType.CUMULATIVE_LCIA // Cumulative LCIA (Excel)// Available system models (use abbreviation):
'cutoff' // Allocation cut-off by classification
'consequential' // Substitution, consequential, long-term
'apos' // Allocation at the Point of Substitution
'EN15804' // Allocation, cut-off, EN15804
// Example:
await ei.getRelease('3.9.1', 'cutoff', ReleaseType.MATRIX);Works out of the box in browsers:
<!DOCTYPE html>
<html>
<head>
<script type="module">
import { Settings, EcoinventRelease } from 'ecoinvent-interface';
const settings = new Settings({
username: 'your-username',
password: 'your-password'
});
const ei = new EcoinventRelease(settings);
await ei.login();
const versions = await ei.listVersions();
console.log('Versions:', versions);
</script>
</head>
<body>
<h1>Ecoinvent Browser Example</h1>
</body>
</html>import React, { useState, useEffect } from 'react';
import { Settings, EcoinventRelease } from 'ecoinvent-interface';
function EcoinventData() {
const [versions, setVersions] = useState([]);
const [loading, setLoading] = useState(true);
useEffect(() => {
async function loadVersions() {
const settings = new Settings({
username: process.env.REACT_APP_EI_USERNAME,
password: process.env.REACT_APP_EI_PASSWORD
});
const ei = new EcoinventRelease(settings);
await ei.login();
const data = await ei.listVersions();
setVersions(data);
setLoading(false);
}
loadVersions();
}, []);
if (loading) return <div>Loading...</div>;
return (
<div>
<h1>Available Versions</h1>
<ul>
{versions.map(v => <li key={v}>{v}</li>)}
</ul>
</div>
);
}import { ProcessMapping } from 'ecoinvent-interface';
const mapping = new ProcessMapping(settings);
// Create remote mapping (from API)
const remoteProcesses = await mapping.createRemoteMapping(
'3.9.1',
'cutoff',
100 // max ID to fetch
);
// Create local mapping (from downloaded files)
const localProcesses = mapping.createLocalMapping(
'ecoinvent 3.9.1_cutoff_ecoSpold02'
);
// Find matches using fuzzy matching
const matches = mapping.matchProcesses(localProcesses, remoteProcesses);
console.log(`Found ${matches.length} matches`);
// Find specific match
const match = mapping.findClosestMatch(
localProcesses[0],
remoteProcesses,
10 // Levenshtein distance threshold
);import { getExcelLciaFileForVersion } from 'ecoinvent-interface';
const excelPath = await getExcelLciaFileForVersion(ei, '3.9.1');
console.log('LCIA Excel file:', excelPath);import { setLogLevel, LogLevel } from 'ecoinvent-interface';
// Enable debug logging
setLogLevel(LogLevel.DEBUG);
// Now all operations will log detailed information
const ei = new EcoinventRelease(settings);
await ei.login(); // Will show detailed login processFiles are automatically cached to avoid re-downloading:
Cache Locations:
- macOS:
~/Library/Caches/ecoinvent-interface - Windows:
%LOCALAPPDATA%\ecoinvent-interface\Cache - Linux:
~/.cache/ecoinvent-interface - Browser: IndexedDB or localStorage
Custom Cache Directory:
const settings = new Settings({
username: 'user',
password: 'pass',
outputPath: '/custom/cache/path'
});Settings- Authentication and configurationEcoinventRelease- Access database releasesEcoinventProcess- Access individual processesProcessMapping- Map between local and remote processesCachedStorage- Manage cached files
ReleaseType- Database format typesProcessFileType- Process file types (UPR, LCI, LCIA, PDF)LogLevel- Logging levels (ERROR, WARN, INFO, DEBUG)
login()- Authenticate with ecoinventlistVersions()- Get available versionslistSystemModels(version)- Get system modelsgetRelease(version, model, type)- Download databaselistReportFiles()- List available reportsgetReport(filename)- Download reportlistExtraFiles(version)- List extra filesgetExtra(version, filename)- Download extra file
setRelease(version, model)- Set version/modelselectProcess(datasetId)- Select process by IDgetBasicInfo()- Get process metadatagetDocumentation()- Get XML documentationgetFile(fileType, directory)- Download process file
createRemoteMapping(version, model, maxId)- Fetch from APIcreateLocalMapping(cacheKey)- Parse local filesfindClosestMatch(local, remotes, threshold)- Find matchmatchProcesses(locals, remotes)- Match all processesaddMapping(data, version, model)- Save mapping
Full TypeScript definitions included:
import {
Settings,
EcoinventRelease,
ReleaseType,
EcoinventProcess,
ProcessFileType,
ISettings
} from 'ecoinvent-interface';
const settings: ISettings = {
username: 'user',
password: 'pass'
};
const ei: EcoinventRelease = new EcoinventRelease(new Settings(settings));Error: "Missing username" or "Missing password"
// Solution: Make sure credentials are set
const settings = new Settings({
username: 'your-username', // ← Don't forget these!
password: 'your-password'
});Error: "Version X.X.X not found"
// Solution: Check available versions first
const versions = await ei.listVersions();
console.log('Available:', versions);// The library has built-in 20-second timeouts
// If you need longer, you may need to adjust your networkSee the examples/ directory for complete working examples:
examples/basic-usage.js- Simple version listing- More examples coming soon
If you're migrating from the Python package:
| Python | JavaScript/TypeScript |
|---|---|
list_versions() |
listVersions() |
get_release() |
getRelease() |
system_model |
systemModel |
output_path |
outputPath |
All functionality is available with JavaScript naming conventions (camelCase).
- Node.js: 14.0 or higher
- Browsers: Modern browsers with ES6 support
- ecoinvent Account: Required for API access
# Install dependencies
npm install
# Run tests
npm test
# Build
npm run build
# Watch mode
npm run devMIT License - see LICENSE file
- Issues: GitHub Issues
- Documentation: This README and MIGRATION_VALIDATION.md
- ecoinvent Support: ecoinvent.org
- ✨ Added
getExcelLciaFileForVersion()utility function - ✨ Added
ProcessMapping.addMapping()for storing mappings - ✨ Enhanced fuzzy matching with
findClosestMatch()andmatchProcesses() - 📚 Comprehensive test suite
- 📖 Improved documentation
- 🌐 Full browser compatibility
- 🎉 Initial release
- ✅ Complete feature parity with Python package
- ✅ TypeScript support
- ✅ Browser and Node.js support
This library is a TypeScript port of the Python ecoinvent-interface package by Chris Mutel.
This is an unofficial and unsupported library. It is not affiliated with or endorsed by ecoinvent. The library interacts with ecoinvent's API which may change without notice.
Made with ❤️ for the LCA community