Skip to main content

rnginline: Flatten multi-file RELAX NG schemas

GitHub Workflow Status (with branch) PyPI Read the Docs

rnginline is a Python library and command-line tool for loading multi-file RELAX NG schemas from arbitary URLs, and flattening them into a single RELAX NG schema.

Features

  • Convert multi-file RNG schemas into one file without breaking or restructuring the schemas
    • Great care is taken to maintain the semantics of the separate schema files in the single output
    • The input documents are changed as little as possible, so the output is as readable as the input
  • Load schemas from:
    • The filesystem
    • From a Python package's data (without unpacking it to the filesystem)
    • Any type of URL by writing your own UrlHandler
  • Command-line interface & Python API
  • Test suite covering lots of edge cases, e.g. namespace handling
    • 100% line & branch code coverage

Quickstart

Install with pip (or pipx if you only need the command-line program):

$ pipx install rnginline

You can use it from the command line like this:

$ rnginline my-nested-schema-root.rng flattened-output.rng

You can use it from Python like this:

>>> import rnginline
>>> rnginline.inline('my-nested-schema-root.rng')
<lxml.etree.RelaxNG object at ...>

You can load a multi-file schema from a Python package's data like this:

>>> import rnginline
>>> from rnginline.urlhandlers import pydata
>>> url = pydata.makeurl('rnginline.test',
...                      'data/testcases/external-ref-1/schema.rng')
>>> url
'pydata://rnginline.test/data/testcases/external-ref-1/schema.rng'
>>> rnginline.inline(url)
<lxml.etree.RelaxNG object at ...>

Documentation

Documentation is available at http://rnginline.readthedocs.org/

Motivation

lxml has good support for using RELAX NG schemas, but lacks support for loading multi-file schemas from anywhere other than the filesystem. This is a problem if you wish to bundle a multi-file schema with your Python package/module. You'd have to depend on setuptools being available to use its resource extraction, or use one of the existing RELAX NG merging tools to convert your schema into a single file.

Existing RELAX NG flattening tools

The following projects didn't quite fit my needs, leading me to write rnginline. They may work for you though.

  • rng2srng — Implements full simplification, so the structure of the input schema will be lost
  • rng-incelim — A similar project to this, implemented in XSLT. Unfortunately doesn't handle namespace declarations on <include> elements correctly. XSLT 1.0 doesn't support creating namespace nodes, so to fix this rng-incelim would have to resolve all QNames in the schema to NCNames with ns attributes, which would be undesirable for me.

Developing

Instructions for developers working on this project are in DEVELOPING.md.

Release files for rnginline 1.0.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 rnginline 1.0.0
File Size Uploaded
rnginline-1.0.0.tar.gz 50.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rnginline 1.0.0
File Interpreter ABI Platform
rnginline-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 136.4 kB

Release files / rnginline-1.0.0.tar.gz

Download URL rnginline-1.0.0.tar.gz
Size 50.7 kB
Tags Source
SHA-256 checksum
How to use checksums
256ab3b3e3aa3b29c8016615806ad98ae882a8e6c08067baac1b740dc3f753a1
BLAKE2b-256 checksum
How to use checksums
6d71294bd361978a48ea5f16b1ccb5f18135ceec8c1ae8ce82eaeef47cbdee01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release files / rnginline-1.0.0-py3-none-any.whl

Download URL rnginline-1.0.0-py3-none-any.whl
Size 85.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
907307854e8c9d26639f2cdbf8e492a80ee8f69d1a6707e77ff4a4820cff3e13
BLAKE2b-256 checksum
How to use checksums
2fa5ea5988d6540d74da85a8c3024213b768e5408598be68e548d10857bdd8f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/4.0.1 CPython/3.11.3

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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