Metadata-Version: 2.5
Name: ili2ogc
Version: 0.1.4
Summary: A pure-Python INTERLIS 2 toolkit: build a live metamodel from .ili, validate .xtf transfers, and convert to/from JSON Schema, OGC JSON-FG, PostgreSQL/GeoPackage SQL, and CQL2-JSON filters, with multi-language (TRANSLATION OF) output
Project-URL: Homepage, https://github.com/maxcollombin/ili2ogc
Project-URL: Repository, https://github.com/maxcollombin/ili2ogc.git
Project-URL: Issues, https://github.com/maxcollombin/ili2ogc/issues
Author-email: Maxime Collombin <maxime.collombin@netplus.ch>
License: MIT License
        
        Copyright (c) 2026 Federal Office of Topography swisstopo
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: cql2,geodata,gis,interlis,json-fg,json-schema,ogc,sql,swisstopo
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: GIS
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: antlr4-python3-runtime==4.13.2
Requires-Dist: jsonschema>=4.23.0
Requires-Dist: pycartosym[sld]>=0.3.5
Requires-Dist: pydantic>=2.13.4
Requires-Dist: pyyaml>=6.0.3
Provides-Extra: dev
Requires-Dist: antlr4-tools>=0.2.2; extra == 'dev'
Requires-Dist: black>=24.0; extra == 'dev'
Requires-Dist: mypy>=1.11; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: ruamel-yaml>=0.19.1; extra == 'dev'
Requires-Dist: ruff>=0.16.2; extra == 'dev'
Description-Content-Type: text/markdown

# ili2ogc

A pure-Python INTERLIS 2 toolkit: parses `.ili` models into a graph of typed
Python objects (the IlisMeta16 metamodel), validates `.xtf` data transfers
against them, and converts both to JSON Schema, SQL DDL (PostgreSQL/
GeoPackage), OGC JSON-FG, CQL2-JSON filters, and back to `.xtf`. `TRANSLATION
OF` models are supported throughout via `--lang` (renames identifiers/keys
in the output, the transfer wire format itself is unaffected).

## Installation

```sh
uv sync          # or: pip install .
```

The generated ANTLR lexer/parser are committed under `src/interlis/antlr/`,
so no grammar build step is needed.

## Usage

```sh
interlis build model.ili --repo models/                                 # parse + print the built model
interlis validate transfer.xtf --repo models/                           # check .xtf against its .ili schema
interlis convert model.ili -o model.schema.json                         # .ili -> JSON Schema
interlis convert-sql model.ili --dialect postgresql -o model.sql        # .ili -> SQL DDL
interlis convert-jsonfg transfer.xtf --repo models/ -o out.jsonfg.json   # .xtf -> OGC JSON-FG
interlis convert-cql2 model.ili -o model.cql2.json                      # CONSTRAINT -> CQL2-JSON filters
interlis write-xtf view-model.ili source.xtf -o view.xtf                # VIEW TOPIC data -> .xtf
```

`--repo DIR` (repeatable) resolves `IMPORTS`/schema references against a
directory of `.ili` files. Run `interlis <command> --help` for every option.

## Python API

```python
from pathlib import Path
from interlis.runtime.parse import parse_file
from interlis.builder.model_builder import InterlisModelBuilder
from interlis.xtf.parse import parse_xtf
from interlis.xtf.validate import validate_transfer

tree, syntax_errors = parse_file(Path("model.ili"))
builder = InterlisModelBuilder(Path("mappings"), Path("spec/grammar/mapping"))
model = builder.build(tree)  # graph of Pydantic objects, e.g. model.Element[0].Name

transfer = parse_xtf(Path("transfer.xtf"))
issues = validate_transfer(transfer, symbol_table=builder.symbol_table)
```

`interlis.convert.jsonschema`/`.sql`/`.jsonfg`/`.cql2`/`.xtf_writer` expose
the same conversions as the CLI's `convert`/`convert-sql`/`convert-jsonfg`/
`convert-cql2`/`write-xtf`. Pass a `ModelRepository`
(`interlis.builder.repository`) to the builder to resolve `IMPORTS` against
other local `.ili` models.

## Development

```sh
uv run pytest                 # test suite
uv run ruff check src/ tests/ # lint (also enforced in CI)
uv run black src/ tests/      # format
```

CI (`.github/workflows/ci.yml`) runs `ruff`, `black --check` and the test
suite on Python 3.10/3.12/3.14.

`spec/grammar/mapping/*.yml` and `mappings/ilismeta16-*.yml` (the
IlisMeta16 metamodel) are the executable source of truth: `InterlisModelBuilder`
is a generic engine driven by this data, not hand-written parsing code per
grammar rule. Regenerating the vendored grammar under
`vendor/interlis-antlr4` is a maintainer-only step, needed only when that
submodule changes.
