Skip to content

Commit

Permalink
schema.py: Allow passing as Python object
Browse files Browse the repository at this point in the history
Allow the calling application to load the schema rather than flatten-tool
Partial work around for: #447
  • Loading branch information
Ed (ODSC) committed Dec 7, 2024
1 parent e29ab09 commit f4c874d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions docs/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
----------------------

Expand Down
4 changes: 3 additions & 1 deletion flattentool/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f4c874d

Please sign in to comment.