Metadata-Version: 2.4
Name: fpml-convert
Version: 0.6.3
Summary: FpML interest-rate-swap XML <-> JSON, standard library only. One projection mapping, also shipped as a JS interpreter and a C++17 converter.
License-Expression: Apache-2.0
Project-URL: Homepage, https://danieltuzes.github.io/fpml-convert/
Project-URL: Downloads, https://danieltuzes.github.io/fpml-convert/versions.html
Keywords: fpml,xml,json,structile,derivatives,swap
Requires-Python: >=3.8
Description-Content-Type: text/markdown

# fpml-convert (Python)

Standard-library-only conversion between **FpML interest-rate-swap XML and
plain JSON**, in both directions. No `lxml`, no third-party JSON — just
`xml.etree.ElementTree` and `json`.

One projection mapping, also implemented as a JavaScript interpreter (for
the [Structile](https://danieltuzes.github.io/structile/) viewer) and a
pure-STL C++17 converter; the three agree byte-for-byte on a shared test
corpus. Downloads, the full version archive, and the mapping's precise
rules: <https://danieltuzes.github.io/fpml-convert/>.

## Install

```sh
pip install fpml-convert
```

No runtime dependencies. Python 3.8+.

## Use

```python
from fpml_convert import fpml_to_json, json_to_fpml

value = fpml_to_json(xml_text)      # -> dict
xml_text2 = json_to_fpml(value)     # -> schema-ordered FpML, round-trips at the value level
```

```sh
# CLI (direction inferred from the input, or forced with --to)
python -m fpml_convert swap.xml  -o swap.json
python -m fpml_convert swap.json -o swap.xml
cat swap.xml | python -m fpml_convert - > swap.json
```

## The mapping

- Element local name → object key; a tag repeated under one parent → an
  array in document order.
- Namespace prefixes and ElementTree Clark notation (`{uri}local`) are both
  reduced to the local name, so the result is identical across a browser
  `DOMParser` and a server-side parser.
- Attributes → `@`-prefixed keys, before any child keys, ordered `@id`,
  `@xsi:type`, `@href`, then the rest. `xsi:type` is kept verbatim.
- A pure reference element (`href`, no children) → the scalar `«id»`;
  Structile renders that as a link to the element whose `@id` matches.
- Typed lexical forms are preserved as strings, never coerced
  (`1000000.00` stays exactly that).
- Every element the projection descends into is checked against a
  supported-subset allowlist — an unknown element raises
  `FpmlUnsupportedError` rather than projecting partially.
- Serialization re-emits children in schema (`xs:sequence`) order.

## Scope

FpML 5.10 confirmation view, interest-rate **swap** `dataDocument` only. A
non-IR-swap document raises `ValueError`. FRA and other products widen the
allowlist in later releases. An FpML-AWG interchange-shape mode is planned.

## License

Apache-2.0. The FpML example files used for testing are redistributed
under the [FpML Public License](https://www.fpml.org/the_standard/fpml-public-license/).
