Metadata-Version: 2.4
Name: ab-plugin-clic
Version: 0.1.0a2
Summary: Import published CLIC inventories into Activity Browser 3
License-Expression: LGPL-3.0-or-later
Project-URL: Source, https://github.com/romainsacchi/ab-plugin-clic
Project-URL: Issues, https://github.com/romainsacchi/ab-plugin-clic/issues
Project-URL: CLIC, https://clic.psi.ch/
Keywords: activity-browser,brightway,lca,life cycle inventory
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Science/Research
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Scientific/Engineering
Requires-Python: <3.15,>=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: COPYING
Requires-Dist: requests<3,>=2.32
Requires-Dist: bw2data<5,>=4.8
Requires-Dist: bw2io<1,>=0.9.17
Requires-Dist: peewee>=4.0.1
Requires-Dist: qtpy<3,>=2
Requires-Dist: keyring<26,>=25.6
Dynamic: license-file

# CLIC for Activity Browser 3

Browse published life cycle inventories from the [Curated Life cycle Inventory Collection (CLIC)](https://clic.psi.ch/) and import them into your active Brightway project.

## Install from PyPI

Install [`ab-plugin-clic` 0.1.0a2](https://pypi.org/project/ab-plugin-clic/0.1.0a2/) and the pinned [plugin-enabled Activity Browser build](https://github.com/LCA-ActivityBrowser/activity-browser/tree/aa164283a3a171ccdeed7fba1fc431a89b9d5c12) in the same Python environment. Python 3.12 on macOS is the tested setup. Activity Browser 3.0.0 and its standalone installers lack the plugin loader.

```bash
python3.12 -m venv .venv
source .venv/bin/activate
python -m pip install \
  'activity-browser @ git+https://github.com/LCA-ActivityBrowser/activity-browser.git@aa164283a3a171ccdeed7fba1fc431a89b9d5c12' \
  'ab-plugin-clic==0.1.0a2'
activity-browser
```

If you already have the pinned Activity Browser build, activate its environment and run `python -m pip install 'ab-plugin-clic==0.1.0a2'`.

In Activity Browser, open **Settings → Plugins**, enable **CLIC**, save, and restart. Then open **Plugins → CLIC → Browse and import**.

## Browse and import

1. Search by dataset name, reference product, location, unit, author, project name or acronym, keyword, classification code, source publication year, or inventory reference year. Click a result to preview its metadata. Use **Paste CLIC link** to open a dataset or a specific published version.
2. Check the datasets to import. The **Selected versions** list follows you across pages and searches. **Exclude non-commercial licenses** hides versions with Creative Commons NonCommercial terms and removes them from the selection. Datasets with undisclosed licenses stay visible. [CLIC license guide](https://clic.psi.ch/licenses/)
3. Choose the local technosphere and biosphere databases and the matching ecoinvent target. The plugin suggests a pair when it recognizes the ecoinvent release and finds one linked biosphere database.
4. Select **Get your token** to create a CLIC API token with inventory download access. The plugin remembers it in your operating system’s credential store when available. Use **Forget token** to remove it.
5. Under **Import destination**, choose **Create a new database** (the default), or **Add to an existing foreground database** and select a writable classic SQLite foreground database. Select **Prepare import** to request an export for up to 100 selected versions and their connected suppliers. Review the included datasets, licenses, conversion warnings, and any unresolved links. When adding to an existing database, the review counts new and identical activities. If the same activity code has different data, choose another destination or review the existing activity before importing.

Earlier CLIC databases without a saved read-only setting can also receive imports. If you explicitly locked a database, double-click its padlock in Activity Browser’s **Databases** pane to make it editable, then reopen the destination dropdown.

Use **Replace matching activities** to update activities whose Brightway codes match the incoming package. The review lists the replacements and asks you to confirm them. The import keeps their activity IDs and incoming links and replaces their data and outgoing exchanges. It also adds new activities and reuses identical ones.

The catalog shows the latest published version of each dataset. Click a column header to sort the current page, drag its borders to resize it, or right-click the header to filter across pages.

Hover over an import field label for guidance, or activate its **?** button to keep the help open as you edit.

If CLIC is still preparing an export, select **Continue later** and resume through **Pending exports** in the same Brightway project. After import, Activity Browser’s **Description** tab shows the available CLIC metadata for each version, including publication details and technology readiness level. The destination database stores its first receipt in Brightway metadata under `clic_import` and any subsequent receipts under `clic_import_history`.

## Backgrounds and unresolved links

The alpha supports classic single-output ecoinvent cutoff and consequential databases using CLIC Brightway JSON schema 1.2. It imports the exported exchange amounts and retains parameter declarations as metadata. Parameter groups for recalculating formulas, product-node and multifunctional backgrounds, and UVEK backgrounds are outside the scope of this alpha.

An unresolved link prevents the import. Check the exchange and database shown in the review. If the review says CLIC omitted a supplier ID, prepare smaller batches. For the battery-pack datasets, separate NMC622 and NMC811. The fix for combined exports is on the CLIC server side.

## Development

Use the same environment as the pinned Activity Browser build. From the repository root, install the plugin with `python -m pip install -e .` and install `ruff` for the lint checks.

```bash
python -m unittest discover -s tests -v
ruff check src tests
ruff format --check src tests
```

The tests use simulated CLIC responses and an isolated Brightway project. To build and check the source distribution and wheel, install `build` and a current `twine`.

```bash
python -m build
python -m twine check --strict dist/*
```

[Issue tracker](https://github.com/romainsacchi/ab-plugin-clic/issues) · [Activity Browser plugin API](https://github.com/LCA-ActivityBrowser/activity-browser/blob/aa164283a3a171ccdeed7fba1fc431a89b9d5c12/docs/plugins/api-reference.md) · [CLIC API](https://clic.psi.ch/api/docs/)

## Releases

Use a Git tag that matches the version in `pyproject.toml`, such as `v0.1.0a2`.
Run **Publish to PyPI** manually on the tag to build and check both distributions.
Publishing the corresponding draft GitHub release starts the PyPI upload workflow.

For the first release, set up a [pending Trusted Publisher](https://pypi.org/manage/account/publishing/) on PyPI with project name `ab-plugin-clic`, owner `romainsacchi`, repository `ab-plugin-clic`, workflow `publish-pypi.yml`, and environment `pypi`. GitHub Actions exchanges its identity for short-lived PyPI upload credentials.

## License

The plugin is licensed under LGPL-3.0-or-later. See [LICENSE](https://github.com/romainsacchi/ab-plugin-clic/blob/main/LICENSE) and the accompanying [GPL text](https://github.com/romainsacchi/ab-plugin-clic/blob/main/COPYING). Imported datasets retain their individual licenses.
