Skip to main content

iil-enrichment

Enrichment Agent Pattern — bridge managed records with external knowledge sources.

ADR-169: Generic pattern for enriching document-centric records (SDS, GBU, tenders, trades) with data from authoritative external APIs (GESTIS, PubChem, ECHA, market data, etc.)

Installation

# Core only (no providers)
pip install iil-enrichment

# With GESTIS provider
pip install iil-enrichment[gestis]

# With Django integration
pip install iil-enrichment[django]

# Everything
pip install iil-enrichment[all]

Quick Start

from enrichment.registry import EnrichmentRegistry
from enrichment.providers.gestis import GESTISProvider
from enrichment.providers.pubchem import PubChemProvider

# Setup registry
registry = EnrichmentRegistry()
registry.register("substance", GESTISProvider())
registry.register("substance", PubChemProvider())

# Enrich a substance by CAS number
result = registry.enrich_merged("substance", "67-64-1")

# Access structured data
print(result.get("agw"))           # AGW from GESTIS
print(result.get("first_aid"))     # First aid from GESTIS
print(result.get("molecular_formula"))  # Formula from PubChem
print(result.confidence)           # 0.0–1.0

Django Integration

from enrichment.django.mixins import EnrichableModelMixin

class GlobalSdsRevision(EnrichableModelMixin, models.Model):
    substance = models.ForeignKey(...)

    def get_natural_key_for_enrichment(self):
        return self.substance.cas_number or self.product_name

    def get_enrichment_domain(self):
        return "sds"

# Usage
revision.run_enrichment()  # → fetches GESTIS + PubChem, stores in enrichment_data JSONB

Architecture

┌──────────────┐     ┌──────────────────────┐
│ Managed      │     │ EnrichmentRegistry   │
│ Record       │────▶│                      │
│ (DMS-focus)  │     │  ┌──────────────┐   │
│              │     │  │ GESTISProv.  │   │
│ enrichment_  │◀────│  │ PubChemProv. │   │
│ data (JSONB) │     │  │ CustomProv.  │   │
└──────────────┘     │  └──────────────┘   │
                     └──────────────────────┘

Built-in Providers

Provider Domain Data
GESTISProvider substance, sds AGW, first aid, storage, transport, WGK, physical properties
PubChemProvider substance, sds Molecular data, GHS classification, H/P codes

Configuration via Environment

All settings have sensible defaults and can be overridden per environment:

Env-Var Default Description
IIL_ENRICHMENT_TIMEOUT 15 HTTP timeout in seconds
IIL_ENRICHMENT_MAX_RETRIES 3 Max retry attempts per request
IIL_ENRICHMENT_BACKOFF_INITIAL 0.5 Initial backoff in seconds
IIL_ENRICHMENT_BACKOFF_MAX 8.0 Max backoff in seconds
IIL_ENRICHMENT_CACHE 1 Cache on (1) or off (0)
IIL_ENRICHMENT_CACHE_DIR ./.cache/iil-enrichment/ Cache directory
IIL_ENRICHMENT_RATE_LIMIT 1 Rate limit on (1) or off (0)
IIL_ENRICHMENT_USER_AGENT iil-enrichment/0.2 ... User-Agent for external APIs
GESTIS_API_KEY (public demo key) Own DGUV key recommended for production

Or configure programmatically:

from enrichment.config import HTTPDefaults
from enrichment.providers.gestis import GESTISProvider

defaults = HTTPDefaults(timeout_seconds=30, max_retries=5, cache_enabled=True)
provider = GESTISProvider(defaults=defaults)

Custom Provider

from enrichment.provider import EnrichmentProvider
from enrichment.types import EnrichmentResult, PropertyValue

class MyProvider:
    @property
    def name(self) -> str:
        return "MySource"

    @property
    def supported_domains(self) -> list[str]:
        return ["my_domain"]

    def can_enrich(self, domain: str, natural_key: str) -> bool:
        return domain == "my_domain" and bool(natural_key)

    def enrich(self, domain: str, natural_key: str) -> EnrichmentResult:
        # Fetch from your API...
        return EnrichmentResult(
            source=self.name,
            confidence=0.9,
            properties={"key": PropertyValue(value="data")},
            natural_key=natural_key,
        )

Ecosystem

iil-enrichment ist die Anreicherungs-Stufe einer dreiteiligen Datenpipeline:

iil-ingest  →  iil-enrichment  →  iil-fieldprefill
(extract)      (enrich)           (prefill form fields)

Eingang ist ein natural key (z. B. CAS-Nummer, oft aus iil-ingest-Text extrahiert); Ausgang EnrichmentResult.properties speist den Kontext für iil-fieldprefill. Vollständiger Flow, reale Typen und ein lauffähiges End-to-End-Beispiel: platform/docs/ecosystem/iil-data-pipeline.md.

License

MIT

Metadata

Release files for iil-enrichment 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iil-enrichment 0.2.0
File Size Uploaded Provenance
iil_enrichment-0.2.0.tar.gz 29.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for iil-enrichment 0.2.0
File Interpreter ABI Platform
iil_enrichment-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 52.1 kB

Release files / iil_enrichment-0.2.0.tar.gz

Download URL iil_enrichment-0.2.0.tar.gz
Size 29.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3ac9645c0990d8f0388390d9dcbec484bb3075073611927dee13975c22a22a3a
BLAKE2b-256 checksum
How to use checksums
60020659f08252db37024be3c75cdcf06575fde26dbdc881eb3f64897e255217
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Release files / iil_enrichment-0.2.0-py3-none-any.whl

Download URL iil_enrichment-0.2.0-py3-none-any.whl
Size 22.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7eb4d5f70090cf4c15a0f1d7618488e2d651127d915a20d6f32f673ec36ac004
BLAKE2b-256 checksum
How to use checksums
5ddfa6f67073a36c9b29316d6a35db022efa2aa010e84cf9f6c14867bafb121b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

Security for iil-enrichment 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for iil_enrichment-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 16, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page