diff --git a/CHANGELOG.md b/CHANGELOG.md index a58e247..13076e2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Put back some translations that were removed - Minor python tidyups - Avoid deprecation warning from the ijson package. https://github.com/OpenDataServices/flatten-tool/pull/458 +- Allow passing of schema as Python object, and update docs ### Removed diff --git a/docs/getting-started.rst b/docs/getting-started.rst index 1c4803f..0d2af37 100644 --- a/docs/getting-started.rst +++ b/docs/getting-started.rst @@ -38,6 +38,27 @@ will print general help information. will print help information specific to that sub-command. +Library +------- + +The package can also be used as a Python library, e.g. to flatten +data: + +.. code-block:: python + + flattentool.flatten(input_filename, ...) + +or unflatten data: + +.. code-block:: python + + flattentool.unflatten(input_filename, ...) + +In addition to the functionality available from the command-line, +Python calls to the library functions also accept a Python object +as a schema rather than a filename. This allows schema objects to +be loaded/constructed by the calling application. + Python Version Support ---------------------- diff --git a/flattentool/schema.py b/flattentool/schema.py index 4f01722..6c99212 100644 --- a/flattentool/schema.py +++ b/flattentool/schema.py @@ -152,7 +152,9 @@ def __init__( _("Only one of schema_filename or root_schema_dict should be supplied") ) if schema_filename: - if schema_filename.startswith("http"): + if isinstance(schema_filename, dict): + self.root_schema_dict = schema_filename + elif schema_filename.startswith("http"): import requests r = requests.get(schema_filename)