Metadata-Version: 2.4
Name: ocx-schema-parser
Version: 3.1.0
Summary: A python package for parsing the OCX schema and exporting it as a typed JSON model.
Author-email: ocastrup <ole.christian.astrup@dnv.com>
Project-URL: Homepage, https://github.com/OCXStandard/ocx-schema-parser
Project-URL: Repository, https://github.com/OCXStandard/ocx-schema-parser.git
Project-URL: Bug Tracker, https://github.com/OCXStandard/ocx-schema-parser/issues
Project-URL: Changelog, https://github.com/OCXStandard/ocx-schema-parser/blob/main/CHANGELOG.md
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: xsdata[cli,lxml]~=26.2
Requires-Dist: pydantic>=2
Requires-Dist: loguru>=0.7
Dynamic: license-file

![](docs/_static/logo.png)
# ocx-schema-parser

A Python library and CLI for parsing the [OCX](https://3docx.org) XSD schema
into a typed, immutable model that serializes to JSON.

## Installation

```
pip install ocx-schema-parser
```

## Usage

### CLI

```
# Export a remote schema to JSON
ocx-schema-parser export https://3docx.org/fileadmin/ocx_schema/V320/OCX_Schema.xsd -o ocx_schema.json

# Export a local schema file or folder
ocx-schema-parser export path/to/OCX_Schema.xsd

# List schema entities as 'prefix:name', one per line
ocx-schema-parser list elements path/to/OCX_Schema.xsd
ocx-schema-parser list complex-types path/to/OCX_Schema.xsd
ocx-schema-parser list simple-types path/to/OCX_Schema.xsd
ocx-schema-parser list enumerations path/to/OCX_Schema.xsd

# Show one entity's documentation, attributes and children (case-insensitive)
ocx-schema-parser list elements path/to/OCX_Schema.xsd --name ocx:Vessel

# Print entity counts grouped by target namespace
ocx-schema-parser summary path/to/OCX_Schema.xsd
```

### Python API

```python
from ocx_schema_parser import load, resolve, DEFAULT_SCHEMA

schemas = load(DEFAULT_SCHEMA)  # URL, local .xsd file, or folder
model = resolve(schemas)  # -> OcxSchema (frozen Pydantic model)

vessel = model.get("ocx:Vessel")
print(vessel.description)
print([a.name for a in vessel.attributes])
print(model.model_dump_json(indent=2))  # full JSON export

# Attributes with inline enumerations reference their EnumType by prefixed
# name (e.g. "ocx:functionType", "unitsml:prefix"), so attribute types can
# be looked up in model.enumerations.
enums = {f"{e.prefix}:{e.name}": e for e in model.enumerations}
```

## API documentation

Autogenerated with ``sphinx``: https://ocxstandard.github.io/ocx-schema-parser/

## Development

This project uses [uv](https://docs.astral.sh/uv/) for environment and
package management.

```bash
# Set up the environment
uv sync

# Install git hooks: linting on commit, full test suite on push
uv run pre-commit install

# Run the tests (with coverage)
uv run pytest
```

### Releasing

1. Add a section for the new version to `CHANGELOG.md`
   (heading format: `## [X.Y.Z] - YYYY-MM-DD`).
2. Run `uv run tbump X.Y.Z` — this bumps the version, commits, and pushes
   a `vX.Y.Z` tag.
3. The tag triggers the publish workflow: tests → build → PyPI (trusted
   publishing) → GitHub Release with the CHANGELOG notes.

## Changelog
[Changelog](https://github.com/OCXStandard/ocx-schema-parser/blob/main/CHANGELOG.md)
